Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save datavudeja/07b2aa697d339f8a2be046c84b037409 to your computer and use it in GitHub Desktop.

Select an option

Save datavudeja/07b2aa697d339f8a2be046c84b037409 to your computer and use it in GitHub Desktop.

Transform an MP4 file to its H.264 codec using FFmpeg

You can do this will the following command:

ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k output.mp4

This command uses the following syntax:

-i input.mp4: Specifies the input file that you want to transform to H.264. -c:v libx264: Specifies the H.264 video codec that will be used for encoding. -crf 23: Specifies the quality of the video compression. A lower value means higher quality, but a larger output file. A value of 23 is a good choice for most cases. -preset medium: Specifies the encoding speed. The medium value is a good choice for most cases, as it provides a good balance between speed and quality. -c:a aac: Specifies the AAC audio codec that will be used for encoding. -b:a 128k: Specifies the audio bitrate in kilobits per second. A value of 128k is a good choice for most cases. output.mp4: Specifies the name and location of the output file.

Note that the transformation to H.264 may take some time, depending on the duration of the input file and the power of your computer. You may also want to adjust the values of -crf and -preset to get the best results for your specific case.

For more examples see video conversion with FFmpeg.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment