FFmpeg is a powerful and extensible open-source software tool designed for audio and video processing. It allows us to manipulate, convert, transform, apply filters, among a large number of multimedia formats efficiently and accurately.
FFmpeg provides a command-line interface for performing complex tasks programmatically. And there are many many many (many!) possible combinations.
Of course, I never remember most commands, so I have my cheat sheet. I share it with you in case it is useful to you, for those of us with a fish memory 🐠. I hope it is useful for you!
To obtain information
Get system information
Get the available codecs in FFmpeg.
ffmpeg -codecs
ffmpeg -formats
Get video information
Displays detailed information about a video file, such as duration, resolution, audio and video codecs.
ffmpeg -i video.mp4
Get information without copyright banner
Displays information about a video file without showing the copyright banner.
ffmpeg -i video.flv -hide_banner
Save information to a JSON file
Saves detailed information about a video file in JSON format.
ffprobe -i video.flv -print_format json -hide_banner
To convert videos
Convert between video formats
Converts a video file from one format to another.
ffmpeg -i video_original.avi output.mp4
Recompress video
Recompresses a video using the libx264 codec to improve quality and reduce file size.
ffmpeg -i youtube.flv -c:v libx264 filename.mp4
Concatenate multiple videos
Merges several video files into one without re-encoding.
ffmpeg -i "concat:video1.mp4|video2.mp4|video3.mp4" -c copy output.mp4
Extract video segment
Cuts a specific segment from a video without re-encoding.
ffmpeg -i video.mp4 -ss 00:01:30 -t 00:00:30 -codec copy output.mp4
Change video speed
Adjusts the video speed by changing the frames per second.
ffmpeg -i video.mp4 -filter:v "setpts=0.5*PTS" output.mp4
To transform videos
Scale video
Changes the resolution of a video while maintaining the aspect ratio.
ffmpeg -i video.mp4 -vf scale=640:360 output.mp4
Scale video proportionally
Adjusts the height of a video while maintaining the original aspect ratio.
ffmpeg -i video.mp4 -vf scale=320:-1 output.mp4
Rotate video
Rotates a video clockwise.
ffmpeg -i video.mp4 -vf transpose=clock output.mp4
Flip video
Flips a video horizontally or vertically.
ffmpeg -i video.mp4 -vf hflip output.mp4
ffmpeg -i video.mp4 -vf vflip output.mp4
Crop video
Crops a video to specific resolution and position.
ffmpeg -i video.mp4 -filter:v "crop=640:480:200:150" output.mp4
Where
- 640:480, width and height
- 200:150, X, Y coordinates of the crop
Add watermark
Adds a logo as a watermark on a video.
ffmpeg -i video.mp4 -i logo.png -filter_complex overlay=10:10 output.mp4
For managing audio
Volume
Increase audio volume
Boosts the volume of a video.
ffmpeg -i video.mp4 -af 'volume=0.5' output.mp4
Mute video
Removes the audio track from a video.
ffmpeg -i video.mp4 -an output.mp4
Add or remove tracks
Extract audio from a video
Extracts the audio track from a video file.
ffmpeg -i video.mp4 -vn output.mp3
Add audio track
Adds an audio track to an existing video.
ffmpeg -i video.mp4 -i audio.mp3 -map 0:v -map 0:a -map 1:a -vcodec copy output.mp4
Conversion and resampling
Convert between audio formats
Converts an audio file from one format to another.
ffmpeg -i audio.mp3 -acodec pcm_s16le output.wav
Cut audio
Cuts a segment of audio without re-encoding.
ffmpeg -i audio.mp3 -ss 00:01:30 -t 30 -acodec copy output.mp3
Recompress audio
Recompresses an audio file with a bitrate of 128.
ffmpeg -i audio.mp3 -ab 128 output.mp3
Resample audio
Changes the sampling rate of an audio file.
ffmpeg -i audio.mp3 -ar 16000 output.mp3
Related to images
Extract images from video
Extract frames from a video
Extracts a specific frame from a video.
ffmpeg -i video.mp4 -ss 00:00:30 -vframes 1 output.png
Extract images every 15 seconds (fps 1/15)
Extracts images from a video at specific intervals.
ffmpeg -i video.mp4 -vf "fps=1/15,select='not(mod(n,1))'" output_%d.png
Extract a GIF from a video
Converts a video into an animated GIF.
ffmpeg -i video.mp4 -vf scale=300:-1 -t 10 -r 10 output.gif
Create video from images
Combine images into a video
Combines static images into a video.
ffmpeg -i video.mp4 -r 0.25 output_%04d.png
Create a video with a static image and audio
Creates a video with a static image and an audio file.
ffmpeg -loop 1 -y -i imagen.png -i audio.mp3 -shortest output.mp4
Concatenate images into a video
Combines JPG images into a video.
cat *.JPG | ffmpeg -f image2pipe -r 0.3 -vcodec mjpeg -i – -vcodec libx264 output.mp4