Sergio Tapia
Sergio Tapia's Blog

Sergio Tapia's Blog

My favorite FFmpeg cookbook.

Sergio Tapia's photo
Sergio Tapia
·Mar 11, 2022·

Subscribe to my newsletter and never miss my upcoming articles

I love FFmpeg. ffmpeg.org

I think it's one of the wonders of the world. A feat in engineering that has had so many people working on it, too powerful for one person to know every nook and cranny. It's gargantuan and incredibly complex.

It also fits too many use cases to count!

Here's my cookbook for FFmpeg. Useful recipes I use almost daily to share things online with friends, archive for myself and otherwise fiddle around with things.

Convert video to Twitter friendly format.

ffmpeg -i video.mp4 -vcodec libx264 -pix_fmt yuv420p -strict experimental -r 30 -t 2:20 -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -vb 1024k -acodec aac -ar 44100 -ac 2 -minrate 1024k -maxrate 1024k -bufsize 1024k -movflags +faststart output.mp4

Convert video to WhatsApp friendly format.

ffmpeg.exe -i video.mp4 -c:v libx264 -profile:v baseline -level 3.0 -pix_fmt yuv420p video-whatsapp.mp4

Convert a funny gif to shareable friendly MP4 format.

First, loop the GIF a few times so the video plays and people can enjoy your meme! Then convert that bigger GIF to an MP4.

ffmpeg.exe -stream_loop 3 -i .\funny.gif funny-loop.gif
ffmpeg.exe -i funny-loop.gif -f gif funny-loop-whatsapp.mp4
ffmpeg.exe -i funny-loop-whatsapp.mp4 -c:v libx264 -profile:v baseline -level 3.0 -pix_fmt yuv420p output.mp4

Convert video to x265 for archiving (same resolution).

ffmpeg.exe -i myvideo.mp4 -c:v libx265 -vtag hvc1 -c:a copy myvideo-x265.mp4

Trim video and grab specific timestamps.

ffmpeg.exe -ss 00:00:10 -t 10 -i '.\Lord of war [K1HEibypsTY].webm' trim.mp4

Mix audio on to video.

Here my audio is larger than my video, and I want to mix the audio in with the video and cut it off. -shortest will use whichever is shorted, audio or video.

ffmpeg.exe -i .\trim.mp4 -i audio.mp3 -c copy -map 0:v:0 -map 1:a:0 -shortest mix.mp4
 
Share this