# Best FFmpeg Cookbook: My Go-To Recipes

I love FFmpeg. https://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.

# Create a timelapse using pictures in a folder.

```powershell
ffmpeg -framerate 30 -pattern_type glob -i '*.JPG' -c:v libx264 -r 30 -pix_fmt yuv420p timelapse.mp4
```

# Add meme caption to videos.

```plaintext
ffmpeg -i "video.mp4" -vf "drawtext=text='TOP TEXT':fontfile='C\:\\Windows\\Fonts\\arial.ttf':fontcolor=white:fontsize=72:borderw=5:x=(w-text_w)/2:y=(h*0.05)" -c:a copy output_with_top_text.mp4

ffmpeg -i "video.mp4" -vf "drawtext=text='ROFL':fontfile='C\:\\Windows\\Fonts\\arial.ttf':fontcolor=white:fontsize=72:borderw=5:x=(w-text_w)/2:y=(h*0.05), drawtext=text='LMAO':fontfile='C\:\\Windows\\Fonts\\arial.ttf':fontcolor=white:fontsize=72:borderw=5:x=(w-text_w)/2:y=(h-text_h)-(h*0.05)" -c:a copy output_with_text.mp4
```

# Convert video to Twitter friendly format.

```plaintext
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.

```plaintext
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.

```plaintext
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).

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

# Trim video and grab specific timestamps.

```plaintext
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.

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