Skip to content

Latest commit

 

History

History
87 lines (57 loc) · 2.56 KB

ffmpeg.md

File metadata and controls

87 lines (57 loc) · 2.56 KB

ffmpeg

Converting videos

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.

References

Compress video

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

References

Extract audio from video

MP3

ffmpeg -i input.mp4 -q:a 0 -map a output.mp3

Copy codec from video

ffmpeg -i input-video.avi -vn -acodec copy output-audio.aac

StackOverflow

Audio to 16khz 16bit mono wav

ffmpeg -i yourfile.mp3 -acodec pcm_s16le -ac 1 -ar 16000 myfile.wav

References

Extract excerpt from video

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.

Re-encoding the output

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

References