FFMPEG 拒绝通过 h264_nvenc 重新编码 vp9

FFMPEG refuses to reencode vp9 via h264_nvenc

使用 Windows,FFMPEG 在将 vp9/opus .webm 视频重新编码为 h264_nvenc/aac 时抛出错误。

问题在于尝试通过 h264_nvenc 重新编码,因为使用 libx264 工作正常。

h264_nvenc 在重新编码 h264 时工作正常。

PS C:\Users\Уруру2\Videos> ffmpeg -i soad.webm -c:a aac -c:v h264_nvenc soad.mp4
ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 10.2.1 (GCC) 20200726
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --enable-librav1e --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Input #0, matroska,webm, from 'soad.webm':
  Metadata:
    ENCODER         : Lavf58.29.100
  Duration: 00:05:07.70, start: -0.007000, bitrate: 14732 kb/s
    Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv, bt709), 7372x3024, SAR 1:1 DAR 1843:756, 23.98 fps, 23.98 tbr, 1k tbn, 1k tbc (default)
    Metadata:
      DURATION        : 00:05:07.682000000
    Stream #0:1(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
    Metadata:
      DURATION        : 00:05:07.701000000
File 'soad.mp4' already exists. Overwrite? [y/N] y
Stream mapping:
  Stream #0:0 -> #0:0 (vp9 (native) -> h264 (h264_nvenc))
  Stream #0:1 -> #0:1 (opus (native) -> aac (native))
Press [q] to stop, [?] for help
[h264_nvenc @ 0000029fd34e3400] Width 7372 exceeds 4096
[h264_nvenc @ 0000029fd34e3400] No capable devices found
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
[aac @ 0000029fd34e4b40] Qavg: 12400.245
[aac @ 0000029fd34e4b40] 2 frames left in the queue on closing
Conversion failed!

发生错误不是因为 vp9,而是视频的宽度。 h264_nvenc 不支持 4096 以上的宽度或高度。我的解决方案是使用 -vf 参数将视频从原来的 7372x3024 缩小到 3686x1512。

最后的命令是

ffmpeg -i soad.webm -c:a aac -c:v h264_nvenc -vf scale=3686:1512,setsar=1:1 soad.mp4