💾 Archived View for sebastien-mouchet.fr › blog › en › ffmpeg-cheat-sheet.gmi captured on 2024-05-10 at 10:52:32. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-03-21)

-=-=-=-=-=-=-

FFmpeg cheat sheet

Posted on January 20, 2024, by SĂ©bastien

Cet article est également disponible en français.

———

This is a highly abridged version of the following blog post:

Audio/video encoding with FFmpeg

———

Audio, lossless → FLAC

ffmpeg -i input.wav output.flac

“-i” stands for “input file”.

Audio, lossy, maximum compatibility → MP3

ffmpeg -i input.wav -c:a libmp3lame -q:a 0 output.mp3

With the LAME MP3 encoder, quality goes from 0 (highest) to 9 (lowest). Using the “quality” parameter instructs LAME to use a variable bitrate.

Audio, lossy, state of the art → Opus

ffmpeg -i input.wav -c:a libopus -b:a 160k output.opus

“-b:a” stands for “audio bitrate” (you can also use “-ab”). By default, the Opus encoder is in variable bitrate mode (not constant bitrate), so this is a target averate bitrate.

Video, wide compatibility → H.264 + MP3

ffmpeg -i input.mp4 -c:v libx264 -crf 24 -c:a libmp3lame -q:a 2 output.mp4

“-c:v” stands for “video codec” (alias to “-vcodec”).

The CRF mode is a “constant quality” mode, as opposed to a “constant bitrate” mode.

Reasonable values for the CRF parameter are between 18 (very high quality) and 28 (medium quality).

Video, state-of-the-art → AV1 + Opus

ffmpeg -i input.mp4 -c:v libsvtav1 -crf 38 -preset 4 -c:a libopus -b:a 128k output.webm

CRF values for “SVT-AV1” are tuned differently than for x264, but the basic idea is the same: increasing it results in a lower quality, and a smaller file size.

The “preset” option is used to adjust the tradeoff between quality and encoding speed. 0 is be the highest quality, and 13 is be the fastest. Keep it as low as you can afford.

Intermediate video codec: VP9

ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 40 -b:v 0 -c:a libopus -b:a 128k output.webm