Edit videos with FFmpeg

FFmpeg is a powerful command-line tool for working with video, audio, and images. It can do it all. It has support for literally everything and it powers everything from Netflix to YouTube. You can find it under the hood of a lot of video tools.
FFmpeg can speed up your workflow dramatically. Here are some of the tools I use often:
1. Add text on top of a video
This is a nice command just to add a title or caption to a video. You can customize the font, size, color, position, and duration of the text.
ffmpeg -hide_banner -stats -y \
-i input.mp4 \
-vf "drawtext=fontfile='/System/Library/Fonts/Helvetica.ttc':text='My Custom Title':fontcolor=white:fontsize=256:x=(w-text_w)/2:y=200:line_spacing=40:enable='lte(t,5)'" \
-c:v h264_videotoolbox -b:v 8M \
-c:a aac -b:a 192k \
-movflags +faststart \
output.mp4
ffmpeg
→ runs the ffmpeg program-hide_banner
→ suppress startup banner (build/config info)-stats
→ show encoding progress (fps, size, bitrate, time)-y
→ overwrite output file without asking-i input.mp4
→ input video file-vf
→ apply a video filterdrawtext=
→ overlay text filtertext='My Custom Title'
→ hardcoded text stringfontfile='/System/Library/Fonts/Helvetica.ttc
→ Use Helveticafontcolor=white
→ set text color to whitefontsize=256
→ text size in pixelsx=(w-text_w)/2
→ center text horizontallyy=200
→ place text 200px from topline_spacing=40
→ vertical spacing between linesenable='lte(t,5)'
→ show text only for first 5 seconds-c:v h264_videotoolbox
→ use Apple’s hardware H.264 encoder-b:v 8M
→ set video bitrate to 8 Mbps-c:a aac
→ use AAC audio codec-b:a 192k
→ set audio bitrate to 192 kbps-movflags +faststart
→ optimize MP4 for web playbackoutput.mp4
→ output file name
2. Merge multiple videos into one
Just create a new file with all the videos stitched together.
ffmpeg -f concat -safe 0 -i <(for f in *.mp4; do echo "file '$PWD/$f'"; done) -c copy output.mp4
3. Create a Instagram Story Video from Images
If you want to stitch multiple images into a 9x16 vertical video (perfect for Instagram Stories), you can do this:
ffmpeg -framerate 1/1.5 -i %d.jpg -vf "scale=1080:1920,format=yuv420p" -c:v libx264 -crf 23 -preset fast output.mp4
This command:
-framerate 1/1.5
→ Each image shows for 1.5 secondsscale=1080:1920
→ Sets the video to portrait size (9:16 ratio)libx264
→ High-quality compression for MP4
4. Convert MP4 to GIF
Need to make lightweight GIFs? This works even on low-power devices like the Raspberry Pi:
ffmpeg -i input.mp4 -vf "fps=15,scale=1280:-1:flags=lanczos" output.gif
Key parameters:
fps=15
→ Keeps the file size reasonablescale=1280:-1
→ Resizes while preserving aspect ratio
5. Adjust a GIF to Fullscreen Size
This is a small trick I use on my Raspberry Pi powered art frame.
If your GIF doesn`t fill the screen, you can extend it with a background color. Use a color picker to grab a matching background:
First check the resolution on your display:
On macOS:
system_profiler SPDisplaysDataType | grep Resolution
On Linux
xrandr | grep '*'
Then use ImageMagick to resize and add a background color:
magick square.gif -coalesce -background "#333333" -gravity center -extent 656x1216 -layers optimize output.gif
6. Convert GIF to MP4
Converting GIFs to MP4 makes them smaller and more web-friendly:
ffmpeg -i input.gif -c:v libx264 -preset slow -crf 23 -pix_fmt yuv420p output.mp4
7. Create a GIF from MP4
A smaller optimized for web
ffmpeg -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos" -c:v pam -f image2pipe - | convert -delay 10 - -loop 0 -layers optimize output.gif
A higher-quality GIF:
ffmpeg -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos" -c:v pam -f image2pipe - | convert -delay 10 - -loop 0 -layers optimize output.gif
8. Convert Video to a Sequence of Images
This is great for making thumbnails or analyzing video frames:
ffmpeg -i "input.mp4" "frames/%04d.jpg"
9. Lower Audio Volume
Quickly adjust audio levels:
ffmpeg -i ac.mp4 -af volume=7 -vcodec copy ac2.mp4
10. Speed Up a Video
Perfect for timelapse-style edits:
ffmpeg -i mp4.mp4 -filter:v "setpts=PTS/6" output.mp4
filter:v "setpts=PTS/6"
: Applies a video filter that modifies the presentation timestamp (PTS) of each framesetpts
is the filter that controls the speed of video playbackPTS/6
means each frame will be displayed for 1/6th of its original duration, resulting in 6x faster playback
11. Add Audio to a Video Recording
Add background music:
ffmpeg -i 1.mp4 -i audio.mp3 -map 0 -map 1:a -c:v copy -shortest output.mp4
12. Convert from MOV to MP4
Fast rewrapping without re-encoding:
ffmpeg -i movie.mov -vcodec copy -acodec copy out.mp4
13. Change Video Resolution
Resize videos easily:
ffmpeg -i input.avi -s 720x480 -c:a copy output.mkv
14. Remove Audio from a Video
Mute a video while keeping the visuals intact:
ffmpeg -i input.mp4 -an output.mp4
15. Extract Images from a Video
Grab one image per second:
ffmpeg -i input.mp4 -r 1 -f image2 image-%2d.png
Final Thoughts
FFmpeg can look intimidating at first, but once you get comfortable, it becomes one of the fastest ways to manipulate media.