Cheat sheets

Cheat sheet: ffmpeg

Convert, cut, and compress video and audio with ffmpeg. invoer and uitvoer are your file names.

Information

What’s in a file? ffprobe -hide_banner invoer.mp4
The version and available formats ffmpeg -version

Converting

To another format, with default settings ffmpeg -i invoer.mkv uitvoer.mp4
Change only the container, without re-encoding (fast) ffmpeg -i invoer.mkv -c copy uitvoer.mp4
To H.264 with good quality (lower number = better) ffmpeg -i invoer.mov -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k uitvoer.mp4
To H.265 (smaller file) ffmpeg -i invoer.mp4 -c:v libx265 -crf 28 -tag:v hvc1 -c:a copy uitvoer.mp4
Make playable everywhere (color format) ffmpeg -i invoer.mp4 -c:v libx264 -pix_fmt yuv420p uitvoer.mp4

Format and speed

Scale down to 1280 width (height automatic) ffmpeg -i invoer.mp4 -vf scale=1280:-2 uitvoer.mp4
Rotate the image 90 degrees ffmpeg -i invoer.mp4 -vf "transpose=1" uitvoer.mp4
Twice as fast ffmpeg -i invoer.mp4 -filter:v "setpts=0.5*PTS" -an uitvoer.mp4
Set the frames per second ffmpeg -i invoer.mp4 -r 30 uitvoer.mp4

Cutting and merging

Extract a section (from 1:00 to 2:30) ffmpeg -ss 00:01:00 -to 00:02:30 -i invoer.mp4 -c copy uitvoer.mp4
A thumbnail at 10 seconds ffmpeg -ss 10 -i invoer.mp4 -frames:v 1 thumbnail.jpg
Concatenate files (list in lijst.txt) ffmpeg -f concat -safe 0 -i lijst.txt -c copy uitvoer.mp4

Audio

Extract the audio as mp3 ffmpeg -i invoer.mp4 -vn -c:a libmp3lame -q:a 2 uitvoer.mp3
Copy the audio unchanged ffmpeg -i invoer.mp4 -vn -c:a copy uitvoer.m4a
Remove the audio ffmpeg -i invoer.mp4 -an -c:v copy uitvoer.mp4
Burn subtitles into the image ffmpeg -i invoer.mp4 -vf subtitles=ondertitel.srt uitvoer.mp4

Images

A sequence of images to a video ffmpeg -framerate 25 -pattern_type glob -i '*.jpg' -c:v libx264 -pix_fmt yuv420p uitvoer.mp4

Good to know

  • lijst.txt for merging contains per line file 'deel1.mp4'.
  • -c copy is fast and doesn’t lose quality, but cutting then only works on keyframes and not all formats can be combined this way.
  • With -y ffmpeg overwrites without asking, with -n never. Existing files are otherwise asked first.

Sources and attribution

This overview is compiled in our own words. Commands and options change per version: check the official documentation when in doubt.