This is a post for geeks. If you don't use "Ubuntu Linux" and an "iPod Touch/Video", don't continue. Your eyes will glaze over and the contents of this post will cause you to drool uncontrollably.
I'm throwing this up for future reference and to help fellow Linux users who may happen to own an iPod Touch or iPod Video and are having a devil of a time creating video that will play properly on it. Specifically under Ubuntu Linux.
It's no secret I'm a media junkie. Movies, specifically. I have slowly spent the past year or so ripping and encoding my DVD collection. When I started, I was using a Sony PSP as a music and video player. For DVD ripping, I use a program called dvd::rip. Works well and will rip 95% of the DVDs I've thrown at it. This can be installed from the Ubuntu package manager.
This program produces the basic AVI and MPEG movie files for computer playback and media server usage. To convert them for use on the PSP, I used a program called PSPVC. This has to be compiled and installed separate but it likewise works well. I used it to produce the MP4 files the PSP expects for video along with the movie thumbnails.
This setup served well for video up until I got an iPod Touch. Initially, I had few problems because I found the MP4 files produced by PSPVC were compatible with the iPod and played just fine. So I kept using the tools. Why change what was working? Alas, it seems sometime in the not-too-distant past Apple decided to change its iPod firmware and for no apparent reason, some MP4 files produced by PSPVC would no longer played on the iPod. I hadn't changed the formats but the iPod, for whatever reason, felt these were invalid video files. What was worse is there was no rhyme or reason for it. Two movies ripped the same day and only one would play.
This became very aggravating. So I began looking for a new encoding solution.
After working with various video tools on Linux for any length of time you'll quickly learn that most of them are front-ends to a program called ffmpeg. ffmpeg is the Swiss Army Knife of video converters. With sufficient codecs available for various video and audio formats and a proper knowledge of its myriad of command line switches, you can make this program convert any video from one format to another. Such is the utility of this program that there are pretty much no competitors to it. Video tools on Linux often simply put pretty front ends onto ffmpeg and invoke it on your behalf to save you from having to knows its arcane details.
This works very well when the defaults of your video tools produce the desired results. Both dvd::rip and PSPVC use ffmpeg for their video encoding. Where it becomes a problem is when the output you get doesn't work for you. That is the boat I found myself in a little while ago on Ubuntu Linux 8.0.4 LTS and my iPod Touch.
Since video is one of the primary uses of my iPod, frustration quickly mounted and I set out to figure out a way to get good video for my iPod under Ubuntu. Google quickly revealed numerous sites with detailed command lines to invoke ffmpeg to produce videos compatible with the iPod Touch. However, when I used these command lines they would either not run at all with bit rate or resolution errors or they would produce video with no audio.
I quickly found that Ubuntu for all its niceties occasionally leaves stuff out. The ffmpeg install on an up-to-date 8.0.4 LTS is decent but like any packaged software tends to be behind current releases. So many of the command lines that reference the iPod as a target output format don't work because the version installed on Ubuntu isn't new enough to recognize it. Past that, it seems that the out-of-the-box Ubuntu ffmpeg install can't handle the AAC audio codec for output properly.
These are my observations only but was the result of tinkering away with ffmpeg in a terminal window in a fruitless attempt to come up with a command line based on my reading to produce a good MP4 file for my iPod Touch. So I did what any good Linux user would do and decided to build a new version of ffmpeg and see if I could get it to work with iPod video.
I succeeded.
So, if you are an Ubuntu Linux user and have an iPod Touch or iPod Video, here's what to do to create compatible video for your movie watching enjoyment.
To create iPod video under Linux, you will need:
I'm throwing this up for future reference and to help fellow Linux users who may happen to own an iPod Touch or iPod Video and are having a devil of a time creating video that will play properly on it. Specifically under Ubuntu Linux.
It's no secret I'm a media junkie. Movies, specifically. I have slowly spent the past year or so ripping and encoding my DVD collection. When I started, I was using a Sony PSP as a music and video player. For DVD ripping, I use a program called dvd::rip. Works well and will rip 95% of the DVDs I've thrown at it. This can be installed from the Ubuntu package manager.
This program produces the basic AVI and MPEG movie files for computer playback and media server usage. To convert them for use on the PSP, I used a program called PSPVC. This has to be compiled and installed separate but it likewise works well. I used it to produce the MP4 files the PSP expects for video along with the movie thumbnails.
This setup served well for video up until I got an iPod Touch. Initially, I had few problems because I found the MP4 files produced by PSPVC were compatible with the iPod and played just fine. So I kept using the tools. Why change what was working? Alas, it seems sometime in the not-too-distant past Apple decided to change its iPod firmware and for no apparent reason, some MP4 files produced by PSPVC would no longer played on the iPod. I hadn't changed the formats but the iPod, for whatever reason, felt these were invalid video files. What was worse is there was no rhyme or reason for it. Two movies ripped the same day and only one would play.
This became very aggravating. So I began looking for a new encoding solution.
After working with various video tools on Linux for any length of time you'll quickly learn that most of them are front-ends to a program called ffmpeg. ffmpeg is the Swiss Army Knife of video converters. With sufficient codecs available for various video and audio formats and a proper knowledge of its myriad of command line switches, you can make this program convert any video from one format to another. Such is the utility of this program that there are pretty much no competitors to it. Video tools on Linux often simply put pretty front ends onto ffmpeg and invoke it on your behalf to save you from having to knows its arcane details.
This works very well when the defaults of your video tools produce the desired results. Both dvd::rip and PSPVC use ffmpeg for their video encoding. Where it becomes a problem is when the output you get doesn't work for you. That is the boat I found myself in a little while ago on Ubuntu Linux 8.0.4 LTS and my iPod Touch.
Since video is one of the primary uses of my iPod, frustration quickly mounted and I set out to figure out a way to get good video for my iPod under Ubuntu. Google quickly revealed numerous sites with detailed command lines to invoke ffmpeg to produce videos compatible with the iPod Touch. However, when I used these command lines they would either not run at all with bit rate or resolution errors or they would produce video with no audio.
I quickly found that Ubuntu for all its niceties occasionally leaves stuff out. The ffmpeg install on an up-to-date 8.0.4 LTS is decent but like any packaged software tends to be behind current releases. So many of the command lines that reference the iPod as a target output format don't work because the version installed on Ubuntu isn't new enough to recognize it. Past that, it seems that the out-of-the-box Ubuntu ffmpeg install can't handle the AAC audio codec for output properly.
These are my observations only but was the result of tinkering away with ffmpeg in a terminal window in a fruitless attempt to come up with a command line based on my reading to produce a good MP4 file for my iPod Touch. So I did what any good Linux user would do and decided to build a new version of ffmpeg and see if I could get it to work with iPod video.
I succeeded.
So, if you are an Ubuntu Linux user and have an iPod Touch or iPod Video, here's what to do to create compatible video for your movie watching enjoyment.
To create iPod video under Linux, you will need:
- The latest version of ffmpeg. Follow the instructions on the Download page to get the current version from the Subversion repository. You will likely need to run sudo apt-get install subversion before you can do this since Ubuntu desktop installs don't have Subversion installed by default.
- Current versions of the libfaac and libfaad audio codecs available here. This is important. Without both, the iPod video encoding won't produce audio.
Open a terminal window. You should be in your home directory. Run the following commands
sudo apt-get install subversion
svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
You'll get an ffmpeg directory in your home directory. This is where you will build your new ffmpeg from. But before you can, you need to install the audio codecs.
Unpack the faac-1.28.tar.gz and faad2-2.7.tar.gz archives you downloaded into your home directory. For me, I use Midnight Commander to open them and copy their contents to my home directory. Or you can use the archiving tool that Ubuntu provides. Once you've unpacked both, go into each directory and run the commands ./configure, make and sudo make install. That will install the latest and greatest versions of these libraries to your system. Overwriting the existing ones doesn't appear to hurt anything.
With the AAC libraries installed, you can now build ffmpeg. Go into the ffmpeg directory and run the following command:
./configure --enable-libfaac --enable-libfaad --enable-nonfree --enable-gpl
Once this command completes, run make. After a cup of coffee or a can of soda, you'll have a new version of ffmpeg sitting in this directory. Since I didn't want to upset my system, I installed the new binary/executable into the bin directory in my home directory. This directory allows you to override system programs with your own versions without having to overwrite them. Since I didn't want to upset Ubuntu with a version of ffmpeg installed outside of its package tree, this is the best option.
Copy the new ffmpeg to your bin directory with the command cp ffmpeg ~/bin.
Now when you run ffmpeg -version from the terminal, you should see something like:
FFmpeg version SVN-r19281, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: --enable-libfaac --enable-libfaad --enable-nonfree --enable-gpl
libavutil 50. 3. 0 / 50. 3. 0
libavcodec 52.32. 0 / 52.32. 0
libavformat 52.36. 0 / 52.36. 0
libavdevice 52. 2. 0 / 52. 2. 0
libswscale 0. 7. 1 / 0. 7. 1
built on Jun 27 2009 13:38:40, gcc: 4.2.4 (Ubuntu 4.2.4-1ubuntu3)
FFmpeg SVN-r19281
libavutil 50. 3. 0 / 50. 3. 0
libavcodec 52.32. 0 / 52.32. 0
libavformat 52.36. 0 / 52.36. 0
libavdevice 52. 2. 0 / 52. 2. 0
libswscale 0. 7. 1 / 0. 7. 1
This is good. It means your configuration and Subversion extracted copy of ffmpeg is in charge. This means you can now encode iPod video.
I prefer simplicity and for PSP compatibility, I've stuck with MPEG-4. The H.264 video codec is superior but takes longer to encode and produces larger files. Plus, my main complaint with most of the command lines out there is they throw every quality setting and option available out there on an iPod video. And then encode it at 640x400 or 640x480 resolution. This will produce video files almost as large as the original 720x480 rips from a standard definition DVD. The screen resolution of the iPod Touch is only 320x240. Lastly, most of these long command lines simply don't work. ffmpeg squawks constantly about bit rate settings being wrong and won't run.
So I punt. At 320x240, the bit rate will stay below the maximum permissible for the iPod Touch. So I produced a command line for ffmpeg that will produce a 320x240 MP4 video using the AAC audio codec. To produce a movie for your iPod Touch, run the following command line:
ffmpeg -i INPUT_FILE -vcodec mpeg4 -acodec libfaac -s 320x240 -f ipod -aspect 16:9 -vol 512 OUTPUT_FILE
Where INPUT_FILE is the name of the original video you want to encode and OUTPUT_FILE is the MP4 you want to produce. So an example command line might be:
ffmpeg -i TheGoonies.avi -vcodec mpeg4 -acodec libfaac -s 320x240 -f ipod -aspect 16:9 -vol 512 TheGoonies.mp4
Short, sweet and simple. And this should run fine and produce an MP4 version of your movie at about 1/3rd the size of the original input file. Use iTunes or whatever mechanism you are using to move your video onto your iPod and it should play fine.
The -vol 512 switch, by the way, is undocumented but increases the audio volume output. 256 is the default level so 512 roughly doubles the output volume. This is useful because the rips from dvd::rip tend to be quiet on the volume level. This helps even things out for iPod playback from its small speaker and headphones.
With this working, you can go one step further and encode an entire collection. For me, I dumped all of my AVI videos into a directory and wrote a little script to blow through them all to produce a iPod movie collection. To do the same, copy the files you want to convert into a single directory (no separate folders) and then save the following script to a file called convertToMP4.sh in your bin directory where you copied ffmpeg.
#!/bin/sh
for f in *.avi
do
name=${f%avi}mp4
echo -n "Converting $f to $name..."
ffmpeg -i $f -vcodec mpeg4 -acodec libfaac -s 320x240 -f ipod -aspect 16:9 -vol 512 $name
echo "done."
done
After you've saved it, run chmod +x ~/bin/convertToMP4.sh. Then go into the directory where your videos are and run convertToMP4.sh. The script will run and systematically convert every AVI file in the directory to an equivalent .mp4 file. If you are using an extension other than AVI, change tjhe 'avi' in the script above to whatever extension it happens to be.
I know it isn't sophisticated but it works. Once the script has run, you can copy the new .mp4 files to wherever you install them to your iPod from. In my case, an iPod directory on an external drive that I hook up to iTunes on a Windows laptop.
So there you have. Sorry for the length but I hope this will help other Linux users out there struggling to make their proprietary and onery Apple iPods useful and not have to use Windows-based tools to do it. Linux does video very well once you know how.
Happy ripping!
sudo apt-get install subversion
svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
You'll get an ffmpeg directory in your home directory. This is where you will build your new ffmpeg from. But before you can, you need to install the audio codecs.
Unpack the faac-1.28.tar.gz and faad2-2.7.tar.gz archives you downloaded into your home directory. For me, I use Midnight Commander to open them and copy their contents to my home directory. Or you can use the archiving tool that Ubuntu provides. Once you've unpacked both, go into each directory and run the commands ./configure, make and sudo make install. That will install the latest and greatest versions of these libraries to your system. Overwriting the existing ones doesn't appear to hurt anything.
With the AAC libraries installed, you can now build ffmpeg. Go into the ffmpeg directory and run the following command:
./configure --enable-libfaac --enable-libfaad --enable-nonfree --enable-gpl
Once this command completes, run make. After a cup of coffee or a can of soda, you'll have a new version of ffmpeg sitting in this directory. Since I didn't want to upset my system, I installed the new binary/executable into the bin directory in my home directory. This directory allows you to override system programs with your own versions without having to overwrite them. Since I didn't want to upset Ubuntu with a version of ffmpeg installed outside of its package tree, this is the best option.
Copy the new ffmpeg to your bin directory with the command cp ffmpeg ~/bin.
Now when you run ffmpeg -version from the terminal, you should see something like:
FFmpeg version SVN-r19281, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: --enable-libfaac --enable-libfaad --enable-nonfree --enable-gpl
libavutil 50. 3. 0 / 50. 3. 0
libavcodec 52.32. 0 / 52.32. 0
libavformat 52.36. 0 / 52.36. 0
libavdevice 52. 2. 0 / 52. 2. 0
libswscale 0. 7. 1 / 0. 7. 1
built on Jun 27 2009 13:38:40, gcc: 4.2.4 (Ubuntu 4.2.4-1ubuntu3)
FFmpeg SVN-r19281
libavutil 50. 3. 0 / 50. 3. 0
libavcodec 52.32. 0 / 52.32. 0
libavformat 52.36. 0 / 52.36. 0
libavdevice 52. 2. 0 / 52. 2. 0
libswscale 0. 7. 1 / 0. 7. 1
This is good. It means your configuration and Subversion extracted copy of ffmpeg is in charge. This means you can now encode iPod video.
I prefer simplicity and for PSP compatibility, I've stuck with MPEG-4. The H.264 video codec is superior but takes longer to encode and produces larger files. Plus, my main complaint with most of the command lines out there is they throw every quality setting and option available out there on an iPod video. And then encode it at 640x400 or 640x480 resolution. This will produce video files almost as large as the original 720x480 rips from a standard definition DVD. The screen resolution of the iPod Touch is only 320x240. Lastly, most of these long command lines simply don't work. ffmpeg squawks constantly about bit rate settings being wrong and won't run.
So I punt. At 320x240, the bit rate will stay below the maximum permissible for the iPod Touch. So I produced a command line for ffmpeg that will produce a 320x240 MP4 video using the AAC audio codec. To produce a movie for your iPod Touch, run the following command line:
ffmpeg -i INPUT_FILE -vcodec mpeg4 -acodec libfaac -s 320x240 -f ipod -aspect 16:9 -vol 512 OUTPUT_FILE
Where INPUT_FILE is the name of the original video you want to encode and OUTPUT_FILE is the MP4 you want to produce. So an example command line might be:
ffmpeg -i TheGoonies.avi -vcodec mpeg4 -acodec libfaac -s 320x240 -f ipod -aspect 16:9 -vol 512 TheGoonies.mp4
Short, sweet and simple. And this should run fine and produce an MP4 version of your movie at about 1/3rd the size of the original input file. Use iTunes or whatever mechanism you are using to move your video onto your iPod and it should play fine.
The -vol 512 switch, by the way, is undocumented but increases the audio volume output. 256 is the default level so 512 roughly doubles the output volume. This is useful because the rips from dvd::rip tend to be quiet on the volume level. This helps even things out for iPod playback from its small speaker and headphones.
With this working, you can go one step further and encode an entire collection. For me, I dumped all of my AVI videos into a directory and wrote a little script to blow through them all to produce a iPod movie collection. To do the same, copy the files you want to convert into a single directory (no separate folders) and then save the following script to a file called convertToMP4.sh in your bin directory where you copied ffmpeg.
#!/bin/sh
for f in *.avi
do
name=${f%avi}mp4
echo -n "Converting $f to $name..."
ffmpeg -i $f -vcodec mpeg4 -acodec libfaac -s 320x240 -f ipod -aspect 16:9 -vol 512 $name
echo "done."
done
After you've saved it, run chmod +x ~/bin/convertToMP4.sh. Then go into the directory where your videos are and run convertToMP4.sh. The script will run and systematically convert every AVI file in the directory to an equivalent .mp4 file. If you are using an extension other than AVI, change tjhe 'avi' in the script above to whatever extension it happens to be.
I know it isn't sophisticated but it works. Once the script has run, you can copy the new .mp4 files to wherever you install them to your iPod from. In my case, an iPod directory on an external drive that I hook up to iTunes on a Windows laptop.
So there you have. Sorry for the length but I hope this will help other Linux users out there struggling to make their proprietary and onery Apple iPods useful and not have to use Windows-based tools to do it. Linux does video very well once you know how.
Happy ripping!

2 comments:
Hi:
I'm trying to follow you, but when I run from ~/ffmpeg the command:
./configure --enable-libfaac --enable-libfaad --enable-nonfree --enable-gpl
It prints a list of settings, like what is enabled and what has support, an then a list of Enabled decoders (where it is libfaad), Enabled encoders (where it is libfaac), Enabled hwaccels (empty), Enabled parsers, Enabled demuxers, Enabled muxers, Enabled protocols, Enabled filters, Enabled bsfs, Enabled indevs, Enabled outdevs, an then the following:
License: nonfree and unredistributable
Creating config.mak and config.h...
and it returns to the command line.
If I run ls ff*, the otuput is:
ffmpeg.c ffmpeg.d ffplay.c ffplay.d ffserver.c ffserver.d ffserver.h and the content of ffpresets.
It seems it did not compile correctly. Moreover, I cannot pass from that point of your instructions.
Do you have any idea what I might be making wrong?
I'm using Ubuntu 8.04 - Hardy Heron in its 64 bit version.
Thanks in advance.
Eli.
thats great, then you can add to the sh:
scp $f alpline@your.i.pod:/var/media/Library/Downloads/transcodes/$f
and it would be fully automated over wifi on a jailbroken one!
Post a Comment