为什么我的 ffmpeg 视频具有可变的帧速率?

为什么我的 ffmpeg 视频具有可变的帧速率?

我尝试直接使用 ffmpeg 内置过滤器将 4 个 3840x2160 曼德布洛特集堆叠成一个 7680x4320 的矩形(不生成如下所示的 y4m),这样就生成了一个可变帧率的视频。

我推测也许 ffmpeg 太贪婪并且过滤器不够快,这导致了帧速率变化——我意识到这只是一种疯狂的猜测。

因此,我尝试了另一个实验,但我看到了相同的结果其中输出视频具有可变帧率大约25 至 27 fps(我需要一个恒定帧率为容器指定,60fps):

ffmpeg -f lavfi -i mandelbrot=s=3840x2160:r=60 -pix_fmt yuv420p -r 60 -t 20 mandel.y4m

And then:

ffmpeg -i mandel.y4m 
-filter_complex 
"[0:v][0:v]hstack=inputs=2[top];
[0:v][0:v]hstack=inputs=2[bottom];
[top][bottom]vstack=inputs=2[out]" -map "[out]" 
-c:v libx265 -profile:v main -b:v 200M -minrate 200M -maxrate 200M -bufsize 400M 
-pix_fmt yuv420p -r 60 -t 20 -y -pass 1 -an -f null /dev/null && 
ffmpeg -i mandel.y4m -filter_complex 
"[0:v][0:v]hstack=inputs=2[top];
[0:v][0:v]hstack=inputs=2[bottom];
[top][bottom]vstack=inputs=2[out]" -map "[out]" 
-c:v libx265 -profile:v main -b:v 200M -minrate 200M -maxrate 200M -bufsize 400M 
-pix_fmt yuv420p -r 60 -t 20 -y -pass 2 mandel.mp4

编辑:帧速率实际上是恒定的。但不是 60 fps。出于某种原因,它是 24。这是一个带有输出的更简单示例:

ffmpeg -f lavfi -i mandelbrot=s=3840x2160:r=60 -f lavfi -i mandelbrot=s=3840x2160:r=60 -f lavfi -i mandelbrot=s=3840x2160:r=60 -f lavfi -i mandelbrot=s=3840x2160:r=60 -filter_complex "[0:v][1:v]hstack=inputs=2[top];[2:v][3:v]hstack=inputs=2[bottom];[top][bottom]vstack=inputs=2[out]" -map "[out]" -c:v libx265 -profile:v main -b:v 200M -minrate 200M -maxrate 200M -bufsize 400M -pix_fmt yuv420p -r 60 -t 20 -y 4MandelSyntheticWithStackFilters.mp4

or w/line breaks for clarity

ffmpeg 
-f lavfi -i mandelbrot=s=3840x2160:r=60 
-f lavfi -i mandelbrot=s=3840x2160:r=60 
-f lavfi -i mandelbrot=s=3840x2160:r=60 
-f lavfi -i mandelbrot=s=3840x2160:r=60 
-filter_complex 
"[0:v][1:v]hstack=inputs=2[top];
[2:v][3:v]hstack=inputs=2[bottom];
[top][bottom]vstack=inputs=2[out]" -map "[out]" 
-c:v libx265 -profile:v main -b:v 200M -minrate 200M -maxrate 200M
-bufsize 400M -pix_fmt yuv420p -r 60 -t 20 -y
4MandelSyntheticWithStackFilters.mp4

ffmpeg version 5.1 Copyright (c) 2000-2022 the FFmpeg developers
  built with Apple clang version 13.0.0 (clang-1300.0.29.30)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/5.1 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
  libavutil      57. 28.100 / 57. 28.100
  libavcodec     59. 37.100 / 59. 37.100
  libavformat    59. 27.100 / 59. 27.100
  libavdevice    59.  7.100 / 59.  7.100
  libavfilter     8. 44.100 /  8. 44.100
  libswscale      6.  7.100 /  6.  7.100
  libswresample   4.  7.100 /  4.  7.100
  libpostproc    56.  6.100 / 56.  6.100
Input #0, lavfi, from 'mandelbrot=s=3840x2160:r=60':
  Duration: N/A, start: 0.000000, bitrate: N/A
  Stream #0:0: Video: rawvideo (RGB[0] / 0x424752), rgb0, 3840x2160 [SAR 1:1 DAR 16:9], 60 tbr, 60 tbn
Input #1, lavfi, from 'mandelbrot=s=3840x2160:r=60':
  Duration: N/A, start: 0.000000, bitrate: N/A
  Stream #1:0: Video: rawvideo (RGB[0] / 0x424752), rgb0, 3840x2160 [SAR 1:1 DAR 16:9], 60 tbr, 60 tbn
Input #2, lavfi, from 'mandelbrot=s=3840x2160:r=60':
  Duration: N/A, start: 0.000000, bitrate: N/A
  Stream #2:0: Video: rawvideo (RGB[0] / 0x424752), rgb0, 3840x2160 [SAR 1:1 DAR 16:9], 60 tbr, 60 tbn
Input #3, lavfi, from 'mandelbrot=s=3840x2160:r=60':
  Duration: N/A, start: 0.000000, bitrate: N/A
  Stream #3:0: Video: rawvideo (RGB[0] / 0x424752), rgb0, 3840x2160 [SAR 1:1 DAR 16:9], 60 tbr, 60 tbn
Stream mapping:
  Stream #0:0 (rawvideo) -> hstack
  Stream #1:0 (rawvideo) -> hstack
  Stream #2:0 (rawvideo) -> hstack
  Stream #3:0 (rawvideo) -> hstack
  vstack:default -> Stream #0:0 (libx265)
