`ffmpeg`
simple cheatsheet
Geese hanging out in The King's Garden, Copenhagen. I don't think they like me.
Now and then I'll want to upload a video to my pull request to make it easier to review, but the file size is over the limit. I pull up ffmpeg
in my terminal to compress it, only to realize I forgot how it works.
I decided to write down some notes on how to use it. Then I thought I should just share them. And here we are. Hope this is useful to somebody besides myself.
`man ffmpeg`
but you don't need a PhD
NAME ffmpeg - ffmpeg media converter EXAMPLE ffmpeg -i input.mp4 -c:v libx265 -preset medium output.mp4 OPTIONS -i [path] Input file path. -c:v [libx264|libx265|libvpx] Video codec. '[libx264|libx265]' are mp4. '[libx265]' has better compression but worse compatibility. '[libvpx]' is webm. -c:a [aac|ac3|libmp3lame|copy] Audio codec. 'copy' means to skip re-encoding audio. -an Discard audio. -preset [ultrafast|superfast|veryfast|faster|fast| medium|slow|slower|veryslow] Settings preset, to be used with [libx264|libx265]. Each option has diminishing returns over the next. -crf [0 <= number <= 51] Compression quality (Constant Rate Factor). Default is '23'. Lower gives better quality. '0' is lossless. Valid range depends on specified video codec. Range given here is for '[libx264|libx265]'. Range for '[libvpx]' is '[4 <= number <= 63]'. -b:v Video bitrate. To be used with '[libvpx]'. Examples: 360p -> -b:v 1M 480p -> -b:v 2M 720p -> -b:v 5M 1080p -> -b:v 8M 2K -> -b:v 16M 4K -> -b:v 40M -vf Filtering tools. Use for scaling a video. Examples: 360p -> -vf scale=640:360 480p -> -vf scale=854:480 720p -> -vf scale=1280:720 1080p -> -vf scale=1920:1080 2K -> -vf scale=2048:1080 4K -> -vf scale=3840:2160 For a vertical video, you'll probably want to flip values around.
Example
Here's some jellyfish 🪼
ffmpeg -i jellyfish.mov -c:v libvpx -an -crf 4 -b:v 1.5M jellyfish.webm
# before 44.5 MB
# after 4.3 MB