FFMPEG using the H264 codec
Posted #CaffeeLog#Linux
I’ve often the “problem”, that I want to show a movie while traveling, but the mpg-file on my PC is a few GB big and the disk-space on my mobile Devices are limited. So, I want to convert my mpg-files to mp4 files, with less or no loss of quality, but a huge reduce of bytes.
And every time I’m searching around the web to find the correct ffmpeg-options. In order not to search the next time I need it, I write it down:
ffmpeg -i input.mpg -c:v libx264 -c:a ac3 output.mp4
The options:
- i: should be clear
- c:v specifies the video codec
- c:a specifies the preferred audio codec
Sometimes the result isn’t quite satisfactory, so we can give ffmpeg more specific arguments:
ffmpeg -i video.mpg -vcodec libx264 -preset slow -crf 22 -threads 4 -acodec mpeg4aac -ab 256k -ar 44100 -vol 500 movie.mp4
The specific options in detail:
- preset -crf: specifies the preset-file, with some option=value pairs. “A slower preset will provide better compression (compression is quality per filesize)” (from ffmpeg-wiki). See “-preset help” for all available presets.
- threads should be clear
- ab specifies the audio bitrate
- ar specifies the auido frequency
- vol should amplify the volume? (it works, but I don’t know it exactly)