我正在尝试在 Windows 上使用 mpeg4 对文件进行编码ffmpeg
,并且效果很好:
ffmpeg.exe -y -i input.avi -c:v mpeg4 -q:v 3 -s 640x448 output.avi
除非我尝试使用两次传递进行编码:
ffmpeg.exe -y -i input.avi -c:v mpeg4 -q:v 3 -s 640x448 -pass 1 -an -f avi NUL
ffmpeg.exe -y -i input.avi -c:v mpeg4 -q:v 3 -s 640x448 -pass 2 output.avi
第一次传递没有问题,但第二次传递出现错误:
Input #0, matroska,webm, from 'input.avi':
Metadata:
encoder : libebml-0.7.5 & libmatroska-0.7.7
creation_time : 2012-05-28T14:59:33.000000Z
Duration: 00:01:11.40, start: 0.000000, bitrate: 2101 kb/s
Stream #0:0(eng): Video: vp8 (VP80 / 0x30385056), yuv420p(progressive), 1280x896, SAR 1:1 DAR 10:7, 15 fps, 15 tbr, 1k
tbn, 1k tbc (default)
Stream #0:1(eng): Audio: vorbis, 22050 Hz, stereo, fltp (default)
Stream mapping:
Stream #0:0 -> #0:0 (vp8 (native) -> mpeg4 (native))
Stream #0:1 -> #0:1 (vorbis (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
[mpeg4 @ 000001d795b8f5c0] requested bitrate is too low
为什么只有当我尝试用两次传递进行编码时才会出现这个问题?
第一遍的完整日志:
ffmpeg version 2021-03-21-git-75fd3e1519-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 10.2.0 (Rev6, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontc
onfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enab
le-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enabl
e-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enabl
e-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable
-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm -
-enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-
libglslang --enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --en
able-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwb
enc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --
enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chr
omaprint
libavutil 56. 71.100 / 56. 71.100
libavcodec 58.135.100 / 58.135.100
libavformat 58. 77.100 / 58. 77.100
libavdevice 58. 14.100 / 58. 14.100
libavfilter 7.111.100 / 7.111.100
libswscale 5. 10.100 / 5. 10.100
libswresample 3. 10.100 / 3. 10.100
libpostproc 55. 10.100 / 55. 10.100
Input #0, matroska,webm, from 'input.avi':
Metadata:
encoder : libebml-0.7.5 & libmatroska-0.7.7
creation_time : 2012-05-28T14:59:33.000000Z
Duration: 00:01:11.40, start: 0.000000, bitrate: 2101 kb/s
Stream #0:0(eng): Video: vp8 (VP80 / 0x30385056), yuv420p(progressive), 1280x896, SAR 1:1 DAR 10:7, 15 fps, 15 tbr, 1k
tbn, 1k tbc (default)
Stream #0:1(eng): Audio: vorbis, 22050 Hz, stereo, fltp (default)
Stream mapping:
Stream #0:0 -> #0:0 (vp8 (native) -> mpeg4 (native))
Press [q] to stop, [?] for help
Output #0, avi, to 'NUL':
Metadata:
ISFT : Lavf58.77.100
Stream #0:0(eng): Video: mpeg4 (FMP4 / 0x34504D46), yuv420p(tv, bt470bg/unknown/unknown, progressive), 640x448 [SAR 1:
1 DAR 10:7], q=2-31, 200 kb/s, 15 fps, 15 tbn (default)
Metadata:
encoder : Lavc58.135.100 mpeg4
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A
frame= 1071 fps=719 q=3.0 Lsize= 13267kB time=00:01:11.40 bitrate=1522.1kbits/s speed=47.9x
video:13236kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.236026%
第二遍的完整日志:
ffmpeg version 2021-03-21-git-75fd3e1519-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 10.2.0 (Rev6, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontc
onfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enab
le-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enabl
e-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enabl
e-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable
-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm -
-enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-
libglslang --enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --en
able-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwb
enc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --
enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chr
omaprint
libavutil 56. 71.100 / 56. 71.100
libavcodec 58.135.100 / 58.135.100
libavformat 58. 77.100 / 58. 77.100
libavdevice 58. 14.100 / 58. 14.100
libavfilter 7.111.100 / 7.111.100
libswscale 5. 10.100 / 5. 10.100
libswresample 3. 10.100 / 3. 10.100
libpostproc 55. 10.100 / 55. 10.100
Input #0, matroska,webm, from 'input.avi':
Metadata:
encoder : libebml-0.7.5 & libmatroska-0.7.7
creation_time : 2012-05-28T14:59:33.000000Z
Duration: 00:01:11.40, start: 0.000000, bitrate: 2101 kb/s
Stream #0:0(eng): Video: vp8 (VP80 / 0x30385056), yuv420p(progressive), 1280x896, SAR 1:1 DAR 10:7, 15 fps, 15 tbr, 1k
tbn, 1k tbc (default)
Stream #0:1(eng): Audio: vorbis, 22050 Hz, stereo, fltp (default)
Stream mapping:
Stream #0:0 -> #0:0 (vp8 (native) -> mpeg4 (native))
Stream #0:1 -> #0:1 (vorbis (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
[mpeg4 @ 000001d795b8f5c0] requested bitrate is too low
答案1
如果想要执行多次传递,请使用-b:v
,而不是-q:v
/ 。-qscale:v
来自一位 FFmpeg 开发人员的说法:
我认为同时拥有这两种选择是没有
-q:v
意义-pass
的。多遍编码旨在实现一定的平均比特率,并在整个文件中进行管理,以便为需要更多比特的部分提供更多比特。
该
-q:v
选项设置量化器值(对于任何给定的帧,该值与质量水平直接相关),并且不允许编码器选择设置比特率。如果您关心最终文件的总大小,则需要使用
-b:v
来设置平均比特率并-pass
尽可能高效地使用它。如果不关心,-q:v
则只需设置一次即可。