I have had an iPhone for a while now and I keep running into instances where I want to have videos outside of youtube in some format that I can watch on the device. These include windows WMV formatted videos from PDC as well as FVL formatted videos on Flex. I finally broke down and found a working solution to convert pretty much any video into a iPhone/iTunes format using mencoder.
Here is the script I came up with to convert a video:
#!/bin/sh BN=`basename $1 .flv` mencoder $1 -ofps 23.976 -ovc lavc -oac copy -o /tmp/test.$BN.avi mencoder /tmp/test.$BN.avi -o togo/$BN.mp4 -vf scale=480:-10,harddup -lavfopts format=mp4 -faacopts mpeg=4:object=2:raw:br=128 -oac faac -ovc x264 -sws 9 -x264encopts nocabac:level_idc=30:bframes=0:global_header:threads=auto:subq=5:frameref=6:partitions=all:trellis=1:chroma_me:me=umh:bitrate=500 -of lavf rm /tmp/test.$BN.avi
One thing to notice is that I have the file format hard coded in the basename argument. I did this because I didn't need the script to be that generic and I just change it when I move from one format to another. For some reason I found that converting the video with the first statement works best. Without that I had a number of audio sync issues as well as some outright conversion failures .
The options for the first command are
- -ofps output frames per second
- -ovc lavc output codec is lavc
- -oac copy output audio is a copy of the input
- -o the output file
The options for the second command are
- -o the output file
- -vf scale=480:-10,harddup video filter that scales to 480 width and rounds the height to the closest 10/16th width as well as forcing duplicate frames to be encoded in the output
- -lavfopts format=mp4 set the video format options to mp4
- -faacopts mpeg=4:object=2:raw:br=128 set the audio options to mp4
- -oac faac set the audio output format to faac
- -ovc x264 set the output to x264 encoding
- -sws 9 set the scaler options to lanczos
- -x264encopts nocabac:level_idc=30:bframes=0:global_header:threads=auto:subq=5:frameref=6:partitions=all:trellis=1:chroma_me:me=umh:bitrate=500 sets the 265 enocoding options
- -of lavf set the output video format
After converting the video all you need to to do is drag it onto the iTunes Library bar and it will then import it and make it available to sync to your iPhone, touch or iPod.