Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FFMPEG cheat sheet

FFMPEG Cheat sheet

Compress MP4 files

ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4

Compressed file to better compatibility (WhatsApp)

ffmpeg -i broken.mp4 -c:v libx264 -profile:v baseline -level 3.0 -pix_fmt yuv420p working.mp4

Convert MOV to MP4

ffmpeg -i input.mov -q:v 0 output.mp4

Convert M4A to MP3

ffmpeg -i filenamee.m4a -acodec libmp3lame -ab 256k output.mp3

Refine MP3

ffmpeg -i file.mp3 -map 0:a:0 -b:a 96k new_file.mp3

Combine to MP3

ffmpeg -i "concat:first.mp3|second.mp3" -acodec copy output.mp3

Add watermark / logo

ffmpeg -i test.mp4 -i watermark2.png \
-filter_complex "pad=height=ih+40:color=#71cbf4,overlay=(main_w-overlay_w)/2:main_h-overlay_h" \
test3.mp4

Trim video

ffmpeg -i movie.mp4 -ss 00:00:03 -t 00:00:08 -async 1 cut.mp4

-ss => start time -t => duration

Extract MP3 from video file

ffmpeg -i videos/Wilderness.mp4 -q:a 0 -map a mp3/Wilderness.mp3

Convert MP3 to Lossless format (Flac)

ffmpeg -i mp3/Wilderness.mp3 -c:a flac flac/Wilderness.flac

Preview cropped video examples

ffplay -i input -vf "crop=in_w:in_h-40"
ffplay -i in.mp4 -vf "crop=800:1000-40"

Crop video examples

ffmpeg -i in.mp4 -filter:v "crop=in_w:in_h-40" -c:a copy out.mp4 
ffmpeg -i in.mp4 -filter:v "crop=800:1000-40" -c:a copy out.mp4

Replace audio (whichever is shorter)

ffmpeg -i video.mp4 -i audio.wav -map 0:v -map 1:a -c:v copy -shortest output.mp4

Combining to 2 MP4 files (didn't work well)

ffmpeg -i output.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts
ffmpeg -i Early_Combined.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts
ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy -bsf:a aac_adtstoasc joined.mp4

Drawtext

ffmpeg -i input.mp4 -filter_complex drawtext="fontfile=/System/Library/Fonts/Supplemental/Georgia.ttf:text='Text to display goes here':fontsize=48: fontcolor=black:x=(w-text_w)/2: y=h-th-80:enable='between(t,0.1,4)',fade=t=in:start_time=0:d=0.5:alpha=1,fade=t=out:start_time=3.7:d=0.5:alpha=1[fg];[0][fg]overlay=format=auto,format=yuv420p" -c:a copy output.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment