Wednesday, 20 January 2010

Converting MP4 files to other divX and mp3 formats

I find myself often converting MP4 video files to divX and mp3 format to play on my LG phone.
I used to do this with VLC application but this required too much button poking on my part.

So after reading up on the Linux command line ffmpeg and mencoder utilities I've created this basic shell script to do it automatically.


#!/bin/bash
echo "MP4 Conversion"
for f in *.mp4;
do
echo "...Processing $f file..."
ffmpeg -i "$f" -vn -ac 2 -acodec libmp3lame -ab 128k `echo $f|cut -d. -f1`.mp3 > /dev/null 2>&1
mencoder "$f" -ovc lavc -lavcopts vcodec=mpeg4:vpass=1 -oac mp3lame -lameopts vbr=3 -o `echo $f|cut -d. -f1`.divx > /dev/null 2>&1
done

This will convert all the mp4 files in the local directory to both divx and mp3 format ready to be transferred to my phone. Obviously you need to have the ffmpeg, mencoder and lame mp3 encoder installed on your Linux machine for this too work.

0 comments: