Monday, July 11, 2011

Convert videos to iPad 2 format

Recorded programs on my MythTV are in a lossless HD mpg format, which doesn't play well on my iPad2 using AirVideo Server over wlan (via wine). So, instead of having AirVideo Server converting it through the wine abstraction layer (which requires more CPU/memory, and uses ffmpeg.exe anyway), I just run this user job from my MythTV server to convert the files that I care to watch on my iPad.

Step 1:
Create this file which I call /usr/bin/mythconverttoipad. If you have an issue with "too may threads," remove -threads 16. I am using this script on a 3 core machine, the -threads option speeds things up a bit.

#!/bin/bash
DIR=$1
FILE=$2

echo $DIR
echo $FILE

ffmpeg -y -i $DIR/$FILE -ab 320kb -vcodec libx264 -b 3200kb -s 1280x720 -threads 16 $DIR/$FILE.m4v


Step 2:
Make the script executable.

chmod +x /usr/bin/mythconverttoipad

Step 3:
Add script as user job within MythTV.

Within mythtv-setup add the following user job:

/usr/bin/mythconverttoipad %DIR% %FILE%

Step 4:

Enable it within rules.

Within a program recording rule (within mythfrontent), enable this user job to be run post-recording.

Step 5:
Access the files from Air Video client or other player.

If you have questions, please comment.

7 comments:

York said...

Thanks for sharing. I followed your instruction to convert the recorded file. I can play it on my ubuntu and mac. But I cannot copy it to ipad using itune. It says "cannot be played on this ipad". Any idea why?

John said...

Try Handbrake. It works well, too.

York said...

I got it work with ffmpeg. The problem was the resolution. Doubled with ipad2 spec and found mpeg4 is only supported up to 640x480. Using h.264 instead. Now it plays ok.

John said...

So were you using this then?

ffmpeg -y -i $DIR/$FILE -ab 320kb -vcodec mpeg4 -b 3200kb -s 640x480 -threads 16 $DIR/$FILE.m4v

York said...

No. I was using -vcodec libx264. I am not near my Linux box so cannot give you exact command. But basically I only specify the codec to h.264 and pick a pre-configuration like normal, or default. Not forcing any resolution change. I figure why bother since ipad2 can handle up to 1080p for h.264. It worked out well.

John said...

Interesting. I will change the post to reflect this. Thanks a bundle!

York said...

The complete command I am using is

ffmpeg -y -i "$DIR/$FILE" -r 30000/1001 -b 2M -bt 4M -vcodec libx264 -vpre normal -threads 4 -acodec libfaac "$DIR/$FILE.m4v"