Convert MythTV Video for IPOD
November 11th, 2007
These steps worked on Ubuntu Feisty on a 32 bit system and an Ipod Classic.
The packaged version of ffmpeg on Ubuntu Feisty wasn't doing the job, giving me this error while trying to convert an mpeg 2 to an mpeg 4: Unsupported codec for output stream #0.1 Newer versions of Ubuntu may fix this so try your luck with the following command.
sudo aptitude update
sudo aptitude install ffmpeg
ffmpeg -i inputfile.mpg -b 300 -qmin 3 -qmax 5 -g 300 -ab 96000 -s 320:240 -aspect 4:3 test.mp4
If this doesn't work ffmpeg will need to be compiled locally with the following instructions.
1. Uninstall ffmpeg
sudo aptitude remove --purge ffmpeg
2. Get the latest ffmpeg source.
An svn checkout is also available at http://ffmpeg.mplayerhq.hu/download.html
wget http://ffmpeg.mplayerhq.hu/ffmpeg-export-snapshot.tar.bz2
tar -xvjf ffmpeg-export-snapshot.tar.bz2
cd ffmpeg-export-???
3. Install compile dependencies.
sudo aptitude install libfaac-dev liba52-dev libdc1394-dev libgsm1-dev libogg-dev libvorbis-dev libxvidcore-dev
4. Configure the build, make, and install.
./configure --enable-libxvid --enable-libfaac --enable-gpl --enable-pp --enable-pthreads --enable-libvorbis --enable-libogg --enable-liba52 --enable-libgsm --enable-libdc1394 --disable-debug --enable-shared
make
sudo make install
5. Edit shared library configuration.
sudo cp /etc/ld.so.conf /etc/so.conf.bak
echo "echo /usr/local/lib >> /etc/ld.so.conf" | sudo sh
6. Update library simlinks.
sudo ldconfig -v
7. Make sure bin paths are configured correctly.
which ffmpeg
This should output /usr/local/bin/ffmpeg. If not, restart the shell and check the PATH variable. Ensure /usr/local/bin comes before /usr/bin and /bin.
8. Test it out somewhere.
ffmpeg -i inputfile.mpg -b 300 -qmin 3 -qmax 5 -g 300 -ab 96000 -s 320:240 -aspect 4:3 test.mp4
file test.mp4
That's it. The remaining is icing on the cake.
9. Automate it.
Make was designed for automating software builds. The advantage in using it to automate file conversion is that it will recognize when no work needs to be done for an output file. Create a directory called ipod which is a sibling of the mythv recordings directory. Place the following make-rule inside a Makefile in that directory.
File: recordings/../ipod/Makefile
%.mp4 : ../recordings/%.mpg
ffmpeg -i $< -b 300 -qmin 3 -qmax 5 -g 300 -ab 96000 -s 320:240 -aspect 4:3 $@
Create a script to tell Make which output files to create. In this case it's the basename of each MythTV mpeg with an mp4 extension. Make will use the above rule to figure out how to create an mp4 file with a given name. Make will do nothing if the file already exists and is newer than the input file. Name the script convert and chmod it to 755.
File: recordings/../ipod/convert
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export PATH
make `ls ../recordings/*.mpg | sed 's/\.\.\/recordings\///' | sed 's/.mpg$/.mp4/'`
The ugly recording filenames consist of two parts. 1005_20071004210000.mpg, for exampe. The 1005 is the chanid column in the 'channels' table and the rest is a date and time. Luckily the information about a recording is in the 'recorded' table so that can be used to create pretty names for the new mp4's. Here's a my solution. TIMTOWDI, right?
File: recordings/../ipod/make-pretty
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export PATH
mkdir -p pretty
for filename in `ls *.mp4`; do
basename=`echo $filename | sed 's/.mp4$/.mpg/'`
prettyname=`mysql -umythtv -p???????? -e "select concat(title, ' ', progstart) as name from recorded where basename = '$basename' limit 1;" --database mythconverg -NE \
| grep name: | sed 's/name: //' | sed 's/00$//' | sed 's/://g' | sed 's/$/.mp4/'`
ln -sf "../$filename" "pretty/$prettyname"
done
Add the following line to /etc/crontab or create a new file called /etc/cron.d/ipod and place it there instead. Be sure to sudo chown -R the ipod directory to the same user specified in the crontab. Every morning the ipod/pretty directory will be filled with shows to watch on the morning commute.
File: /etc/cron.d/ipod
05 2 * * * mythtv cd ???????? && nice -n19 ./convert && ./make-pretty
on November 11th, 2007 at 02:27 PM
My hero! Thank you!
on November 11th, 2007 at 02:48 PM
does it work with 64 bit libraries? I tried this, but got some errors I wasn’t able to decipher well enough to fix.
Very cool, though. Maybe I’ll sftp all my stuff to your box, and sync the ipod later! :-D
on November 11th, 2007 at 03:00 PM
Good question. I have no idea. Tara and I don’t have a 64-bit machine yet.
on November 17th, 2007 at 01:53 AM
Brilliant, absolutely brilliant! Only one small thing that I noticed: the latest ffmpeg doesn’t support the—enable-libogg switch, does somebody know why?
on November 17th, 2007 at 06:32 PM
The ./configure options seem to be changing quite a bit since every webiste I’ve referenced has different flags and most were unsupported e.g. —enable-ogg became—enable-libogg, and now it’s most likely something else. I compiled an updated version a few days after this and the—enable-libogg was gone.