iPhone and Linux

Sunday, February 7, 2010

Minimal video encoding for iPhone

There are countless ways of encoding video for the iPhone, but this is the command I normally use. I don't watch many videos on the phone and my goal is usually to create a video with a small size that doesn't strain the system too much to run. A lower bitrate, 20.98 framerate and 320x240 resolution (which is used on the iPod) would be terrible for watching a hi-def movie, but works great for most videos.

ffmpeg -i infile -f mp4 -vcodec mpeg4 -b 200k -aspect 4:3 -r 20.98 -s 320x240 -acodec libfaac -ar 48000 outfile


The only videos I routinely watch are of The Daily Show, so this little script encodes and renames them from
The.Daily.Show.2010.02.04.Rep.Anthony.Weiner.HDTV.XviD.avi to TDS-02.04.mp4

#! /bin/sh                       
for i in `ls *.avi`
do
name=TDS-$(echo $i | cut -c 21-25).mp4
ffmpeg -i $i -f mp4 -vcodec mpeg4 -b 200k -aspect 4:3 -r 20.98 -s 320x240 -acodec libfaac -ar 48000 $name
done
If you happen to use Prowl and want a notification when it is finished...
num=$(ls | grep mp4 | wc -l)
dir=$(pwd)
url=https://prowl.weks.net/publicapi/add
app="Pod converter"
desc="Finished converting $num Daily Shows in $dir"
curl -k $url -F apikey=XXX -F application=$app -F description=$desc
... or want to transfer them with ssh (using ssh keys):
mkdir mp4s
mv *.mp4 ./mp4s
scp -r -i ~/.ssh/SSH_FILENAME /path/to/mp4s mobile@IP:/var/mobile
Tweak it a bit and you can have a basic method for encoding and automatically syncing your favorite videos while you sleep.

Blog Archive