Friday, March 20, 2009

Batch transcoding with VLC

I have a bunch of MPG videos from my videocam but neither iPhoto nor iMovie would recognise them. Now VLC has a transcoding wizard that'd do the conversion to MP4 nicely, but to do it interactively through the GUI is just too tedious. Using this tip from the VideoLAN Wiki, I used a script to perform the batch transcoding:

#!/bin/bash
vcodec="mp4v"
acodec="mp4a"
bitrate="3072"
arate="192"
ext="mp4"
mux="mp4"
vlc="/Applications/VLC.app/Contents/MacOS/clivlc"
fmt="MPG"
dst="/Dest/Path/"
for a in *$fmt; do
  $vlc -I dummy -vvv "./$a" --sout "#transcode{vcodec=$vcodec,\
  vb=$bitrate,acodec=$acodec,ab=$arate}:standard{mux=$mux,\
  dst=\"$dst$a.$ext\",access=file}" vlc://quit
  touch -m -r $a $dst$a.$ext
done

If you want to try this on Linux or Windows, you should use vlc instead of clivlc. I included the touch command so that the transcoded videos would still have the original capture date/time as their last modified date.

1 comment:

hussein said...

Neaaaaaaaaat :)

Yeah I find iMovie not able to play back audio from my digicam too.

Thanks for the script. It's a timesaver!