It is possible to easily convert media files with the default settings of ffmpeg
. For example, all of the following commands should work as expected:
ffmpeg -i input.avi output.mp4
ffmpeg -i input.mp4 output.avi
ffmpeg -i input.mkv output.mp4
ffmpeg -i input.mkv output.avi
However, it is also possible to select the specific codecs. For instance:
ffmpeg -i input.avi -c:v libx264 -crf 23 -c:a aac -b:a 192k output.mp4
In this case, the -crf
flag indicates the Constant Rate Factor and the lower the value the higher the quality. Typical values are in between 18 and 28.
- A quick guide to using FFmpeg to convert media files, opensource.com
- What is -crf used for in FFmpeg?, superuser
ffmpeg -i input.mp4 -vcodec h264 -acodec aac output.mp4
ffmpeg -i input.mp4 -vcodec libx265 -crf 20 output.mp4
The higher crf
the more compression
ffmpeg -i input.mp4 -q:a 0 -map a output.mp3
ffmpeg -i input-video.avi -vn -acodec copy output-audio.aac
ffmpeg -i yourfile.mp3 -acodec pcm_s16le -ac 1 -ar 16000 myfile.wav
ffmpeg -i input.mp4 -vcodec copy -acodec copy -ss 00:00:00 -t 01:00:00 -sn part1.mp4
-ss
specifies the start time.-t
specifies the duration of the clip.-to
specifies the end time.
Sometimes, using -c copy leads to output files that some players cannot process properly (showing black frames at the beginning or with audio-video sync errors).
It is possible to re-encode the output video and audio according to the format you chose. For example:
ffmpeg -i input.mkv -ss 00:00:02.500 -to 00:00:15.200 -c:v libx264 -crf 23 -c:a aac -b:a 192k excerpt.mp4