.avi file to .webm file with alpha channel - ffmpeg

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

Related

Encoding in h264 with ffmpeg on RTX 3080 fails

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.

How to make ffmpeg re-encode an vp9 webm with alpha into a vp9 webm with alpha

I am trying to find optimal parameters for encoding a transparent video using ffmpeg in my scenario, and as a test, I have been re-encoding a pre-made transparent .webm (vp9 with alpha channel, made using python vidgear) like this:
$ /usr/bin/ffmpeg -i pre-made.webm pre-made-remade.webm
ffmpeg version 4.3.2-0york0~18.04 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuration: --prefix=/usr --extra-version='0york0~18.04' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp
--enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libzimg --enable-pocketsphinx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
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
libavresample 4. 0. 0 / 4. 0. 0
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 'pre-made.webm':
Metadata:
ENCODER : Lavf58.45.100
Duration: 00:01:11.04, start: 0.000000, bitrate: 1107 kb/s
Stream #0:0: Video: vp9 (Profile 0), yuv420p(tv), 1514x1910, SAR 1:1 DAR 757:955, 25 fps, 25 tbr, 1k tbn, 1k tbc (default)
Metadata:
alpha_mode : 1
ENCODER : Lavc58.91.100 libvpx-vp9
DURATION : 00:01:11.040000000
Stream mapping:
Stream #0:0 -> #0:0 (vp9 (native) -> vp9 (libvpx-vp9))
Press [q] to stop, [?] for help
[libvpx-vp9 # 0x55927254b0c0] v1.7.0
[libvpx-vp9 # 0x55927254b0c0] Neither bitrate nor constrained quality specified, using default CRF of 32
Output #0, webm, to 'pre-made-remade.webm':
Metadata:
encoder : Lavf58.45.100
Stream #0:0: Video: vp9 (libvpx-vp9), yuv420p, 1514x1910 [SAR 1:1 DAR 757:955], q=-1--1, 25 fps, 1k tbn, 25 tbc (default)
Metadata:
alpha_mode : 1
DURATION : 00:01:11.040000000
encoder : Lavc58.91.100 libvpx-vp9
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
frame= 1776 fps=8.9 q=0.0 Lsize= 6159kB time=00:01:11.00 bitrate= 710.6kbits/s speed=0.354x
video:6146kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.214488%
According to the ffmpeg logs, the libvpx-vp9 is correctly being chosen, and alpha_mode is 1, which bodes well.
However, when actually viewing the video, the video is no longer trasparent.
How could I force ffmpeg to keep the alpha channel when re-encoding the video? (This also applies when trying to merge audio into the .webm)
Bonus question: what arguments do you recommend for efficient vp9 encoding? I have tried using -threads 16 -speed 4 -tile-columns 6 -frame-parallel 1 -row-mt 1 but it seems to fail at fully utilizing all my CPU cores when encoding with the alpha channel (when piping frames from my python script).
See the line
Stream #0:0: Video: vp9 (Profile 0), yuv420p(tv) ...
The yuv420p indicates that ffmpeg hasn't detected alpha in the input, else it would be yuva420p. To export alpha from VP9 streams, you need to use libvpx decoders, so
ffmpeg -c:v libvpx-vp9 -i pre-made.webm ...

ffmpeg convert to h264 Decoder (codec av1) not found for input stream #0:0

convert a mp4 file to h264 format by this command below
ffmpeg -i agrawsnzefjkuvsqczucbajyhrpaizzaobubqikayxrbfgfep.mp4 -c:v libx264 -c:a aac test.mp4
but I get Decoder (codec av1) not found for input stream #0:0
The result of the detail is below:
#ffmpeg -i agrawsnzefjkuvsqczucbajyhrpaizzaobubqikayxrbfgfep.mp4 -c:v libx264 -c:a aac test.mp4
ffmpeg version 3.4.8-0ubuntu0.2 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuration: --prefix=/usr --extra-version=0ubuntu0.2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'agrawsnzefjkuvsqczucbajyhrpaizzaobubqikayxrbfgfep.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
encoder : Lavf57.83.100
Duration: 00:04:05.95, start: 0.000000, bitrate: 684 kb/s
Stream #0:0(und): Video: av1 (av01 / 0x31307661), none, 1920x1080, 551 kb/s, 25 fps, 25 tbr, 12800 tbn, 12800 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
Metadata:
handler_name : SoundHandler
File 'test.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
Stream #0:0 -> #0:0 (? (?) -> h264 (libx264))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Decoder (codec av1) not found for input stream #0:0
How to fix "Decoder (codec av1) not found for input stream #0:0" error?
There is no native (software) decoder for AV1 in FFmpeg as of v4.4. However, multiple external decoder libraries are supported via wrappers. These libs are libaom, libdav1d and various hardware-accelerated decoders such as nvdec. You'll need recent ffmpeg (4.3+) to avail many of these. Your ffmpeg ver is 3.4.8. Get a static binary for linux from https://johnvansickle.com/ffmpeg/

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

Resources