FFmpeg Cookbook: frequently used ffmpeg commands and parameters

Last Update: Dec 5, 2024

Here is a summary of some frequently used FFmpeg commands, and parameters, for quick reference.

Resize Video

# specific dimension ffmpeg -i input.avi -s 720x480 -c:a copy output.mp4 # specify one dimension ffmpeg -i input.avi -filter:v scale=720:-1 -c:a copy output.mp4
  • -c:a copy apply the same codec for audio stream. a can be v (video stream) or s (subtitle streams)

  • -filter:v apply filter to the video stream, this is identical to -vf

Pad Video

# ffmpeg -i "input.mov" -c:a copy -c:v copy -vf "pad=width=1920:height=1080:x=-1:y=-1:color=black" output.mp4
  • -vf "pad=width=1920:height=1080:x=-1:y=-1:color=black" pad the video to 1920x1080, x and y are the coordinates of the padded color, the color can also in the 0x000000 format

Crop Video

ffmpeg -i in.mp4 -vf "crop=tx:ty:width:height" out.mp4

Trim Video

# start time + duration, the unit is second ffmpeg -i input.wmv -c copy -ss 30 -t 10 output.mp4 # start time + duration, more accurate time ffmpeg -i input.wmv -c copy -ss 00:00:30.0 -t 00:00:10.0 output.mp4

Change Codec

# ffmpeg -i input.mov -c:v libx264 -pix_fmt yuv420p -c:a aac output.mp4
  • -c:v libx264 sets the H.264 codec for video compression

  • -pix_fmt yuv420p changes the pixel format to one compatible with H.264

  • -c:a aac compresses the audio stream using the AAC codec

Change bitrate

# ffmpeg -i input.mov -b:v 5000k output.mp4
  • -b:v 5000k set the bitrate to 5000k

Extract Audio

# ffmpeg -i input.mp4 -map 0:a -c copy output.mp3
  • -map 0:a map audio streams from the first input file to the output. 0 refers to the first input file. If you have multiple input files, they are indexed starting from 0. a refers to the audio streams. Other possible stream specifiers include v for video and s for subtitles.

Simple Format Convert

# default options based on the file name extension ffmpeg -i input.mov output.mp3

See also ffmpeg's official docs: https://www.ffmpeg.org/ffmpeg.html



Thanks for reading. Stay Awsome!