Skip to content

FFmpeg commands

Dani János edited this page Jul 23, 2020 · 3 revisions

Transcode to H.264

ffmpeg -i input_file -c:v libx264 -pix_fmt yuv420p -c:a aac -strict -2 output_file


This command takes an input file and transcodes it to H.264 with an .mp4 wrapper, keeping the audio the same codec as the original. The libx264 codec defaults to a “medium” preset for compression quality and a CRF of 23. CRF stands for constant rate factor and determines the quality and file size of the resulting H.264 video. A low CRF means high quality and large file size; a high CRF means the opposite.

  • -c:v libx264

tells FFmpeg to encode the video stream as H.264

  • -pix_fmt yuv420p

libx264 will use a chroma subsampling scheme that is the closest match to that of the input. This can result in Y′CBCR 4:2:0, 4:2:2, or 4:4:4 chroma subsampling. QuickTime and most other non-FFmpeg based players can’t decode H.264 files that are not 4:2:0. In order to allow the video to play in all players, you can specify 4:2:0 chroma subsampling.

  • -c:a aac

encode audio as AAC. AAC is the codec most often used for audio streams within an .mp4 container.

  • -strict -2

It's for "The encoder 'aac' is experimental but experimental codecs are not enabled" error handling. It is very important where the -strict -2 is added, it should be just before the last argument!


By using this command we create video contents for web:

ffmpeg -i input.mp4 -ar 44100 -c:v libx264 -b:v 2M -maxrate 2M -bufsize 1M -movflags +faststart output.mp4

The explanations of these command arguments are the following:

  • -ar 44100

Sets the audio sampling rate to 441000 Hz.

  • -c:v libx264 -b:v 2M -maxrate 2M -bufsize 1M

Sets the average video bitrate to maximum 2MB.

  • -movflags +faststart

For making a video playable under HTML5.

sources:

  1. amiaopensource
  2. stackoverflow
Clone this wiki locally