如何在使用 ffmpeg 转码 VFR 文件时保持原始可变帧速率?

如何在使用 ffmpeg 转码 VFR 文件时保持原始可变帧速率?

我有一堆高带宽 AVC 视频文件,我想将它们重新编码为较低的比特率,以使这种转换尽可能无损。

因此我想保留原始帧速率。有些文件的帧速率可变:

$ mediainfo "$SOURCE".mp4|grep -i frame
Format settings                          : CABAC / 1 Ref Frames
Format settings, Reference frames        : 1 frame
Frame rate mode                          : Variable
Frame rate                               : 29.970 (29970/1000) FPS
Minimum frame rate                       : 25.395 FPS
Maximum frame rate                       : 30.090 FPS
Bits/(Pixel*Frame)                       : 0.322
Frame rate                               : 46.875 FPS (1024 SPF)

但重新编码后: ffmpeg -i "$SOURCE".mp4 -vsync 0 -c:v libvpx-vp9 -crf 30 -b:v 0 -c:a copy "$OUT".mp4

生成的文件具有恒定的 CFR:

$ mediainfo "$OUT".mp4|grep -i frame
Frame rate mode                          : Constant
Frame rate                               : 30.000 FPS
Bits/(Pixel*Frame)                       : 0.132
Frame rate                               : 46.875 FPS (1024 SPF)

我认为-vsync 0应该可以解决问题。我遗漏了什么?

更新:每个请求的完整日志:

ffmpeg -i VID_20191130_125715.mp4 -vsync 0 -c:v libvpx-vp9 -crf 30 -b:v 0  -c:a copy VID_20191130_125715_vsync0_2.mp4                                       ffmpeg version n4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.2.0 (GCC)
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'VID_20191130_125715.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2019-11-30T09:57:27.000000Z
    location        : <HIDDEN>
    location-eng    : <HIDDEN>
    com.android.version: 9
  Duration: 00:00:11.27, start: 0.000000, bitrate: 20733 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, unknown/bt470bg/unknown), 1920x1080, 20031 kb/s, SAR 1:1 DAR 16:9, 29.98 fps, 30 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      rotate          : 90
      creation_time   : 2019-11-30T09:57:27.000000Z
      handler_name    : VideoHandle
    Side data:
      displaymatrix: rotation of -90.00 degrees
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2019-11-30T09:57:27.000000Z
      handler_name    : SoundHandle
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> vp9 (libvpx-vp9))
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[libvpx-vp9 @ 0x564718caf5c0] v1.8.1
Output #0, mp4, to 'VID_20191130_125715_vsync0_2.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    com.android.version: 9
    location        : <HIDDEN>
    location-eng    : <HIDDEN>
    encoder         : Lavf58.29.100
    Stream #0:0(eng): Video: vp9 (libvpx-vp9) (vp09 / 0x39307076), yuv420p, 1080x1920 [SAR 1:1 DAR 9:16], q=-1--1, 30 fps, 15360 tbn, 30 tbc (default)
    Metadata:
      encoder         : Lavc58.54.100 libvpx-vp9
      creation_time   : 2019-11-30T09:57:27.000000Z
      handler_name    : VideoHandle
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
      displaymatrix: rotation of -0.00 degrees
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2019-11-30T09:57:27.000000Z
      handler_name    : SoundHandle
frame=  338 fps=4.0 q=0.0 Lsize=   11511kB time=00:00:11.23 bitrate=8394.3kbits/s speed=0.132x    
video:11324kB audio:176kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.093868%
$ mediainfo VID_20191130_125715.mp4 VID_20191130_125715_vsync0_2.mp4  
General
Complete name                            : VID_20191130_125715.mp4
Format                                   : MPEG-4
Format profile                           : Base Media / Version 2
Codec ID                                 : mp42 (isom/mp42)
File size                                : 27.9 MiB
Duration                                 : 11 s 273 ms
Overall bit rate                         : 20.7 Mb/s
Encoded date                             : UTC 2019-11-30 09:57:27
Tagged date                              : UTC 2019-11-30 09:57:27
xyz                                      : <HIDDEN>
com.android.version                      : 9

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : [email protected]
Format settings                          : CABAC / 1 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 1 frame
Format settings, GOP                     : M=1, N=30
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 11 s 273 ms
Bit rate                                 : 20.0 Mb/s
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Rotation                                 : 90°
Frame rate mode                          : Variable
Frame rate                               : 29.970 (29970/1000) FPS
Minimum frame rate                       : 25.395 FPS
Maximum frame rate                       : 30.090 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.322
Stream size                              : 26.9 MiB (97%)
Title                                    : VideoHandle
Language                                 : English
Encoded date                             : UTC 2019-11-30 09:57:27
Tagged date                              : UTC 2019-11-30 09:57:27
Color range                              : Limited
Color primaries                          : BT.601 PAL
mdhd_Duration                            : 11273
Codec configuration box                  : avcC

Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 11 s 221 ms
Bit rate mode                            : Constant
Bit rate                                 : 128 kb/s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 48.0 kHz
Frame rate                               : 46.875 FPS (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 176 KiB (1%)
Title                                    : SoundHandle
Language                                 : English
Encoded date                             : UTC 2019-11-30 09:57:27
Tagged date                              : UTC 2019-11-30 09:57:27

General
Complete name                            : VID_20191130_125715_vsync0_2.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/mp41)
File size                                : 11.2 MiB
Duration                                 : 11 s 267 ms
Overall bit rate                         : 8 369 kb/s
Writing application                      : Lavf58.29.100

Video
ID                                       : 1
Format                                   : vp09
Codec ID                                 : vp09
Duration                                 : 11 s 267 ms
Bit rate                                 : 8 234 kb/s
Width                                    : 1 080 pixels
Height                                   : 1 920 pixels
Display aspect ratio                     : 0.562
Frame rate mode                          : Constant
Frame rate                               : 30.000 FPS
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.132
Stream size                              : 11.1 MiB (98%)
Title                                    : VideoHandle
Language                                 : English

Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 11 s 222 ms
Bit rate mode                            : Constant
Bit rate                                 : 128 kb/s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 48.0 kHz
Frame rate                               : 46.875 FPS (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 176 KiB (2%)
Title                                    : SoundHandle
Language                                 : English
Default                                  : Yes
Alternate group                          : 1

相关内容