Press [q] to stop, [?] for help
x265 [info]: HEVC encoder version 3.4+31-6722fce1f
x265 [info]: build info [Mac OS X][clang 12.0.0][64 bit] 8bit+10bit+12bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [info]: Main profile, Level-6.1 (High tier)
x265 [info]: Thread pool created using 8 threads
x265 [info]: Slices                              : 1
x265 [info]: frame threads / pool features       : 3 / wpp(68 rows)
x265 [info]: Coding QT: max CU size, min CU size : 64 / 8
x265 [info]: Residual QT: max TU size, max depth : 32 / 1 inter / 1 intra
x265 [info]: ME / range / subpel / merge         : hex / 57 / 2 / 3
x265 [info]: Keyframe min / max / scenecut / bias  : 25 / 250 / 40 / 5.00 
x265 [info]: Lookahead / bframes / badapt        : 20 / 4 / 2
x265 [info]: b-pyramid / weightp / weightb       : 1 / 1 / 0
x265 [info]: References / ref-limit  cu / depth  : 3 / off / on
x265 [info]: AQ: mode / str / qg-size / cu-tree  : 2 / 1.0 / 32 / 1
x265 [info]: Rate Control / qCompress            : ABR-200000 kbps / 0.60
x265 [info]: VBV/HRD buffer / max-rate / init    : 400000 / 200000 / 0.750
x265 [info]: tools: rd=3 psy-rd=2.00 early-skip rskip mode=1 signhide tmvp
x265 [info]: tools: b-intra strong-intra-smoothing lslices=8 deblock sao
Output #0, mp4, to '4MandelSyntheticWithStackFilters.mp4':
  Metadata:
    encoder         : Lavf59.27.100
  Stream #0:0: Video: hevc (hev1 / 0x31766568), yuv420p(tv, progressive), 7680x4320 [SAR 1:1 DAR 16:9], q=2-31, 200000 kb/s, 60 fps, 15360 tbn
    Metadata:
      encoder         : Lavc59.37.100 libx265
    Side data:
      cpb: bitrate max/min/avg: 200000000/0/200000000 buffer size: 400000000 vbv_delay: N/A
frame= 1200 fps=1.0 q=41.7 Lsize=  500040kB time=00:00:19.95 bitrate=205329.2kbits/s speed=0.0163x        
video:500016kB audio:0kB subtitle:0kB other streams:0kB global headers:2kB muxing overhead: 0.004902%
x265 [info]: frame I:      5, Avg QP:26.50  kb/s: 964113.12
x265 [info]: frame P:    236, Avg QP:30.57  kb/s: 577628.54
x265 [info]: frame B:    959, Avg QP:38.13  kb/s: 109097.65
x265 [info]: Weighted P-Frames: Y:0.0% UV:0.0%
x265 [info]: consecutive B-frames: 0.4% 0.0% 0.0% 0.4% 99.2% 

encoded 1200 frames in 1220.18s (0.98 fps), 204804.62 kb/s, Avg QP:36.60

最后,请注意帧速率不是 60 fps,而是 24。这是为什么呢?

ffmpeg -i 4MandelSyntheticWithStackFilters.mp4 -vf vfrdet -an -f null -
ffmpeg version 5.1 Copyright (c) 2000-2022 the FFmpeg developers
  built with Apple clang version 13.0.0 (clang-1300.0.29.30)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/5.1 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
  libavutil      57. 28.100 / 57. 28.100
  libavcodec     59. 37.100 / 59. 37.100
  libavformat    59. 27.100 / 59. 27.100
  libavdevice    59.  7.100 / 59.  7.100
  libavfilter     8. 44.100 /  8. 44.100
  libswscale      6.  7.100 /  6.  7.100
  libswresample   4.  7.100 /  4.  7.100
  libpostproc    56.  6.100 / 56.  6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '4MandelSyntheticWithStackFilters.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf59.27.100
  Duration: 00:00:20.00, start: 0.000000, bitrate: 204816 kb/s
  Stream #0:0[0x1](und): Video: hevc (Main) (hev1 / 0x31766568), yuv420p(tv, progressive), 7680x4320 [SAR 1:1 DAR 16:9], 204806 kb/s, 60 fps, 60 tbr, 15360 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc59.37.100 libx265
Stream mapping:
  Stream #0:0 -> #0:0 (hevc (native) -> wrapped_avframe (native))
Press [q] to stop, [?] for help
Output #0, null, to 'pipe:':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf59.27.100
  Stream #0:0(und): Video: wrapped_avframe, yuv420p(tv, progressive), 7680x4320 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 60 fps, 60 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc59.37.100 wrapped_avframe
frame= 1200 fps= 24 q=-0.0 Lsize=N/A time=00:00:20.00 bitrate=N/A speed=0.394x    
video:553kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[Parsed_vfrdet_0 @ 0x7fdf00f27040] VFR:0.000000 (0/1199)

答案1

已经在评论中回答了,但如果你查看“输出 #0”部分,你会看到视频流被标记为 60 fps 流。该fps= 24部分是实时更新进度线。

注意:如果这是一个日志文件,您将看不到控制台实时更新;在我的控制台中,大部分时间都花在更新该行上:

frame=  556 fps=2.6 q=28.8 size=   15360kB time=00:00:03.84 bitrate=32765.6kbits/s speed=0.0182x

该行中的所有字段均表示当前的编码状态,截至最后一块(对我来说是最后几秒);正如它在最终输出中出现的那样,它几乎没有意义,因为它描述的是编码的最后几秒,而不是任何类型的摘要。

相关内容