Examples of ffmpeg command lines

August 6, 2017

Examples of ffmpeg command lines.


Convert Video to Audio

Convert video mp4 to audio only mp3, with output quality of 95kb/s (the default is 128kb/s)

ffmpeg -i input_file.mp4 -aq 95k output_file.mp3

Convert video mp4 to audio only mp3, specifying a start time

ffmpeg -ss 00:00:14 -i input_file.mp4 output_file.mp3

Convert video mp4 to audio only mp3, specifying a duration

ffmpeg -t 00:05:00 -i input_file.mp4 output_file.mp3

Resize Video


ffmpeg -i input_file.mov -strict -2 -s 848x478 output_file.mp4

Read Input at Native Frame Rate

Read input at native frame rate. This is useful if CPU usage is high at the faster (default) frame rate reading

ffmpeg -re -i input_file.mov -strict -2 output_file.mp4

Remove Chapters metadata from Video


ffmpeg -i input.m4v -map_chapters -1 -strict -2 output_file.m4v

OR


ffmpeg -i input_file.m4v -map_chapters -1 -c:v copy -c:a copy output_file.m4v

Change Video Title


ffmpeg -i input_file.m4v -metadata title=“New Title” -strict -2 output_file.m4v

OR


ffmpeg -i input_file.m4v -metadata title=“New Title” -c:v copy -c:a copy output_file.m4v

Change Video Resolution and Bitrate

Change Video Resolution


ffmpeg -i input_file.mp4 -s 1280x720 -strict -2 output_file.mp4

Change Video Bitrate


ffmpeg -i input_file.mp4 -b:v 2000k -strict - 2 output_file.mp4

Remove Audio from Video


ffmpeg -i input_file.mp4 -c copy -an output_file.mp4

Extract and Combine Video and Audio

Extract only Video


ffmpeg -i input_file.flv -c:v copy -an output_file.m4v

Extract only Audio


ffmpeg -i input_file.flv -c:a copy -vn output_file.m4a

Combine Video and Audio


ffmpeg -i input_file.m4v -i input_file.m4a -c copy output_file.mp4

Delay Video or Audio

Delay Video by 1.23 seconds


ffmpeg -i input_file.mp4 -itsoffset 1.23 -i input_file.mp4 -map 1:v -map 0:a -c copy output_file.mp4

Delay Audio by 1.23 seconds


ffmpeg -i input_file.mp4 -itsoffset 1.23 -i input_file.mp4 -map 0:v -map 1:a -c copy output_file.mp4

Concatenate Files

We need a text file with the list of files in the following format:

file '/path/to/file1.wav'
file '/path/to/file2.wav'
file '/path/to/file3.wav'

Let’s assume we have the above list on a file named ‘list.txt’
We would use the following to concatenate the files:


ffmpeg -f concat -i list.txt -c copy output_file.wav