使用 movflags 选项生成调整大小的代理文件后,帧数不匹配

使用 movflags 选项生成调整大小的代理文件后,帧数不匹配

我正在使用 FFMpeg 生成缩小尺寸的代理视频以供下游处理。我将视频作为流传输到 FFMpeg,并将生成的代理视频作为流直接传输回调用应用程序。为了做到这一点,我使用“-movflags frag_keyframe+empty_moov”选项将“moov”原子放置在流的开头。这一切都运行正常,但是使用代理视频的下游进程抛出错误,因为代理视频中的帧数与文件元数据中定义的帧数不匹配。为了验证这一点,我运行了以下 FFMpeg 命令将代理视频的各个帧导出到子目录。

ffmpeg -i proxy_video.mp4 帧/$filename%03d.bmp

然后我计算生成的帧数,如下所示。ls frames | wc -l

对于我的小样本视频,这给了我 167 个计数。

然后我使用 FFProbe 获取视频的帧数,如下所示。ffprobe -v error -select_streams v:0 -count_frames -show_entries stream=nb_read_frames proxy_video.mp4

对于同一个视频,我得到的计数是 165。查看原始视频确实有 165 帧,查看为代理生成的 bmp 文件,似乎在开头添加了两个额外的帧。这两个额外的帧不是问题,但实际帧数与元数据中定义的帧数必须匹配。

有什么方法可以更新标题中的帧数,或者有什么方法可以防止生成多余的帧?

我运行的FFMpeg命令如下。ffmpeg -i test_video.mp4 -acodec libmp3lame -vcodec libx264 -r 30 -vf scale=480:-2 -f mov -movflags frag_keyframe+empty_moov proxy_video.mp4

我在 Mac OS 12.6.1 上运行此程序,并且还观察到了 Ubuntu 20.04 上的问题

我的 FFMpeg 版本的输出如下,

ffmpeg version 5.1.2 Copyright (c) 2000-2022 the FFmpeg developers
  built with Apple clang version 14.0.0 (clang-1400.0.29.102)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/5.1.2 --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

谢谢你的帮助 Mike

附录。FFMpeg 的完整输出如下。

 % ffmpeg -i test_video.mp4 -acodec libmp3lame -vcodec libx264 -r 30 -vf scale=480:-2 -f mov -movflags frag_keyframe+empty_moov proxy_video.mp4
ffmpeg version 5.1.2 Copyright (c) 2000-2022 the FFmpeg developers
  built with Apple clang version 14.0.0 (clang-1400.0.29.102)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/5.1.2 --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 'test_video.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2018-05-17T20:57:37.000000Z
  Duration: 00:00:05.51, start: 0.000000, bitrate: 10528 kb/s
  Stream #0:0[0x1](eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 10189 kb/s, 29.97 fps, 29.97 tbr, 30k tbn (default)
    Metadata:
      creation_time   : 2018-05-17T20:57:37.000000Z
      handler_name    : ?Mainconcept Video Media Handler
      vendor_id       : [0][0][0][0]
      encoder         : AVC Coding
  Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
    Metadata:
      creation_time   : 2018-05-17T20:57:38.000000Z
      handler_name    : #Mainconcept MP4 Sound Media Handler
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
[libx264 @ 0x7fd91e206000] using SAR=1/1
[libx264 @ 0x7fd91e206000] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x7fd91e206000] profile High, level 2.1, 4:2:0, 8-bit
[libx264 @ 0x7fd91e206000] 264 - core 164 r3095 baee400 - H.264/MPEG-4 AVC codec - Copyleft 2003-2022 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mov, to 'proxy_video.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    encoder         : Lavf59.27.100
  Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 480x270 [SAR 1:1 DAR 16:9], q=2-31, 30 fps, 15360 tbn (default)
    Metadata:
      creation_time   : 2018-05-17T20:57:37.000000Z
      handler_name    : ?Mainconcept Video Media Handler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc59.37.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
  Stream #0:1(eng): Audio: mp3 (.mp3 / 0x33706D2E), 48000 Hz, stereo, fltp (default)
    Metadata:
      creation_time   : 2018-05-17T20:57:38.000000Z
      handler_name    : #Mainconcept MP4 Sound Media Handler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc59.37.100 libmp3lame
frame=  165 fps= 52 q=-1.0 Lsize=     551kB time=00:00:05.52 bitrate= 817.8kbits/s speed=1.74x    
video:461kB audio:87kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.689201%
[libx264 @ 0x7fd91e206000] frame I:1     Avg QP:24.34  size: 27213
[libx264 @ 0x7fd91e206000] frame P:46    Avg QP:25.37  size:  7748
[libx264 @ 0x7fd91e206000] frame B:118   Avg QP:30.86  size:   741
[libx264 @ 0x7fd91e206000] consecutive B-frames:  4.2%  0.0%  3.6% 92.1%
[libx264 @ 0x7fd91e206000] mb I  I16..4:  0.8% 38.2% 61.0%
[libx264 @ 0x7fd91e206000] mb P  I16..4:  0.4%  1.5%  1.0%  P16..4: 38.2% 28.3% 24.4%  0.0%  0.0%    skip: 6.1%
[libx264 @ 0x7fd91e206000] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8: 42.5%  7.1%  2.2%  direct: 1.7%  skip:46.4%  L0:36.8% L1:48.0% BI:15.2%
[libx264 @ 0x7fd91e206000] 8x8 transform intra:45.4% inter:44.7%
[libx264 @ 0x7fd91e206000] coded y,uvDC,uvAC intra: 75.9% 95.1% 82.9% inter: 17.6% 15.2% 5.9%
[libx264 @ 0x7fd91e206000] i16 v,h,dc,p: 44% 25% 23%  8%
[libx264 @ 0x7fd91e206000] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 13% 22%  5%  6%  7%  6%  8% 10%
[libx264 @ 0x7fd91e206000] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 21% 14% 15%  8%  9%  9%  8%  9%  8%
[libx264 @ 0x7fd91e206000] i8c dc,h,v,p: 49% 18% 23% 10%
[libx264 @ 0x7fd91e206000] Weighted P-Frames: Y:17.4% UV:17.4%
[libx264 @ 0x7fd91e206000] ref P L0: 67.5% 15.9%  8.5%  7.7%  0.4%
[libx264 @ 0x7fd91e206000] ref B L0: 88.5%  9.1%  2.4%
[libx264 @ 0x7fd91e206000] ref B L1: 91.4%  8.6%
[libx264 @ 0x7fd91e206000] kb/s:685.25

相关内容