Converting WMV with mencoder

Steve and I have been working on a YouTube video downloader based in PHP. One of the features that I’ve been adding in is the ability to upload videos of any format and be encoded into a FLV, just like those big YouTube sites.

One of the problems I’ve been having is that the WMV videos race through at over 10 times the speed of the video, and leave the audio playing at normal speed. This, apparently, has to do with WMVs (and any ASF-based video) using a variable frame rate.

To get around this, you simply need to set a frame rate manually with -ofps. So, to convert a video from WMV to Flash video, you’d need a command like this:

<code>mencoder MyVid.wmv -o MyVid.flv -of lavf -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts vcodec=flv:vbitrate=400:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -srate 22050 -ofps 25</code>

This will keep the frame rate to 25 fps. Now, all I need to do is work out how to get the correct frame rate for the whole video…