How to Convert Video Files to MPEG4/H.264 – Software Recommendations

codecsconversionsoftware-recommendationvideo

I want to convert a large number of video files in various formats into .mp4 files (container MPEG-4, codec H.264). I want to do this on an Ubuntu machine, using only command-line tools and I'm willing to install packages from main, restricted, universe and multiverse.

Ideally I'd like to be able to do …

for VIDEO_FILE in *; do
  some_conversion_program $VIDEO_FILE $VIDEO_FILE.mp4
done

… and have all my video files in .mp4 format with container MPEG-4 and codec H.264.

How would you tackle this problem on an Ubuntu machine? What packages do I need to install?

Best Answer

You will need to install these :

sudo apt-get install ffmpeg libavcodec-unstripped-52 libavdevice-unstripped-52 libavformat-unstripped-52 libavutil-unstripped-50 libpostproc-unstripped-51 libswsclale-unstripped-0 x264

In Karmic, Lucid and Maverick you should replace "unstripped" by "extra" but since there is transitional packages this work too.

And then you can use a script with :

for i in *.avi; do ffmpeg -i "$i" -f mp4 "`basename "$i" .avi`.mp4";done

And you can use options like these to set up resolution, video codec and audio codec and audio quality :

for i in *.avi; do ffmpeg -i "$i" -s 352x288 -vcodec libx264 -vpre default -acodec libmp3lame -ab 192k -ac 2 -ar 44100 -f mp4 "`basename "$i" .avi`.mp4";done