Encoding in h264 with ffmpeg on RTX 3080 fails - ffmpeg

I'm trying to convert a 7200x3600 60fps h265 video using my RTX 3080 to the h264 codec because of some compatibility issue with VR.
This command line result in "No NVENC capable devices found" error:
ffmpeg -hwaccel_device 0 -hwaccel cuda -i input.mp4 -c:v h264_nvenc output.mp4
However this command works (for h265):
ffmpeg -hwaccel_device 0 -hwaccel cuda -i input.mp4 -c:v hevc_nvenc output.mp4
Which for me, means that my gpu is 'NVENC capable' but I don't see what to try.
EDIT:
output of ffmpeg -f lavfi -i nullsrc -c:v h264_nvenc -gpu list -f null /dev/null:
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9.2.1 (GCC) 20200122
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-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-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
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, lavfi, from 'nullsrc':
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (h264_nvenc))
Press [q] to stop, [?] for help
[h264_nvenc # 0000017e82c22540] [ GPU #0 - < NVIDIA GeForce RTX 3080 > has Compute SM 8.6 ]
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
Conversion failed!

For H.264, nvenc has a max. resolution limit of 4096x4096. Use a software encoder like libx264. But note that a resolution of 7200x3600 is beyond the limit of any valid H.264 level so hope your target player doesn't care. Or use HEVC with different parameters.

Related

.avi file to .webm file with alpha channel

I have no idea how to use FFmpeg, but my .avi file is too large for a 2-second video? Any idea how I can convert it to WebM? While retaining its alpha channel?
I tried this:
ffmpeg -i "1.avi" -c:v libvpx -pix_fmt yuva420p "1.webm"
Output showed:
ffmpeg version 4.4-essentials_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-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --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-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
libavutil 56. 70.100 / 56. 70.100
libavcodec 58.134.100 / 58.134.100
libavformat 58. 76.100 / 58. 76.100
libavdevice 58. 13.100 / 58. 13.100
libavfilter 7.110.100 / 7.110.100
libswscale 5. 9.100 / 5. 9.100
libswresample 3. 9.100 / 3. 9.100
libpostproc 55. 9.100 / 55. 9.100
[avi # 00000245f2e7d640] Stream #0: not enough frames to estimate rate; consider increasing probesize
Guessed Channel Layout for Input Stream #0.1 : stereo
Input #0, avi, from '1.avi':
Duration: 00:00:02.00, start: 0.000000, bitrate: 3983150 kb/s
Stream #0:0: Video: rawvideo, bgra, 1920x1080, 4014784 kb/s, 60 fps, 60 tbr, 60 tbn, 60 tbc
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s16, 1536 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> vp8 (libvpx))
Stream #0:1 -> #0:1 (pcm_s16le (native) -> opus (libopus))
Press [q] to stop, [?] for help
[libvpx # 00000245f2e8ecc0] v1.10.0-24-g8b3e575a4
[libvpx # 00000245f2e8ecc0] Neither bitrate nor constrained quality specified, using default CRF of 32 and bitrate of 256kbit/sec
[libvpx # 00000245f2e8ecc0] Transparency encoding with auto_alt_ref does not work
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
Conversion failed!
Simplest command is:
ffmpeg -i input.avi output.webm
The video encoder libvpx-vp9 will be used by default.
libvpx-vp9 supports alpha, so alpha will be preserved by default.
For more info see FFmpeg Wiki: VP9.
Command I used to solve:
ffmpeg -i "1.avi" -c:v libvpx -b:v 2000k -pix_fmt yuva420p -auto-alt-ref 0 "1.webm"
"1.avi" - input.avi
"1.webm" - out.webm
Simple command:
ffmpeg -i input.avi output.webm

ffmpeg sRGB jpgs to rec709 mov

I'm trying to convert an sRGB jpeg sequence into a rec709 DnX Quicktime... but struggle to get the colormatrix right.
ffmpeg -y -f image2 -start_number 1 -framerate 24 -i input.%04d.jpg -c:v dnxhd -vf "scale=1920:1080,fps=24,format=yuv422p10,colorspace=all=bt709:itrc=srgb" -b:v 175M -c:a pcm_s16le output.mov
My understanding is this should set everything to rec709, but override the input response curve (itrc=srgb), but this fails with
Unsupported input primaries 2 (unknown)
Error while filtering: Invalid argument
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:0
I haven't been able to come up with any combination of flags that doesn't trough an error and produces the right colors.
Some docs here: ffmpeg filters trc
Any help much appreciated!
Edit:
Full log:
$ ffmpeg -y -f image2 -start_number 1 -framerate 24 -i input.%04d.jpg -c:v dnxhd -vf "scale=1920:1080,fps=24,format=yuv422p10,colorspace=all=bt709:itrc=srgb" -b:v 175M -c:a pcm_s16le output.mov
ffmpeg version 4.3.1-2020-11-08-essentials_build-www.gyan.dev Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 10.2.0 (Rev3, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --en
able-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --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-li
bmfx --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
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, image2, from 'input.%04d.jpg':
Duration: 00:00:00.13, start: 0.000000, bitrate: N/A
Stream #0:0: Video: mjpeg (Baseline), yuvj444p(pc, bt470bg/unknown/unknown), 1920x1080 [SAR 1200:1200 DAR 16:9], 24 fps, 24 tbr, 24 tbn, 24 tbc
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> dnxhd (native))
Press [q] to stop, [?] for help
[swscaler # 0000026ac0f81600] deprecated pixel format used, make sure you did set range correctly
Output #0, mov, to 'output.mov':
Metadata:
encoder : Lavf58.45.100
Stream #0:0: Video: dnxhd (DNXHD) (AVdn / 0x6E645641), yuv422p10le, 1920x1080 [SAR 1:1 DAR 16:9], q=2-1024, 175000 kb/s, 24 fps, 12288 tbn, 24 tbc
Metadata:
encoder : Lavc58.91.100 dnxhd
[Parsed_colorspace_3 # 0000026ac0f7e080] Unsupported input primaries 2 (unknown)
Error while filtering: Invalid argument
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:0
Conversion failed!

FFMPEG refuses to reencode vp9 via h264_nvenc

Using Windows, FFMPEG throws an error when reencoding vp9/opus .webm video into h264_nvenc/aac.
The issue is within trying to reencode via h264_nvenc, as using libx264 works just fine.
h264_nvenc works just fine when reencoding 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!
The error happened not because of vp9, but rather the width of the video.
h264_nvenc does not support width or height above 4096. My solution was to scale the video down from the original 7372x3024 to 3686x1512 using -vf parameter.
The final command is
ffmpeg -i soad.webm -c:a aac -c:v h264_nvenc -vf scale=3686:1512,setsar=1:1 soad.mp4

ffmpeg: kmsgrab to v4l2 loopback device

I've been trying to pipe my screen into a v4l2 loopback device (as a hack to share screen during calls on wayland). This is what I tried so far:
$ sudo modprobe vl42loopback
$ sudo ffmpeg -device /dev/dri/card0 -f kmsgrab -i - -vf 'hwmap=derive_device=vaapi,scale_vaapi=w=1920:h=1080:format=nv12' -f v4l2 /dev/video2
ffmpeg version n4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 10.1.0 (GCC)
configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-avisynth --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-libmfx --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librav1e --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --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. 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
[kmsgrab # 0x55f52ac85380] Using plane 55 to locate framebuffers.
[kmsgrab # 0x55f52ac85380] Template framebuffer is 99: 3840x2160 32bpp 32b depth.
Input #0, kmsgrab, from 'pipe:':
Duration: N/A, start: 1600327750.235546, bitrate: N/A
Stream #0:0: Video: wrapped_avframe, drm_prime, 3840x2160, 29.83 tbr, 1000k tbn, 1000k tbc
Stream mapping:
Stream #0:0 -> #0:0 (wrapped_avframe (native) -> rawvideo (native))
[video4linux2,v4l2 # 0x55f52ac89e40] Unknown V4L2 pixel format equivalent for vaapi_vld
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:0 --
Conversion failed!
Also tried adding -vcodec rawvideo -pix_fmt yuv420p as follows:
sudo ffmpeg -device /dev/dri/card0 -f kmsgrab -i - -vf 'hwmap=derive_device=vaapi,scale_vaapi=w=1920:h=1080:format=nv12' -vcodec rawvideo -pix_fmt yuv420p -f v4l2 /dev/video2
which failed with:
....
Stream mapping:
Stream #0:0 -> #0:0 (wrapped_avframe (native) -> rawvideo (native))
Impossible to convert between the formats supported by the filter 'Parsed_scale_vaapi_1' and the filter 'auto_scaler_0'
Error reinitializing filters!
Failed to inject frame into filter network: Function not implemented
Error while processing the decoded data for stream #0:0
Conversion failed!
How can I get this working?

Error using ffmpeg and libvpx to encode webm from many images

The command I used was :
C:\cmd\ffmpeg\bin\ffmpeg.exe -i "C:\Users\user\Dropbox\Workspace - C#\SnowflakeGenerator\out\out%d.png" -c:v libvpx -b:v 1M "C:\Users\user\Dropbox\Workspace - C#\SnowflakeGenerator\video.webm" -y
The output was:
ffmpeg version N-82889-g54931fd Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 5.4.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
libavutil 55. 43.100 / 55. 43.100
libavcodec 57. 68.100 / 57. 68.100
libavformat 57. 61.100 / 57. 61.100
libavdevice 57. 2.100 / 57. 2.100
libavfilter 6. 68.100 / 6. 68.100
libswscale 4. 3.101 / 4. 3.101
libswresample 2. 4.100 / 2. 4.100
libpostproc 54. 2.100 / 54. 2.100
Input #0, image2, from 'C:\Users\yb5243yv\Dropbox\Workspace - C#\SnowflakeGenerator\out\out%d.png':
Duration: 00:00:21.04, start: 0.000000, bitrate: N/A
Stream #0:0: Video: png, rgba(pc), 1000x1000 [SAR 3779:3779 DAR 1:1], 25 fps, 25 tbr, 25 tbn, 25 tbc
[libvpx # 0000000000be89c0] v1.6.0
[libvpx # 0000000000be89c0] Transparency encoding with auto_alt_ref does not work
Stream mapping:
Stream #0:0 -> #0:0 (png (native) -> vp8 (libvpx))
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
The error is:
[libvpx # 0000000000be89c0] Transparency encoding with auto_alt_ref does not work
and
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
I'm not sure exactly what is causing the issue, I followed this tutorial, however they did not mention the error. I should mention that I am not using audio, so I left the audio encoder out (I did try it with the audio encoder to make sure, and that was not the problem)
Like the error msg says, Transparency encoding with auto_alt_ref does not work, so
ffmpeg.exe -i "out%d.png" -c:v libvpx -b:v 1M -auto-alt-ref 0 "video.webm" -y

Resources