个人工具

“UbuntuHelp:IPodVideoEncoding”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
(新页面: {{From|https://help.ubuntu.com/community/iPodVideoEncoding}} {{Languages|UbuntuHelp:iPodVideoEncoding}} == Encoding Video for the iPod Video == This is a guide for encoding video to a ...)
 
第2行: 第2行:
 
{{Languages|UbuntuHelp:iPodVideoEncoding}}
 
{{Languages|UbuntuHelp:iPodVideoEncoding}}
 
== Encoding Video for the iPod Video ==
 
== Encoding Video for the iPod Video ==
 
+
This is a guide for encoding video to a format acceptable by the 5th generation iPods, aka the iPod Video (The format is also compatible with 6th generation iPods, iPhones, Apple TV's, and the QuickTime player / iTunes.  The following methods have been tested successfully on Ubuntu Breezy through Gutsy. They require adding new repositories (Feisty and higher) or rebuilding your system's ffmpeg (before Feisty), so be warned that the modifications to your system from this guide won't be officially condoned by Canonical.
 
+
 
+
This is a guide for encoding video to a format acceptable by the 5th generation iPods, aka the iPod Video.  The following methods have been tested successfully on Ubuntu Breezy, Dapper, and Edgy. They require rebuilding your system's ffmpeg, so be warned that the modifications to your system from this guide won't be officially condoned by Canonical.
+
 
+
 
If you need more information, make sure to check out the [[UbuntuHelp:iPodVideo|iPod Video wiki page]], as well as the [[UbuntuHelp:iPodVideoTransferring|Guide to Transferring Video to the iPod Video]].
 
If you need more information, make sure to check out the [[UbuntuHelp:iPodVideo|iPod Video wiki page]], as well as the [[UbuntuHelp:iPodVideoTransferring|Guide to Transferring Video to the iPod Video]].
 
 
As for encoding, you will have to recompile ffmpeg so that it has the correct configuration in order to encode videos in the format required by the iPod Video.  This guide walks you through compiling and installing ffmpeg correctly, as well as encoding video correctly using ffmpeg.
 
As for encoding, you will have to recompile ffmpeg so that it has the correct configuration in order to encode videos in the format required by the iPod Video.  This guide walks you through compiling and installing ffmpeg correctly, as well as encoding video correctly using ffmpeg.
 
 
However, you could also just choose to use a tool which will do all of this automatically for you.  And here's how!
 
However, you could also just choose to use a tool which will do all of this automatically for you.  And here's how!
 
+
=== Mark Pilgrim's mencoder based solution ===
=== Encoding for iPod: The Easy Way! ===
+
This script does not use ffmpeg (like the others) and allows you to bypass the hassles of the other methods that require you to add new repositories or even rebuild ffmpeg. mencoder also does better with WMV, Real Video, and other very proprietary formats by allowing you to take advantage of w32codecs. Like pypodconv below, it also uses the high-quality H.264 video codec.
 
+
 
<pre><nowiki>
 
<pre><nowiki>
sudo aptitude install lsdvd mplayer mp4box zenity
+
sudo aptitude install lsdvd mplayer gpac zenity
 
sudo wget http://diveintomark.org/public/2007/06/podencoder.txt -O /usr/local/bin/podencoder
 
sudo wget http://diveintomark.org/public/2007/06/podencoder.txt -O /usr/local/bin/podencoder
 
sudo chmod +x /usr/local/bin/podencoder
 
sudo chmod +x /usr/local/bin/podencoder
第25行: 第18行:
 
podencoder --help
 
podencoder --help
 
</nowiki></pre>
 
</nowiki></pre>
 
Note : Take attention to the installation of <code><nowiki>mp4box</nowiki></code>, it's possible that you must install <code><nowiki>gpac</nowiki></code> instead.
 
 
 
 
=== Fixing ffmpeg on Ubuntu ===
 
=== Fixing ffmpeg on Ubuntu ===
 
 
'''For Ubuntu 7.04 Feisty Fawn, ffmpeg in Medibuntu contains this "unlocked" ffmpeg. Enable Medibuntu with the [https://help.ubuntu.com/community/Medibuntu#head-7486ed038a9becc1dff10a24cc07a38a00d70e9f instructions here], then skip this section!'''
 
'''For Ubuntu 7.04 Feisty Fawn, ffmpeg in Medibuntu contains this "unlocked" ffmpeg. Enable Medibuntu with the [https://help.ubuntu.com/community/Medibuntu#head-7486ed038a9becc1dff10a24cc07a38a00d70e9f instructions here], then skip this section!'''
 
 
Edgy/Dapper users, follow these instructions:
 
Edgy/Dapper users, follow these instructions:
 
 
For a litany of legal reasons, ffmpeg does not come with all of the necessary things enabled for you to encode video for the iPod Video by default.  Therefore, we need to build it from source and install some other libraries and programs, as well.  Make sure you have multiverse and universe enabled. Apologies for this necessary procedure -- it certainly looks intimidating. I (JohnDong) am currently working with Medibuntu to have ready-to-use packages available in the form of an APT repository.
 
For a litany of legal reasons, ffmpeg does not come with all of the necessary things enabled for you to encode video for the iPod Video by default.  Therefore, we need to build it from source and install some other libraries and programs, as well.  Make sure you have multiverse and universe enabled. Apologies for this necessary procedure -- it certainly looks intimidating. I (JohnDong) am currently working with Medibuntu to have ready-to-use packages available in the form of an APT repository.
 
 
 
In the terminal, run:
 
In the terminal, run:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo apt-get build-dep ffmpeg
 
sudo apt-get build-dep ffmpeg
第45行: 第28行:
 
sudo apt-get install liblame-dev libfaad2-dev libfaac-dev libxvidcore4-dev liba52-0.7.4 liba52-0.7.4-dev libx264-dev
 
sudo apt-get install liblame-dev libfaad2-dev libfaac-dev libxvidcore4-dev liba52-0.7.4 liba52-0.7.4-dev libx264-dev
 
</nowiki></pre>
 
</nowiki></pre>
 
 
'''64-bit (AMD64) Ubuntu users only''': You need to force ffmpeg to link against the PIC version of ffmpeg. Issue the following command:
 
'''64-bit (AMD64) Ubuntu users only''': You need to force ffmpeg to link against the PIC version of ffmpeg. Issue the following command:
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo cp /usr/lib/libx264_pic.a /usr/lib/libx264.a
 
sudo cp /usr/lib/libx264_pic.a /usr/lib/libx264.a
 
</nowiki></pre>
 
</nowiki></pre>
 
 
All users: Continue with the following commands:
 
All users: Continue with the following commands:
 
<pre><nowiki>
 
<pre><nowiki>
第61行: 第42行:
 
make
 
make
 
sudo make install
 
sudo make install
 
 
If you are using the FFMPEG source from a edgy repository, skip the rest of this code block.
 
If you are using the FFMPEG source from a edgy repository, skip the rest of this code block.
 
If you are using the FFMPEG source from a recent (20070331) SVN checkout, the configure options have changed.  Use this line instead of the one above and then continue with the make command:
 
If you are using the FFMPEG source from a recent (20070331) SVN checkout, the configure options have changed.  Use this line instead of the one above and then continue with the make command:
 
 
./configure --enable-gpl --enable-pp --enable-pthreads \
 
./configure --enable-gpl --enable-pp --enable-pthreads \
 
--enable-libogg --enable-liba52 --enable-libdts \
 
--enable-libogg --enable-liba52 --enable-libdts \
 
--enable-dc1394 --enable-libgsm --disable-debug --enable-libmp3lame \
 
--enable-dc1394 --enable-libgsm --disable-debug --enable-libmp3lame \
 
--enable-libfaad --enable-libfaac --enable-xvid --enable-x264  
 
--enable-libfaad --enable-libfaac --enable-xvid --enable-x264  
 
 
 
</nowiki></pre>
 
</nowiki></pre>
 
 
 
Note how you should first install ffmpeg before doing sudo make install. This will work less intrusively as checkinstall, as it just overwrites the exact files owned by the ffmpeg package without disturbing the way the package structure is registered to dpkg.
 
Note how you should first install ffmpeg before doing sudo make install. This will work less intrusively as checkinstall, as it just overwrites the exact files owned by the ffmpeg package without disturbing the way the package structure is registered to dpkg.
 
 
'''64-bit (AMD64) Ubuntu users only''': Revert the change we made above to your system:
 
'''64-bit (AMD64) Ubuntu users only''': Revert the change we made above to your system:
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo apt-get install --reinstall libx264-dev
 
sudo apt-get install --reinstall libx264-dev
 
</nowiki></pre>
 
</nowiki></pre>
 
 
=== Script 1: pypodconv Script ===
 
=== Script 1: pypodconv Script ===
 
This is a newer (03/2007) Python script that encapsulates all the below functionality into a script. It requires ffmpeg '''AND gpac''' to work. And due to the number of people who apparently glanced over that, here it is again: '''You need gpac from multiverse for the script to function'''. (If you forget to install that, the encoding will fail at the very end, nullifying your hours of encoding work). Here's a "screenshot":
 
This is a newer (03/2007) Python script that encapsulates all the below functionality into a script. It requires ffmpeg '''AND gpac''' to work. And due to the number of people who apparently glanced over that, here it is again: '''You need gpac from multiverse for the script to function'''. (If you forget to install that, the encoding will fail at the very end, nullifying your hours of encoding work). Here's a "screenshot":
第86行: 第59行:
 
jdong@severance:~/src/pypodconv$ pypodconv
 
jdong@severance:~/src/pypodconv$ pypodconv
 
Usage: pypodconv [options]
 
Usage: pypodconv [options]
 
 
Options:
 
Options:
 
-h, --help            show this help message and exit
 
-h, --help            show this help message and exit
第106行: 第78行:
 
Number of passes. (Default: 2)
 
Number of passes. (Default: 2)
 
</nowiki></pre>
 
</nowiki></pre>
 
 
To install, download [http://web.mit.edu/~jdong/www/pypodconv/pypodconv pypodconv] and save it to /tmp. Then, run:
 
To install, download [http://web.mit.edu/~jdong/www/pypodconv/pypodconv pypodconv] and save it to /tmp. Then, run:
 
<pre><nowiki>
 
<pre><nowiki>
第114行: 第85行:
 
</nowiki></pre>
 
</nowiki></pre>
 
For Gutsy and SVN ffmpeg, use [http://web.mit.edu/~jdong/www/pypodconv.ffmpegsvn/pypodconv this pypodconv].
 
For Gutsy and SVN ffmpeg, use [http://web.mit.edu/~jdong/www/pypodconv.ffmpegsvn/pypodconv this pypodconv].
 
 
The basic operation is:
 
The basic operation is:
 
<pre><nowiki>
 
<pre><nowiki>
第123行: 第93行:
 
pypodconv -i INPUT_FILE -o OUTPUT_FILE --hd -b 500
 
pypodconv -i INPUT_FILE -o OUTPUT_FILE --hd -b 500
 
</nowiki></pre>
 
</nowiki></pre>
 
 
'''Support''': For now, I will handle support personally through my e-mail: jdong <at> ubuntu (dot) com. If demand rises then I will make a formal Launchpad product.
 
'''Support''': For now, I will handle support personally through my e-mail: jdong <at> ubuntu (dot) com. If demand rises then I will make a formal Launchpad product.
 
 
=== Script 2: ipodvidenc Script ===
 
=== Script 2: ipodvidenc Script ===
 
 
Finally, to encode the videos you can create a script for converting your videos to iPod Video format.
 
Finally, to encode the videos you can create a script for converting your videos to iPod Video format.
 
 
<pre><nowiki>
 
<pre><nowiki>
 
gedit
 
gedit
 
</nowiki></pre>
 
</nowiki></pre>
 
 
This should pop up a blank document. Now, just copy and paste this code into it:
 
This should pop up a blank document. Now, just copy and paste this code into it:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
 
input_file=$1
 
input_file=$1
 
 
echo "What would you like to name the output file (sans extension)?"
 
echo "What would you like to name the output file (sans extension)?"
 
 
read output_file_name
 
read output_file_name
 
 
echo "$output_file_name will be located in $PWD. Is this acceptable? [y/n]"
 
echo "$output_file_name will be located in $PWD. Is this acceptable? [y/n]"
 
 
read output_file_loc_permis
 
read output_file_loc_permis
 
 
if [ $output_file_loc_permis == 'n' ] || [ $output_file_loc_permis == 'N' ]
 
if [ $output_file_loc_permis == 'n' ] || [ $output_file_loc_permis == 'N' ]
 
then
 
then
第155行: 第113行:
 
output_dir=$PWD
 
output_dir=$PWD
 
fi
 
fi
 
 
ffmpeg -i ${input_file} -f mp4 -vcodec mpeg4 -maxrate 1000 -b 700 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec aac -ab 192 -s 320x240 -aspect 4:3 ${output_dir}/${output_file_name}.mov
 
ffmpeg -i ${input_file} -f mp4 -vcodec mpeg4 -maxrate 1000 -b 700 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec aac -ab 192 -s 320x240 -aspect 4:3 ${output_dir}/${output_file_name}.mov
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Save as ipodvidenc in your present working directory (it will be moved, anyway). Back in the terminal, run:
 
Save as ipodvidenc in your present working directory (it will be moved, anyway). Back in the terminal, run:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
chmod 755 ipodvidenc
 
chmod 755 ipodvidenc
 
sudo mv ipodvidenc /usr/bin
 
sudo mv ipodvidenc /usr/bin
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Now, when you want to encode a video to iPod format, run this command:
 
Now, when you want to encode a video to iPod format, run this command:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
ipodvidenc video.avi
 
ipodvidenc video.avi
 
</nowiki></pre>
 
</nowiki></pre>
 
 
It will run you through a few prompts and then encode the video and put it into the correct format.
 
It will run you through a few prompts and then encode the video and put it into the correct format.
 
 
As of January 15th, 2006, using this method will work with raw .vob files, meaning that you no longer have to transcode your DVDs!  If you followed this guide before Januray 15th, 2006, you can get .vob encoding support by doing the following:
 
As of January 15th, 2006, using this method will work with raw .vob files, meaning that you no longer have to transcode your DVDs!  If you followed this guide before Januray 15th, 2006, you can get .vob encoding support by doing the following:
 
 
<code><nowiki>sudo apt-get install liba52-0.7.4 liba52-0.7.4-dev</nowiki></code>
 
<code><nowiki>sudo apt-get install liba52-0.7.4 liba52-0.7.4-dev</nowiki></code>
 
 
Edit the debian/rules file in the ffmpeg source folder to include:
 
Edit the debian/rules file in the ffmpeg source folder to include:
 
 
<code><nowiki>confflags += --enable-a52</nowiki></code>
 
<code><nowiki>confflags += --enable-a52</nowiki></code>
 
 
Then reconfigure, remake, and reinstall.
 
Then reconfigure, remake, and reinstall.
 
 
=== The gui option - thinliquidfilm ===
 
=== The gui option - thinliquidfilm ===
 
 
If you would prefer to use a gui to encode video, then you can use thinliquidfilm.  thinliquidfilm is a gui frontend for ffmpeg, specifically designed to encode ipod compatible videos.  You can find it [http://thinliquidfilm.org here].  It requires ffmpeg (compiled as set out above) and pyqt (which is installed as part of the '''kubuntu-desktop''' package).  There are other non-essential dependencies for uploading to an ipod (see the [[UbuntuHelp:iPodVideoTransferring|Guide to Transferring Video to the iPod Video]] for more details) and mplayer is required to preview encoded videos before encoding).
 
If you would prefer to use a gui to encode video, then you can use thinliquidfilm.  thinliquidfilm is a gui frontend for ffmpeg, specifically designed to encode ipod compatible videos.  You can find it [http://thinliquidfilm.org here].  It requires ffmpeg (compiled as set out above) and pyqt (which is installed as part of the '''kubuntu-desktop''' package).  There are other non-essential dependencies for uploading to an ipod (see the [[UbuntuHelp:iPodVideoTransferring|Guide to Transferring Video to the iPod Video]] for more details) and mplayer is required to preview encoded videos before encoding).
 
 
thinliquidfilm will:
 
thinliquidfilm will:
 
 
* Batch process any number of files;
 
* Batch process any number of files;
 
* Display detailed information about source video files;
 
* Display detailed information about source video files;
第206行: 第149行:
 
* Add pre-encoded videos to the transfer list;
 
* Add pre-encoded videos to the transfer list;
 
* Add files for encoding via the included servicemenu.
 
* Add files for encoding via the included servicemenu.
 
 
Installation is very simple with the included installation script.  The [http://thinliquidfilm.org website] has comprehensive documentation on installing and using thinliquidfilm, and therefore there is no point in repeating it here.
 
Installation is very simple with the included installation script.  The [http://thinliquidfilm.org website] has comprehensive documentation on installing and using thinliquidfilm, and therefore there is no point in repeating it here.
 
 
=== Using ffmpeg ===
 
=== Using ffmpeg ===
 
 
If you would like to have more control than ipodvidenc or thinliquid film gives, and just use an ffmpeg command, and perhaps set it as an alias, the command is as follows:
 
If you would like to have more control than ipodvidenc or thinliquid film gives, and just use an ffmpeg command, and perhaps set it as an alias, the command is as follows:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
ffmpeg -i input_file.avi -f mp4 -vcodec mpeg4 -maxrate 1000 -b 700 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec aac -ab 192 -s 320x240 -aspect 4:3 output_file.mov
 
ffmpeg -i input_file.avi -f mp4 -vcodec mpeg4 -maxrate 1000 -b 700 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec aac -ab 192 -s 320x240 -aspect 4:3 output_file.mov
 
</nowiki></pre>
 
</nowiki></pre>
 
 
This encodes a 700kbit MPEG-4 ASP (i.e. "xvid") format video using ffmpeg's mpeg4 encoder. Alternatively, you may use the xvid codec, which squeezes a bit more quality for the same bitrate than the above command, though it is slightly slower. Simply replace "mpeg4" with "xvid". Since Firmware 1.2 and higher, you can bump -maxrate and/or -b to 2500, and resolution (-s) to 640x480. Note that you will need to bump up the bitrate to at least 1000kbit if you want a good-looking 640x480 mpeg4-ASP video.
 
This encodes a 700kbit MPEG-4 ASP (i.e. "xvid") format video using ffmpeg's mpeg4 encoder. Alternatively, you may use the xvid codec, which squeezes a bit more quality for the same bitrate than the above command, though it is slightly slower. Simply replace "mpeg4" with "xvid". Since Firmware 1.2 and higher, you can bump -maxrate and/or -b to 2500, and resolution (-s) to 640x480. Note that you will need to bump up the bitrate to at least 1000kbit if you want a good-looking 640x480 mpeg4-ASP video.
 
 
=== H.264 Encoding ===
 
=== H.264 Encoding ===
 
 
H.264 (MPEG-4 AVC) is a newer codec that the iPod supports. It's able to deliver similar quality at half the bitrate of MPEG-4 ASP! However, it is an extremely slow and CPU-intensive encoder. Expect the encode to take 5x longer than mpeg4 or xvid. You also need ffmpeg compiled with x264 support. As of 20-Dec-2006 this guide has been updated to reflect that, but if you rebuilt your ffmpeg before then, you need to follow the "fixing ffmpeg" procedure again for x264 support.
 
H.264 (MPEG-4 AVC) is a newer codec that the iPod supports. It's able to deliver similar quality at half the bitrate of MPEG-4 ASP! However, it is an extremely slow and CPU-intensive encoder. Expect the encode to take 5x longer than mpeg4 or xvid. You also need ffmpeg compiled with x264 support. As of 20-Dec-2006 this guide has been updated to reflect that, but if you rebuilt your ffmpeg before then, you need to follow the "fixing ffmpeg" procedure again for x264 support.
 
 
Due to this enormous speed tradeoff, it's most practical to use H.264 for encoding high-resolution 640x480 video suitable for outputting to a TV (or also for viewing on your computer). Here's the ffmpeg command for doing a 500kbit 640x480 H.264 encode:
 
Due to this enormous speed tradeoff, it's most practical to use H.264 for encoding high-resolution 640x480 video suitable for outputting to a TV (or also for viewing on your computer). Here's the ffmpeg command for doing a 500kbit 640x480 H.264 encode:
 
<pre><nowiki>
 
<pre><nowiki>
 
ffmpeg -y -i input_file.avi -an -v 1 -threads auto -vcodec h264 -b 500 -bt 175 -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 1 -me_range 21 -chroma 1 -slice 2 -max_b_frames 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -max_qdiff 4 -i_quant_factor 0.71428572 -rc_max_rate 768 -rc_buffer_size 244 -cmp 1 -s 640x480 -f mp4 -pass 1 /dev/null
 
ffmpeg -y -i input_file.avi -an -v 1 -threads auto -vcodec h264 -b 500 -bt 175 -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 1 -me_range 21 -chroma 1 -slice 2 -max_b_frames 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -max_qdiff 4 -i_quant_factor 0.71428572 -rc_max_rate 768 -rc_buffer_size 244 -cmp 1 -s 640x480 -f mp4 -pass 1 /dev/null
 
 
ffmpeg -y -i input_file.avi -v 1 -threads auto -vcodec h264 -b 500 -bt 175 -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 6 -me_range 21 -chroma 1 -slice 2 -max_b_frames 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -max_qdiff 4 -i_quant_factor 0.71428572 -rc_max_rate 768 -rc_buffer_size 244 -cmp 1 -s 640x480 -acodec aac -ab 96 -ar 48000 -ac 2 -f mp4 -pass 2 output_file.mp4
 
ffmpeg -y -i input_file.avi -v 1 -threads auto -vcodec h264 -b 500 -bt 175 -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 6 -me_range 21 -chroma 1 -slice 2 -max_b_frames 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -max_qdiff 4 -i_quant_factor 0.71428572 -rc_max_rate 768 -rc_buffer_size 244 -cmp 1 -s 640x480 -acodec aac -ab 96 -ar 48000 -ac 2 -f mp4 -pass 2 output_file.mp4
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Due to the iPod's limited feature support for H.264, the command for doing the encode is that much more complex. You can also adjust the bitrate controls (-b is average bitrate, -rc_max_rate is the max instantaneous bitrate spike allowed). The iPod supports up to 1500kbit. Note that this is a 2-pass encode. Doing two passes allows for more accurate bitrate control and substantially better quality, but the encode will take twice as long as a one-pass. The resulting mp4 looks great on the iPod, on the TV, and even on a 1280x800 laptop screen.
 
Due to the iPod's limited feature support for H.264, the command for doing the encode is that much more complex. You can also adjust the bitrate controls (-b is average bitrate, -rc_max_rate is the max instantaneous bitrate spike allowed). The iPod supports up to 1500kbit. Note that this is a 2-pass encode. Doing two passes allows for more accurate bitrate control and substantially better quality, but the encode will take twice as long as a one-pass. The resulting mp4 looks great on the iPod, on the TV, and even on a 1280x800 laptop screen.
 
 
You can also use H.264 to do 320x240 encodes if you are not interested in the ability to output the mp4 on your TV or your computer. Simply replace 640x480 with 320x240. You can also reduce the average bitrate (-b) to 175, and it still looks flawless. Quality is still "bearable" even down to around 130kbit. Try doing that with xvid!
 
You can also use H.264 to do 320x240 encodes if you are not interested in the ability to output the mp4 on your TV or your computer. Simply replace 640x480 with 320x240. You can also reduce the average bitrate (-b) to 175, and it still looks flawless. Quality is still "bearable" even down to around 130kbit. Try doing that with xvid!
 
 
Note that as of December 2006, the SVN version of ffmpeg has renamed several options and some options now use bits/s instead of kilobits.  The following command is the same as above except modified to work with the new SVN version:
 
Note that as of December 2006, the SVN version of ffmpeg has renamed several options and some options now use bits/s instead of kilobits.  The following command is the same as above except modified to work with the new SVN version:
 
<pre><nowiki>
 
<pre><nowiki>
 
ffmpeg -y -i input_file.avi -an -v 1 -threads auto -vcodec libx264 -b 500k -bt 175k -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 1 -me_range 21 -chroma 1 -slice 2 -bf 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -qdiff 4 -i_qfactor 0.71428572 -maxrate 768k -bufsize 2M -cmp 1 -s 640x480 -f mp4 -pass 1 /dev/null
 
ffmpeg -y -i input_file.avi -an -v 1 -threads auto -vcodec libx264 -b 500k -bt 175k -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 1 -me_range 21 -chroma 1 -slice 2 -bf 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -qdiff 4 -i_qfactor 0.71428572 -maxrate 768k -bufsize 2M -cmp 1 -s 640x480 -f mp4 -pass 1 /dev/null
 
 
ffmpeg -y -i input_file.avi -v 1 -threads auto -vcodec libx264 -b 500k -bt 175k -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 6 -me_range 21 -chroma 1 -slice 2 -bf 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -qdiff 4 -i_qfactor 0.71428572 -maxrate 768k -bufsize 2M -cmp 1 -s 640x480 -acodec libfaac -ab 96 -ar 48000 -ac 2 -f mp4 -pass 2 output_file.mp4
 
ffmpeg -y -i input_file.avi -v 1 -threads auto -vcodec libx264 -b 500k -bt 175k -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 6 -me_range 21 -chroma 1 -slice 2 -bf 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -qdiff 4 -i_qfactor 0.71428572 -maxrate 768k -bufsize 2M -cmp 1 -s 640x480 -acodec libfaac -ab 96 -ar 48000 -ac 2 -f mp4 -pass 2 output_file.mp4
 
</nowiki></pre>
 
</nowiki></pre>
 
 
 
Another note. As of October, 2007 (or before), the syntax has changed slightly. The names of the codecs are now more generic (h264 vs. libx264, aac vs. libfaac):
 
Another note. As of October, 2007 (or before), the syntax has changed slightly. The names of the codecs are now more generic (h264 vs. libx264, aac vs. libfaac):
 
<pre><nowiki>
 
<pre><nowiki>
 
ffmpeg -y -i input_file.avi -an -v 1 -threads auto -vcodec h264 -b 500k -bt 175k -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 1 -me_range 21 -chroma 1 -slice 2 -bf 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -qdiff 4 -i_qfactor 0.71428572 -maxrate 768k -bufsize 2M -cmp 1 -s 640x480 -f mp4 -pass 1 /dev/null
 
ffmpeg -y -i input_file.avi -an -v 1 -threads auto -vcodec h264 -b 500k -bt 175k -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 1 -me_range 21 -chroma 1 -slice 2 -bf 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -qdiff 4 -i_qfactor 0.71428572 -maxrate 768k -bufsize 2M -cmp 1 -s 640x480 -f mp4 -pass 1 /dev/null
 
 
ffmpeg -y -i input_file.avi -v 1 -threads auto -vcodec h264 -b 500k -bt 175k -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 6 -me_range 21 -chroma 1 -slice 2 -bf 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -qdiff 4 -i_qfactor 0.71428572 -maxrate 768k -bufsize 2M -cmp 1 -s 640x480 -acodec aac -ab 96 -ar 48000 -ac 2 -f mp4 -pass 2 output_file.mp4
 
ffmpeg -y -i input_file.avi -v 1 -threads auto -vcodec h264 -b 500k -bt 175k -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 6 -me_range 21 -chroma 1 -slice 2 -bf 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -qdiff 4 -i_qfactor 0.71428572 -maxrate 768k -bufsize 2M -cmp 1 -s 640x480 -acodec aac -ab 96 -ar 48000 -ac 2 -f mp4 -pass 2 output_file.mp4
 
</nowiki></pre>
 
</nowiki></pre>
 
 
=== Encoding from a DVD source ===
 
=== Encoding from a DVD source ===
 
 
As mentioned, ffmpeg is able to take .VOB files from the video_ts directory of a dvd as a source. However, VOBs are usually split arbitrarily into 1GB pieces, sometimes even two titles are mixed together in one VOB, making it very inconvenient to use this method of encoding.
 
As mentioned, ffmpeg is able to take .VOB files from the video_ts directory of a dvd as a source. However, VOBs are usually split arbitrarily into 1GB pieces, sometimes even two titles are mixed together in one VOB, making it very inconvenient to use this method of encoding.
 
 
However, our good friend mplayer will come to the rescue. By instructing mplayer to play a particular title, you can dump the complete vob for that title directly to the hard disk. You will need mplayer installed (also from Multiverse)
 
However, our good friend mplayer will come to the rescue. By instructing mplayer to play a particular title, you can dump the complete vob for that title directly to the hard disk. You will need mplayer installed (also from Multiverse)
 
 
<pre><nowiki>
 
<pre><nowiki>
 
mplayer dvd://1 -dumpstream -dumpfile dump.vob
 
mplayer dvd://1 -dumpstream -dumpfile dump.vob
 
</nowiki></pre>
 
</nowiki></pre>
 
 
This will output the first title of your DVD to dump.vob, which you can then give to ffmpeg as the input. Note that mplayer doesn't generate any progress indication and will appear to 'hang' during this process. Please be patient! If you are familiar with mplayer, you can fine-tune that command to dump a particular chapter, range of chapters, or many other modifications, too.
 
This will output the first title of your DVD to dump.vob, which you can then give to ffmpeg as the input. Note that mplayer doesn't generate any progress indication and will appear to 'hang' during this process. Please be patient! If you are familiar with mplayer, you can fine-tune that command to dump a particular chapter, range of chapters, or many other modifications, too.
 
 
An alternate method is to do an ordinary DVD rip to an AVI or other format using your favorite DVD ripping tool, then feed that output to ffmpeg. The benefit to this approach is that there are many nice DVD-ripping GUI's to choose title/chapters, audio streams, cropping, and so on. The downsides are that you will suffer a slightly degraded quality and you have to wait for the dvd to rip to AVI format before being able to use ffmpeg to convert it to MP4.
 
An alternate method is to do an ordinary DVD rip to an AVI or other format using your favorite DVD ripping tool, then feed that output to ffmpeg. The benefit to this approach is that there are many nice DVD-ripping GUI's to choose title/chapters, audio streams, cropping, and so on. The downsides are that you will suffer a slightly degraded quality and you have to wait for the dvd to rip to AVI format before being able to use ffmpeg to convert it to MP4.
 
 
=== Widescreen Resolutions ===
 
=== Widescreen Resolutions ===
 
 
Your iPod supports a maximum of 640x480 or 320x240, but anything in that's below those specs would work. For widescreen, just adjust that ratio so that the width <= 640 and height <= 480. It's advisable to keep both dimensions a multiple of 16, else the encoder will not compress as efficiently.
 
Your iPod supports a maximum of 640x480 or 320x240, but anything in that's below those specs would work. For widescreen, just adjust that ratio so that the width <= 640 and height <= 480. It's advisable to keep both dimensions a multiple of 16, else the encoder will not compress as efficiently.
 
 
=== Black Screen or iPod Resets When Trying to Play Video ===
 
=== Black Screen or iPod Resets When Trying to Play Video ===
 
 
The mp4's that ffmpeg generates are slightly nonstandard. Firmware 1.1 iPods had severe issues playing them back, typically marked by audio suddenly disappearing 15 seconds into the video. Firmware 1.2 fixes these issues, so for the large part ffmpeg's mp4's work perfectly on the iPod. However, on short clips encoded in h.264, the iPod still may show a black screen, freeze, or reset when trying to play it.
 
The mp4's that ffmpeg generates are slightly nonstandard. Firmware 1.1 iPods had severe issues playing them back, typically marked by audio suddenly disappearing 15 seconds into the video. Firmware 1.2 fixes these issues, so for the large part ffmpeg's mp4's work perfectly on the iPod. However, on short clips encoded in h.264, the iPod still may show a black screen, freeze, or reset when trying to play it.
 
 
''The pypodconv script already performs this workaround listed below. If you are using the pypodconv script, you should not encounter this issue''
 
''The pypodconv script already performs this workaround listed below. If you are using the pypodconv script, you should not encounter this issue''
 
 
The solution is to use MP4Box to repack the mp4. You will need <code><nowiki>gpac</nowiki></code> installed from Multiverse:
 
The solution is to use MP4Box to repack the mp4. You will need <code><nowiki>gpac</nowiki></code> installed from Multiverse:
 
<pre><nowiki>
 
<pre><nowiki>
第278行: 第193行:
 
</nowiki></pre>
 
</nowiki></pre>
 
This repacks original.mp4 into fixed.mp4. After this is done, you may remove original.mp4. You may have seen some guides suggesting to -add original directly to original, and that'll pack it "in place". This is WRONG. It will just give you a double-sized mp4 file that still won't play on the iPod!
 
This repacks original.mp4 into fixed.mp4. After this is done, you may remove original.mp4. You may have seen some guides suggesting to -add original directly to original, and that'll pack it "in place". This is WRONG. It will just give you a double-sized mp4 file that still won't play on the iPod!
 
 
Since for larger video files, the repacking procedure could be quite time consuming, it's a good practice not to do it except for the rare portion of files that fail without repacking.
 
Since for larger video files, the repacking procedure could be quite time consuming, it's a good practice not to do it except for the rare portion of files that fail without repacking.
 
 
 
 
=== iTunes complains about these files, but GtkPod transfers them and the iPod plays fine ===
 
=== iTunes complains about these files, but GtkPod transfers them and the iPod plays fine ===
 
 
'''2007-11-20: There is now a fix for this issue'''. Upgrade to the latest gpac in Hardy (0.4.4) or soon to be in Gutsy Backports, then download the newest pypodconv.ffmpegsvn branch linked in the instructions. This allows MP4Box to output the iPod MP4 header.
 
'''2007-11-20: There is now a fix for this issue'''. Upgrade to the latest gpac in Hardy (0.4.4) or soon to be in Gutsy Backports, then download the newest pypodconv.ffmpegsvn branch linked in the instructions. This allows MP4Box to output the iPod MP4 header.
 
 
This phenomenon mostly happens with the 640x480 H.264 encodes. iTunes expects to find a QuickTime-specific MP4 header and rejects the results from any other encoder. However, when the MP4's are transferred onto the iPod with another program (i.e. GtkPod), the iPod plays them back without a hitch.
 
This phenomenon mostly happens with the 640x480 H.264 encodes. iTunes expects to find a QuickTime-specific MP4 header and rejects the results from any other encoder. However, when the MP4's are transferred onto the iPod with another program (i.e. GtkPod), the iPod plays them back without a hitch.
 
 
This is a known issue, and there's been some patches and discussion over at the ffmpeg mailing list. If you're interested in learning more about this, see: http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2006-September/045391.html
 
This is a known issue, and there's been some patches and discussion over at the ffmpeg mailing list. If you're interested in learning more about this, see: http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2006-September/045391.html
 
 
 
[[category:CategoryDocumentation]] [[category:CategoryCleanup]]
 
[[category:CategoryDocumentation]] [[category:CategoryCleanup]]
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2007年11月30日 (五) 18:06的版本

Encoding Video for the iPod Video

This is a guide for encoding video to a format acceptable by the 5th generation iPods, aka the iPod Video (The format is also compatible with 6th generation iPods, iPhones, Apple TV's, and the QuickTime player / iTunes. The following methods have been tested successfully on Ubuntu Breezy through Gutsy. They require adding new repositories (Feisty and higher) or rebuilding your system's ffmpeg (before Feisty), so be warned that the modifications to your system from this guide won't be officially condoned by Canonical. If you need more information, make sure to check out the iPod Video wiki page, as well as the Guide to Transferring Video to the iPod Video. As for encoding, you will have to recompile ffmpeg so that it has the correct configuration in order to encode videos in the format required by the iPod Video. This guide walks you through compiling and installing ffmpeg correctly, as well as encoding video correctly using ffmpeg. However, you could also just choose to use a tool which will do all of this automatically for you. And here's how!

Mark Pilgrim's mencoder based solution

This script does not use ffmpeg (like the others) and allows you to bypass the hassles of the other methods that require you to add new repositories or even rebuild ffmpeg. mencoder also does better with WMV, Real Video, and other very proprietary formats by allowing you to take advantage of w32codecs. Like pypodconv below, it also uses the high-quality H.264 video codec.

sudo aptitude install lsdvd mplayer gpac zenity
sudo wget http://diveintomark.org/public/2007/06/podencoder.txt -O /usr/local/bin/podencoder
sudo chmod +x /usr/local/bin/podencoder
podencoder foo.mpg
podencoder foo.avi
podencoder foo.wmv
podencoder
podencoder --help

Fixing ffmpeg on Ubuntu

For Ubuntu 7.04 Feisty Fawn, ffmpeg in Medibuntu contains this "unlocked" ffmpeg. Enable Medibuntu with the instructions here, then skip this section! Edgy/Dapper users, follow these instructions: For a litany of legal reasons, ffmpeg does not come with all of the necessary things enabled for you to encode video for the iPod Video by default. Therefore, we need to build it from source and install some other libraries and programs, as well. Make sure you have multiverse and universe enabled. Apologies for this necessary procedure -- it certainly looks intimidating. I (JohnDong) am currently working with Medibuntu to have ready-to-use packages available in the form of an APT repository. In the terminal, run:

sudo apt-get build-dep ffmpeg
sudo apt-get install ffmpeg
sudo apt-get install liblame-dev libfaad2-dev libfaac-dev libxvidcore4-dev liba52-0.7.4 liba52-0.7.4-dev libx264-dev

64-bit (AMD64) Ubuntu users only: You need to force ffmpeg to link against the PIC version of ffmpeg. Issue the following command:

sudo cp /usr/lib/libx264_pic.a /usr/lib/libx264.a

All users: Continue with the following commands:

apt-get source ffmpeg
cd ffmpeg-*/
./configure --enable-gpl --enable-pp --enable-pthreads \
	--enable-libogg --enable-a52 --enable-dts \
	--enable-dc1394 --enable-libgsm --disable-debug --enable-mp3lame \
	--enable-faad --enable-faac --enable-xvid --enable-x264
make
sudo make install
If you are using the FFMPEG source from a edgy repository, skip the rest of this code block.
If you are using the FFMPEG source from a recent (20070331) SVN checkout, the configure options have changed.  Use this line instead of the one above and then continue with the make command:
./configure --enable-gpl --enable-pp --enable-pthreads \
--enable-libogg --enable-liba52 --enable-libdts \
--enable-dc1394 --enable-libgsm --disable-debug --enable-libmp3lame \
--enable-libfaad --enable-libfaac --enable-xvid --enable-x264 

Note how you should first install ffmpeg before doing sudo make install. This will work less intrusively as checkinstall, as it just overwrites the exact files owned by the ffmpeg package without disturbing the way the package structure is registered to dpkg. 64-bit (AMD64) Ubuntu users only: Revert the change we made above to your system:

sudo apt-get install --reinstall libx264-dev

Script 1: pypodconv Script

This is a newer (03/2007) Python script that encapsulates all the below functionality into a script. It requires ffmpeg AND gpac to work. And due to the number of people who apparently glanced over that, here it is again: You need gpac from multiverse for the script to function. (If you forget to install that, the encoding will fail at the very end, nullifying your hours of encoding work). Here's a "screenshot":

jdong@severance:~/src/pypodconv$ pypodconv
Usage: pypodconv [options]
Options:
-h, --help            show this help message and exit
-i INPUT, --input=INPUT
Source file to encode
--sd, --320, --standard-definition
Encode to Standard Definition (that is, 320xNNN,
native iPod screen resolution) [DEFAULT]
--hd, --640, --high-definition
Encode to High Definition (that is, 640xNNN, maximum
iPod-supported resolution
-c CODEC, --codec=CODEC
Video Codec: h264 [DEFAULT], xvid, or mpeg4.
-o OUTPUT, --output=OUTPUT
Output file, with file extension.
-b VBITRATE, --vbitrate=VBITRATE
Video Bitrate, in kbit/s. (default: 200)
-p PASSES, --passes=PASSES
Number of passes. (Default: 2)

To install, download pypodconv and save it to /tmp. Then, run:

sudo apt-get install gpac
sudo mv /tmp/pypodconv /usr/local/bin/pypodconv
sudo chmod +x /usr/local/bin/pypodconv

For Gutsy and SVN ffmpeg, use this pypodconv. The basic operation is:

pypodconv -i INPUT_FILE -o OUTPUT_FILE

This by default creates a 200kbit/s 320xNNN 2-pass H.264 video, suitable for iPod viewing. The help printout is useful for figuring out the other methods of usage. For example, if I want to make 500kbit high-definition encodes, I'd do:

pypodconv -i INPUT_FILE -o OUTPUT_FILE --hd -b 500

Support: For now, I will handle support personally through my e-mail: jdong <at> ubuntu (dot) com. If demand rises then I will make a formal Launchpad product.

Script 2: ipodvidenc Script

Finally, to encode the videos you can create a script for converting your videos to iPod Video format.

gedit

This should pop up a blank document. Now, just copy and paste this code into it:

input_file=$1
echo "What would you like to name the output file (sans extension)?"
read output_file_name
echo "$output_file_name will be located in $PWD. Is this acceptable? [y/n]"
read output_file_loc_permis
if [ $output_file_loc_permis == 'n' ] || [ $output_file_loc_permis == 'N' ]
then
	echo "Where would you like to store $output_file_name.mov?"
	read output_dir
else
	output_dir=$PWD
fi
ffmpeg -i ${input_file} -f mp4 -vcodec mpeg4 -maxrate 1000 -b 700 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec aac -ab 192 -s 320x240 -aspect 4:3 ${output_dir}/${output_file_name}.mov

Save as ipodvidenc in your present working directory (it will be moved, anyway). Back in the terminal, run:

chmod 755 ipodvidenc
sudo mv ipodvidenc /usr/bin

Now, when you want to encode a video to iPod format, run this command:

ipodvidenc video.avi

It will run you through a few prompts and then encode the video and put it into the correct format. As of January 15th, 2006, using this method will work with raw .vob files, meaning that you no longer have to transcode your DVDs! If you followed this guide before Januray 15th, 2006, you can get .vob encoding support by doing the following: sudo apt-get install liba52-0.7.4 liba52-0.7.4-dev Edit the debian/rules file in the ffmpeg source folder to include: confflags += --enable-a52 Then reconfigure, remake, and reinstall.

The gui option - thinliquidfilm

If you would prefer to use a gui to encode video, then you can use thinliquidfilm. thinliquidfilm is a gui frontend for ffmpeg, specifically designed to encode ipod compatible videos. You can find it here. It requires ffmpeg (compiled as set out above) and pyqt (which is installed as part of the kubuntu-desktop package). There are other non-essential dependencies for uploading to an ipod (see the Guide to Transferring Video to the iPod Video for more details) and mplayer is required to preview encoded videos before encoding). thinliquidfilm will:

  • Batch process any number of files;
  • Display detailed information about source video files;
  • Change output settings for one or many files;
  • Save default settings for future sessions;
  • Configure output quality settings;
  • Choose between mpeg4 and h264 as output codec;
  • Choose between 320 and 640 output video width, while maintaining aspect ratio;
  • Choose between 1 or 2 pass encoding;
  • Preview encoded videos before encoding;
  • Progress bar to show encoding progress;
  • Uses ffmpeg as the encoding engine;
  • Upload encoded files to your ipod directly;
  • Set file information for upload to your ipod;
  • Add files to existing or new video playlists on your ipod;
  • Add pre-encoded videos to the transfer list;
  • Add files for encoding via the included servicemenu.

Installation is very simple with the included installation script. The website has comprehensive documentation on installing and using thinliquidfilm, and therefore there is no point in repeating it here.

Using ffmpeg

If you would like to have more control than ipodvidenc or thinliquid film gives, and just use an ffmpeg command, and perhaps set it as an alias, the command is as follows:

ffmpeg -i input_file.avi -f mp4 -vcodec mpeg4 -maxrate 1000 -b 700 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec aac -ab 192 -s 320x240 -aspect 4:3 output_file.mov

This encodes a 700kbit MPEG-4 ASP (i.e. "xvid") format video using ffmpeg's mpeg4 encoder. Alternatively, you may use the xvid codec, which squeezes a bit more quality for the same bitrate than the above command, though it is slightly slower. Simply replace "mpeg4" with "xvid". Since Firmware 1.2 and higher, you can bump -maxrate and/or -b to 2500, and resolution (-s) to 640x480. Note that you will need to bump up the bitrate to at least 1000kbit if you want a good-looking 640x480 mpeg4-ASP video.

H.264 Encoding

H.264 (MPEG-4 AVC) is a newer codec that the iPod supports. It's able to deliver similar quality at half the bitrate of MPEG-4 ASP! However, it is an extremely slow and CPU-intensive encoder. Expect the encode to take 5x longer than mpeg4 or xvid. You also need ffmpeg compiled with x264 support. As of 20-Dec-2006 this guide has been updated to reflect that, but if you rebuilt your ffmpeg before then, you need to follow the "fixing ffmpeg" procedure again for x264 support. Due to this enormous speed tradeoff, it's most practical to use H.264 for encoding high-resolution 640x480 video suitable for outputting to a TV (or also for viewing on your computer). Here's the ffmpeg command for doing a 500kbit 640x480 H.264 encode:

ffmpeg -y -i input_file.avi -an -v 1 -threads auto -vcodec h264 -b 500 -bt 175 -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 1 -me_range 21 -chroma 1 -slice 2 -max_b_frames 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -max_qdiff 4 -i_quant_factor 0.71428572 -rc_max_rate 768 -rc_buffer_size 244 -cmp 1 -s 640x480 -f mp4 -pass 1 /dev/null
ffmpeg -y -i input_file.avi -v 1 -threads auto -vcodec h264 -b 500 -bt 175 -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 6 -me_range 21 -chroma 1 -slice 2 -max_b_frames 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -max_qdiff 4 -i_quant_factor 0.71428572 -rc_max_rate 768 -rc_buffer_size 244 -cmp 1 -s 640x480 -acodec aac -ab 96 -ar 48000 -ac 2 -f mp4 -pass 2 output_file.mp4

Due to the iPod's limited feature support for H.264, the command for doing the encode is that much more complex. You can also adjust the bitrate controls (-b is average bitrate, -rc_max_rate is the max instantaneous bitrate spike allowed). The iPod supports up to 1500kbit. Note that this is a 2-pass encode. Doing two passes allows for more accurate bitrate control and substantially better quality, but the encode will take twice as long as a one-pass. The resulting mp4 looks great on the iPod, on the TV, and even on a 1280x800 laptop screen. You can also use H.264 to do 320x240 encodes if you are not interested in the ability to output the mp4 on your TV or your computer. Simply replace 640x480 with 320x240. You can also reduce the average bitrate (-b) to 175, and it still looks flawless. Quality is still "bearable" even down to around 130kbit. Try doing that with xvid! Note that as of December 2006, the SVN version of ffmpeg has renamed several options and some options now use bits/s instead of kilobits. The following command is the same as above except modified to work with the new SVN version:

ffmpeg -y -i input_file.avi -an -v 1 -threads auto -vcodec libx264 -b 500k -bt 175k -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 1 -me_range 21 -chroma 1 -slice 2 -bf 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -qdiff 4 -i_qfactor 0.71428572 -maxrate 768k -bufsize 2M -cmp 1 -s 640x480 -f mp4 -pass 1 /dev/null
ffmpeg -y -i input_file.avi -v 1 -threads auto -vcodec libx264 -b 500k -bt 175k -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 6 -me_range 21 -chroma 1 -slice 2 -bf 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -qdiff 4 -i_qfactor 0.71428572 -maxrate 768k -bufsize 2M -cmp 1 -s 640x480 -acodec libfaac -ab 96 -ar 48000 -ac 2 -f mp4 -pass 2 output_file.mp4

Another note. As of October, 2007 (or before), the syntax has changed slightly. The names of the codecs are now more generic (h264 vs. libx264, aac vs. libfaac):

ffmpeg -y -i input_file.avi -an -v 1 -threads auto -vcodec h264 -b 500k -bt 175k -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 1 -me_range 21 -chroma 1 -slice 2 -bf 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -qdiff 4 -i_qfactor 0.71428572 -maxrate 768k -bufsize 2M -cmp 1 -s 640x480 -f mp4 -pass 1 /dev/null
ffmpeg -y -i input_file.avi -v 1 -threads auto -vcodec h264 -b 500k -bt 175k -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 6 -me_range 21 -chroma 1 -slice 2 -bf 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -qdiff 4 -i_qfactor 0.71428572 -maxrate 768k -bufsize 2M -cmp 1 -s 640x480 -acodec aac -ab 96 -ar 48000 -ac 2 -f mp4 -pass 2 output_file.mp4

Encoding from a DVD source

As mentioned, ffmpeg is able to take .VOB files from the video_ts directory of a dvd as a source. However, VOBs are usually split arbitrarily into 1GB pieces, sometimes even two titles are mixed together in one VOB, making it very inconvenient to use this method of encoding. However, our good friend mplayer will come to the rescue. By instructing mplayer to play a particular title, you can dump the complete vob for that title directly to the hard disk. You will need mplayer installed (also from Multiverse)

mplayer dvd://1 -dumpstream -dumpfile dump.vob

This will output the first title of your DVD to dump.vob, which you can then give to ffmpeg as the input. Note that mplayer doesn't generate any progress indication and will appear to 'hang' during this process. Please be patient! If you are familiar with mplayer, you can fine-tune that command to dump a particular chapter, range of chapters, or many other modifications, too. An alternate method is to do an ordinary DVD rip to an AVI or other format using your favorite DVD ripping tool, then feed that output to ffmpeg. The benefit to this approach is that there are many nice DVD-ripping GUI's to choose title/chapters, audio streams, cropping, and so on. The downsides are that you will suffer a slightly degraded quality and you have to wait for the dvd to rip to AVI format before being able to use ffmpeg to convert it to MP4.

Widescreen Resolutions

Your iPod supports a maximum of 640x480 or 320x240, but anything in that's below those specs would work. For widescreen, just adjust that ratio so that the width <= 640 and height <= 480. It's advisable to keep both dimensions a multiple of 16, else the encoder will not compress as efficiently.

Black Screen or iPod Resets When Trying to Play Video

The mp4's that ffmpeg generates are slightly nonstandard. Firmware 1.1 iPods had severe issues playing them back, typically marked by audio suddenly disappearing 15 seconds into the video. Firmware 1.2 fixes these issues, so for the large part ffmpeg's mp4's work perfectly on the iPod. However, on short clips encoded in h.264, the iPod still may show a black screen, freeze, or reset when trying to play it. The pypodconv script already performs this workaround listed below. If you are using the pypodconv script, you should not encounter this issue The solution is to use MP4Box to repack the mp4. You will need gpac installed from Multiverse:

MP4Box -add original.mp4 fixed.mp4

This repacks original.mp4 into fixed.mp4. After this is done, you may remove original.mp4. You may have seen some guides suggesting to -add original directly to original, and that'll pack it "in place". This is WRONG. It will just give you a double-sized mp4 file that still won't play on the iPod! Since for larger video files, the repacking procedure could be quite time consuming, it's a good practice not to do it except for the rare portion of files that fail without repacking.

iTunes complains about these files, but GtkPod transfers them and the iPod plays fine

2007-11-20: There is now a fix for this issue. Upgrade to the latest gpac in Hardy (0.4.4) or soon to be in Gutsy Backports, then download the newest pypodconv.ffmpegsvn branch linked in the instructions. This allows MP4Box to output the iPod MP4 header. This phenomenon mostly happens with the 640x480 H.264 encodes. iTunes expects to find a QuickTime-specific MP4 header and rejects the results from any other encoder. However, when the MP4's are transferred onto the iPod with another program (i.e. GtkPod), the iPod plays them back without a hitch. This is a known issue, and there's been some patches and discussion over at the ffmpeg mailing list. If you're interested in learning more about this, see: http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2006-September/045391.html