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

Here’s my take on how to install a Ruby on Rails app with lighttpd. The app is configured to start on boot with an init.d script that runs the spinner as any system user.

Read the rest of this entry

Getting started with a Linux operating system is a bit like learning to ride a bike without training wheels. If you’re used to a GUI and don’t want to change that’s okay. The Linux GUI’s are anything but lame. Check out Compiz, a desktop enhancement that blows away anything currently on the market. The KDE and GNOME window managers are refined and complete to the point that a Windows or Mac user would feel right at home. The real power of Linux, however, is locked away in the command line interface (CLI).

Read the rest of this entry