ffmpeg cheatsheet

Examples

H265 working in Quicktime Player

ffmpeg -i <inputfile> -c:v libx265 -tag:v hvc1 -vf format=yuv420p Output.mp4

Convert a whole subdirectory

cd 265_Videos
for f in ../*.mov; do o=${f##*/}; ffmpeg -i $f -c:v libx265 -crf 25 -tag:v hvc1 ${o%.*}.h265.mp4; done

Create an Overcast Style Video of a Podcast

ffmpeg -f lavfi -i color=c=white:s=540x960 -loop 1 -framerate 1/5 -i podcast_logo.jpg -ss 30:00 -i podcast_episode.mp3 -t 13 -filter_complex "[1:v]scale=440:440:flags=bicubic[cover];[0:v]drawtext=fontfile=/System/Library/Fonts/SFNSDisplay.ttf:fontsize=60:fontcolor=black:x=(w-text_w)/2:y=680:text='UKW001',drawtext=fontfile=/System/Library/Fonts/SFNSDisplay.ttf:fontsize=40:fontcolor=black:x=(w-text_w)/2:y=(680+70):text='Schalke ist durchgeimpft',drawtext=fontfile=/System/Library/Fonts/SFNSDisplay.ttf:fontsize=40:fontcolor=black:x=(w-110)/2:y=(720+60+80-ascent):text='%{pts\:gmtime\:1800\:%M\\\\\:%S}'[title];[title][cover]overlay=(W-w)/2:140:shortest=1,format=yuv420p[vo]" -map "[vo]" -map 2:a -c:v h264 -crf 31 -r 30  -movflags +faststart podcast-snippet.mp4

Switches

Common switches

-codecs          # list codecs
-c:v             # video codec (-vcodec) - 'copy' to copy stream
-c:a             # audio codec (-acodec)
-af "volume=2.0" # increase audio volume
-movflags faststart # rearrange headers for internet consumption

Testruns

-ss 00:20:00.0 -t 10 # 10 seconds, 20 min in 

Bitrate

-b:v 1M          # video bitrate (1M = 1Mbit/s)
-b:a 1M          # audio bitrate

Video

-crf CRF         # CRF lower is higher quality
                 # 23 is default for h264, 26 for h265
                 # meaningful range between 19 and 29
-aspect RATIO    # aspect ratio (4:3, 16:9, or 1.25)
-r RATE          # frame rate per sec
-s WIDTHxHEIGHT  # frame size
-vn              # no video

Audio

-ac 1            # audio channels (1=mono, 2=stereo)
-an              # no audio