FFmpeg: Difference between revisions

No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 250: Line 250:
Add a background to transparent images.<br>
Add a background to transparent images.<br>
<pre>
<pre>
ffmpeg -i in.mov -filter_complex
ffmpeg -i in.mov -filter_complex "[0]format=pix_fmts=yuva420p,split=2[bg][fg];[bg]drawbox=c=white@1:replace=1:t=fill[bg];[bg][fg]overlay=format=auto" -c:a copy new.mov
      "[0]format=pix_fmts=yuva420p,split=2[bg][fg];[bg]drawbox=c=white@1:replace=1:t=fill[bg];
        [bg][fg]overlay=format=auto" -c:a copy new.mov
</pre>
</pre>


Line 356: Line 354:


==JavaScript API==
==JavaScript API==
To use FFmpeg in a browser, see [https://ffmpegwasm.github.io/ ffmpegwasm].   
To use FFmpeg in a browser, see [https://ffmpegwasm.netlify.app/ ffmpegwasm].   
Note: I have not tried this. It uses CLI commands, not library API commands.
This is used in https://davidl.me/apps/media/index.html.


==My Preferences==
==My Preferences==
My preferences for encoding video
My preferences for encoding video
===H264===
I mostly use H264 when working on projects for compatibility purposes. Here I typically don't need the smallest file size or best quality, prioritizing encoding speed.
<syntaxhighlight lang="bash">
!#/bin/bash


ffmpeg -i $1 -c:v libx264 -crf 28 -preset medium -pix_fmt yuv420p -c:a libfdk_aac -b:a 128K $2
===AV1===
</syntaxhighlight>
Prefer AV1 for encoding video on on modern devices.


;Notes
* MP4 is ok


===H265/HEVC===
===H265/HEVC===
H264/HEVC is used for archival purposes to minimize the file size and maximize the quality.
H264/HEVC is now a good tradeoff between size, quality, and compatibility.
This has been supported on devices since Android 5.0 (2014).
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
!#/bin/bash
ffmpeg -i $1 -c:v libx265 -crf 23 -preset slow -pix_fmt yuv444p10le -c:a libopus -b:a 128K $2
ffmpeg -i $1 -c:v libx265 -crf 23 -preset slow -pix_fmt yuv444p10le -c:a libopus -b:a 128K $2
</syntaxhighlight>
</syntaxhighlight>


;Notes
;Notes
* You need to output to a MKV file
* The pixel format <code>yuv444p10le</code> is 10 bit color without chroma subsampling. If your source is lower, you can use <code>yuv420p</code> instead for 8-bit color and 4:2:0 chroma subsampling.
* The pixel format <code>yuv444p10le</code> is 10 bit color without chroma subsampling. If your source is lower, you can use <code>yuv420p</code> instead for 8-bit color and 4:2:0 chroma subsampling.


===AV1===
===H264===
If you need compatability with very old and low end devices.
<syntaxhighlight lang="bash">
ffmpeg -i $1 -c:v libx264 -crf 28 -preset medium -pix_fmt yuv420p -c:a libfdk_aac -b:a 128K $2
</syntaxhighlight>
 
===Opus===
 
For streaming:
<syntaxhighlight lang="bash">
ffmpeg -i input.wav -c:a libopus -b:a 96k output.opus
</syntaxhighlight>
 
See https://wiki.xiph.org/Opus_Recommended_Settings