Common ffmpeg parameters


Argument Description
-codecs Display codecs
-formats Display formats
-f fmt Force format "fmt"
-i filename Set input file name
-y Overwrite output file
-t secs Force duration to specific length (hh:mm:ss[.xxx])
-fs limit Set file size limit
-ss secs Seek to given time position (hh:mm:ss[.xxx])
-target type Specify target type ("vcd", "svcd", "dvd", "dv", "dv50", "pal-vcd" etc); all format options are set automatically
-b bitrate Video bitrate in bps
-r fps Set frame rate (default 25)
-s WxH Set frame size (default same as source)
-vf scale=W:H Rescale video (use <=1 to scale, e.g. "640:-1" means resize height to scale, -2 means same but maintain even /2 count)
-vf transpose=n Rotate video (0 = 90° counterclockwise and vertical flip; 1 = 90° clockwise; 2 = 90° counterclockwise; 3 = 90° clockwise and vertical flip)
-aspect aspect Set aspect ratio (4:3, 16:9 etc)
-vn Disable video
-pass n Multipass rendering (1 or 2)
-vcodec Force video codec (e.g. "h264", "copy")
-crf nn Constant Rate Factor (0=lossless, 23=default, 17-28=acceptable)
-ar freq Audio frequency (default 44100 Hz)
-ab bitrate Audio bitrate in bps (default 64k)
-ac channels Audio channels (ac=2 to downmix 5.1 to stereo)
-an Disable audio
-acodec Force audio codec ("aac", "mp3", "copy")
-q:a n VBR quality: mp3=0-9, 0=~240kbit/s, 2=~190kbit/s (standard), 4=160kbit/s (medium)
-scodec Force subtitle codec ("copy" to copy stream)
-sn Disable subtitles
-map_metadata -1 Strip ID3 (or any kind of) metadata from input files (-1 is a dummy stream specifier)

Dump information to JSON format:

ffprobe "file.mkv" -v quiet -print_format json \
    -show_streams \
    -show_format \
    -show_programs \
    -show_chapters \
    -show_private_data \

Concatenate two videos two one:

ffmpeg -i movie1.avi -i movie2.avi \
    -filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0]concat=n=2:v=1:a=1[outv][outa]" \
    -map "[outv]" -map "[outa]" result.m4v
  • [0:v:0][0:a:0][1:v:0][1:a:0] means "input 0 video stream 0; input 0 audio stream 0; input 1 video stream 0; input 2 video stream 0"
  • concat=n=2:v=1:a=1 means concatenate filter, two streams, one stream per video and one stream per audio
  • [outv][outa] means map to two result streams, outv and outa
  • -map is used to map streams to output instead of the input streams

Cut part of video out

Generate a video file containing two minutes of video, one 60-second clip from the start and another 60-second clip from 5 minutes into the video.

ffmpeg -i input.mp4 -filter_complex "\
    [0:v] trim=0:60, setpts=PTS-STARTPTS [v1]; \
    [0:a] atrim=0:60, asetpts=PTS-STARTPTS [a1]; \
    [0:v] trim=300:360, setpts=PTS-STARTPTS [v2]; \
    [0:a] atrim=300:360, asetpts=PTS-STARTPTS [a2]; \
    [v1][a1][v2][a2] concat=n=2:a=1:v=1 [outv][outa]" \
    -map "[outv]" -map "[outa]" result.m4v
  • The input stream is trimmed, both audio and video, into streams v1 and a1.
  • The setpts/asetpts filters are very important since that resets the timecode, otherwise there would be tons of dead space in between the clips
  • The two video and audio streams are concatenated into outv and outa
  • ...which are then mapped to the output streams