basic usage
Use output file as last argument.
ffmpeg output.mp4
File format (and its defaults) are derived from file ending.
Use -i to specify input files.
ffmpeg -i film.mp4 -i subtitles.srt
Several input files are possible.
Use -map to select streams.
ffmpeg -i film.mp4 -i subtitles.srt -map 0:0 -map 0:2 -map 1:0
i:j means take stream with index j in file with index i. File indices are given by order of -i uses in the command line.
Specify output codecs and options.
-c:v copy -c:v mpeg4 -b:v 8000k -c:v libx264 -crf 17 (lower numbers = higher quality) -c:a copy -c:a libmp3lame -b:a 320k -c:a libfdk_aac -b:a 384k -c:a aac -b:a 384k -c:s mov_text
useful options
cutting off borders
centred:
-vf crop=in_w-20:in_h-100
positioned:
-vf crop=in_w-20:in_h-100:20:100
means cut off 10px off top, 10px off bottom, 50px off left, 50px off right.
starting and ending at a specific position
-ss 00:03:40 -t 00:01:12
or
-ss 220 -t 72
numbers in seconds (float)
concatenate same-codec files
Create file containing file names, e.g.:
file 'file1.mp4' file 'file2.mp4'
Then:
ffmpeg -f concat -safe 0 -i .files -c copy output.mp4
extract d frames per second
ffmpeg -i input.mp4 -q:v 2 -r d output-%03d.png
Prefer png for higher quality (does not need -q:v).
To extract only key frames:
ffmpeg -skip_frame nokey -i input.mp4 -q:v 2 -r d output-%03d.png
remove metadata
-map_metadata -1
dump metadata
ffmpeg -i input.mp3 -f ffmetadata metadata.txt