个人工具

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

来自Ubuntu中文

跳转至: 导航, 搜索
(创建新页面为 '{{From|https://help.ubuntu.com/community/AndroidVideoEncoding}} {{Languages|UbuntuHelp:AndroidVideoEncoding}} <<Include(Tag/ContentCleanup)>> == Encoding Video for the Android P...')
 
 
(未显示同一用户的2个中间版本)
第1行: 第1行:
 
{{From|https://help.ubuntu.com/community/AndroidVideoEncoding}}
 
{{From|https://help.ubuntu.com/community/AndroidVideoEncoding}}
 
{{Languages|UbuntuHelp:AndroidVideoEncoding}}
 
{{Languages|UbuntuHelp:AndroidVideoEncoding}}
<<Include(Tag/ContentCleanup)>>
+
== Encoding Video for the Android Phone, for example, HTC/Google G1 ==
== Encoding Video for the Android Phone, for example, G1 ==
+
HTC/Google G1 phone can decode mpeg4, h263 and h264 codecs and can play mp4 and 3gp video formats.  Since these format combinations are relatively uncommon, here are instructions to convert your videos to the compatible format.
Google G1 phone can decode mpeg4, h263 and h264 codecs and can play mp4 and 3gp video formats.  Since these format combinations are relatively uncommon, here are instructions to convert your videos to the compatible format.
+
If your source is a DVD, skip to [[UbuntuHelp:[Using HandBrake (GUI)|HandBrake section]]]
=== Before you begin ===
+
== Using Avidemux (GUI) ==
==== Fixing ffmpeg on Ubuntu ====
+
=== Supported operations ===
 +
{|border="1" cellspacing="0"
 +
|Source||Support Matrix||Workaround
 +
|-
 +
|Individual file||SUPPORTED||
 +
|-
 +
|DVD||NOT SUPPORTED||[[UbuntuHelp:DVD::Rip|DVD::Rip]]
 +
|}
 +
=== Instructions ===
 +
This method has been tested in Ubuntu 9.04, adapted from [http://www.android-unleashed.com/2008/11/howto-encode-video-for-android-g1-with.html this article].  It will produce a movie encoded with mpeg4 codec, fast but not optimal.
 +
<ol><li>Install the avidemux package from the Ubuntu multiverse repository
 +
</li><li>Configure video options:
 +
<ol><li>Click on the video dropdown on the left and select MPEG-4 ASP (lavc)
 +
</li><li>Click Configure->Encoding Mode->Single Pass - Bitrate
 +
</li><li>Enter in any bitrate up to 512 to be safe, then click Ok.
 +
</li><li>Click Filters->[[UbuntuHelp:MPlayer|MPlayer]] Resize->Double Click on it-> Width:432, Height:320 if source video is standard resolution.
 +
<ol><li>For widescreen source, choose Width:480, Height:272.
 +
</li><li>Click Ok, then close.
 +
</li></ol></li></ol></li><li>Configure audio options:
 +
<ol><li>Click Audio->AAC (FAAC)
 +
</li><li>Configure->Bitrate 96
 +
</li><li>Click Format->MP4
 +
</li></ol></li><li>Click Save and specify a name.mp4 for your video, encoding will start
 +
</li><li>Once enconding has completed, plug in your phone via USB and transfer the video to it, anywhere. The videos can be opened directly using a file manager such as Astro.</li></ol>
 +
 
 +
== Using WinFF (GUI) ==
 +
This method will achieve '''superior compression''' using a newer [http://en.wikipedia.org/wiki/Video_codec video codec] and higher level of control.
 +
{{http://winff.org/images/screenshots/winff044-ubuntu-small.jpg}}
 +
=== Supported operations ===
 +
{|border="1" cellspacing="0"
 +
|Source||Support Matrix||Workaround
 +
|-
 +
|Individual file||SUPPORTED||
 +
|-
 +
|DVD||NOT SUPPORTED||[[UbuntuHelp:DVD::Rip|DVD::Rip]]
 +
|}
 +
Install WinFF on Ubuntu 9.04 or later using by clicking on the following link: '''[[UbuntuHelp:apt:winff|apt:winff]]'''.  For older version of Ubuntu, please click on the link for the instructions: [http://ubuntuforums.org/showthread.php?t=766683 Instructions for WinFF installation]
 +
=== Instructions ===
 +
* Click on Options and verify that Additional Options are selected -- they will show up on the bottom of the screen
 +
* Click on Add and select one or multiple movies that you want to convert.
 +
* Select Convert to: Ipod
 +
* Select Device Presets: H.264 for Ipod *Linux* (4:3) for standard resolution or H.264 for Ipod *Linux* (16:9) for wide resolution
 +
* In the Additional Options below, choose Video Settings and type Video Size: 432 x 320 for standard resolution and 480 x 272 for wide resolution
 +
* In Audio Settings: If you are planning to listen primarily with headphones, do nothing.  If you are planning to listen on the speakerphone, select Audio Channels: 1 to create mono sound.
 +
* Click on Convert toolbar icon.
 +
== Using HandBrake (GUI) ==
 +
[http://trac.handbrake.fr/wiki/LinGuiScreenshots {{http://trac.handbrake.fr/raw-attachment/wiki/LinGuiScreenshots/HandBrake-Pic.jpeg}}]
 +
=== Supported operations ===
 +
{|border="1" cellspacing="0"
 +
|Source||Support Matrix
 +
|-
 +
|Individual file||SUPPORTED
 +
|-
 +
|DVD||SUPPORTED
 +
|}
 +
=== Installation ===
 +
Summary of instructions from [https://launchpad.net/~handbrake-ubuntu/+archive/ppa].
 +
Ubuntu 9.10 karmic and later: add '''ppa:handbrake-ubuntu/ppa''' to your system's Software Sources. 
 +
Ubuntu 9.04 and earlier: Copy and paste the following command into the terminal to add the new WinFF repository (example for JAUNTY, SUBSTITUTE WITH YOUR VERSION):
 +
<pre><nowiki>
 +
echo "For 9.04 and earlier versions only!"
 +
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com A58BCAE3
 +
echo "deb http://ppa.launchpad.net/handbrake-ubuntu/ppa/ubuntu jaunty main" | sudo tee /etc/apt/sources.list.d/handbrake.list
 +
sudo apt-get update && sudo apt-get install handbrake-gtk
 +
</nowiki></pre>
 +
=== G1-specific Video Conversion Instructions ===
 +
<ol><li>When encoding a DVD, select File, "/dev/dvd".  Name might be different.
 +
</li><li>When encoding a file, click on Source and select a desired source file.
 +
</li><li>Click on Preset: Apple -> iPhone & iPod Touch
 +
</li><li>Click on Video tab.  In Quality, reduce quality to 49 and uncheck Constant Rate Factor
 +
</li><li>Click on Start.
 +
</li><li>Once encoding has completed, plug in your phone via USB and transfer the video to it, anywhere. The videos can be opened directly using a file manager such as Astro.</li></ol>
 +
 
 +
=== Preset File for Import ===
 +
Tested on HTC Hero: To import, choose "options" at the bottom right of the window, then import.
 +
[[UbuntuHelp:attachment:Android_Tested_on_Hero.plist|attachment:Android_Tested_on_Hero.plist]]
 +
== Expert mode: Using ffmpeg (command line) ==
 +
=== Supported operations ===
 +
{|border="1" cellspacing="0"
 +
|Source||Support Matrix
 +
|-
 +
|Individual file||SUPPORTED
 +
|-
 +
|DVD||NOT SUPPORTED
 +
|}
 +
=== Introduction ===
 +
This method will give you the greatest control of the resulting output.
 
For most versions of Ubuntu, ffmpeg in Medibuntu contains this "unlocked" ffmpeg. Enable Medibuntu with the [[UbuntuHelp:Medibuntu|instructions here]].
 
For most versions of Ubuntu, ffmpeg in Medibuntu contains this "unlocked" ffmpeg. Enable Medibuntu with the [[UbuntuHelp:Medibuntu|instructions here]].
=== Starting with video size ===
 
G1 phone displays best videos with resolution of 480x320.  This is often called 3:2 aspect ratio.  The problem is nearly no videos come in this format. Most popular aspect ratios are 4:3 and 16:9, and they will look stretched and deformed unless you pad them properly.  So, there are a few more options you'll need to know, but you have to do the math.
 
* -padtop #, -padbottom #, -padleft #, -padright # - number of pixels thick of padding (black bar) to put on this edge of the video.
 
I'll use ''The Terminal'' starring Catherine Zeta Jones and Tom Hanks as a perfect example. The rip I have is 480x256. Not the highest grade to begin with, but I'll live. This is a 1.875:1 ratio, neither 16:9, 16:10. 4:3, nor 3:2. Doesn't matter though, because the G1 screen is 480 pixels wide to begin with. We just need to pad the video out to 320 pixels tall. 320 - 256 is 64, so we need 32 pixels top and bottom: '''-padtop 32 -padbottom 32'''
 
mplayer spits out the size of the movie in the command line window before playing it, so get the size ratios from that. Divide the actual width by the intended width to get a number, then divide the actual height by that same number to get the intended height. This way, your video will always be full width (assuming you're doing widescreen). If you're doing 4:3, simply swap height and width and solve for the other).
 
For another example, ''Office Space'', in my rip, is 672 by 352. I want to scale it to fit 480 by 320. 672 (starting width) divided by 480 (target width) is 1.4, so if I divide 672 by 1.4 I get 480. 1.4 is the magic ratio, because now I know what to divide the starting height by to get the target height. So likewise, I divide 352 (starting height) by 1.4 and I get 251.4 (target height). Since ffmpeg requires an even number (and you can't have a fraction of a pixel), I'll round it down to 250 (252 would work too, it won't be visibly noticeable). So the output video will be 480 by 250. [edit: This is the -s option above, and thus should be '''-s 480x250''' on the ffmpeg command line.] This will be full width in the G1, but requires padding top and bottom to prevent the G1 decoder from stretching it to fill the screen. 320 (screen height) - 250 (video height) is 70. Since the padding number must be an even one, I'll go with 34 pixels on top and 36 on the bottom to equal 70 total. (edit: '''-padtop 34 -padbottom 36''' on the ffmpeg command line.)
 
But what if you like old T.V. shows, videos from your digital camera or a camcoder? Let's say we have a 4:3 video, let's say it's 640 by 480, and we want it to be on the G1. Well, if we fit full width, the G1 will shrink it to fit, and everyone will look wide, so instead, we fit it full height and pad out the width. We know, therefore, the height has to be 320, but it's currently 480. 480 divided by 320 is 1.5, so we divide 640 by 1.5 to get the intended width of 426.667. So we can scale 640x480 down to '''426x320'''. It will now need padding on the left and right to keep G1 from stretching it out to fit the screen. 480 wide, minus 426 output, is 54. Divide by 2 to get 27. '''Pad left 26 and pad right 28''' and you'll have perfect aspect ratio that will fit the screen.
 
The size and the padding options apply to the following two sections.  The '''-s''' is the output size BEFORE applying crop and pad arguments.  The padding options will be used in examples below.
 
 
=== MPEG4 (standard) encoding ===
 
=== MPEG4 (standard) encoding ===
 
The default encoding of the videos is MPEG-4 ASP (i.e. "xvid") format video using ffmpeg's mpeg4 encoder.  If you are interested in higher quality encodings, which will take quite a bit more time but may result in better quality, see H.264 section below.
 
The default encoding of the videos is MPEG-4 ASP (i.e. "xvid") format video using ffmpeg's mpeg4 encoder.  If you are interested in higher quality encodings, which will take quite a bit more time but may result in better quality, see H.264 section below.
第22行: 第100行:
 
</nowiki></pre>
 
</nowiki></pre>
 
This is VERY basic. For full options, go to [http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html#SEC6 FFmpeg Documentation]
 
This is VERY basic. For full options, go to [http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html#SEC6 FFmpeg Documentation]
* -s is "size" of output video. This gave me fits early on because I tried it before (via GUI wrappers, IIRC) and was told by the program that this size wasn't supported regardless of which codec I selected. I don't know what the diff is, but it works for me now.
+
* -s is "size" of output video.  
 
* -vcodec Choices for G1 are mpeg4 and h263. IMHO I get better quality and marginally smaller file size with mpeg4.
 
* -vcodec Choices for G1 are mpeg4 and h263. IMHO I get better quality and marginally smaller file size with mpeg4.
 
* -acodec aac is the audio codec. I know of no other choice here for this purpose.  
 
* -acodec aac is the audio codec. I know of no other choice here for this purpose.  
第31行: 第109行:
 
* -ab 32000 bitrate of the audio -- 32 kbps in this case. Normally I'd balk at such low numbers, but remember, I'm trying to keep filesize low. I'm not broadcasting to a large audience with this, am I? No, it's for me. For you? Use your best judgement. Experiment a little.
 
* -ab 32000 bitrate of the audio -- 32 kbps in this case. Normally I'd balk at such low numbers, but remember, I'm trying to keep filesize low. I'm not broadcasting to a large audience with this, am I? No, it's for me. For you? Use your best judgement. Experiment a little.
 
* -aspect 3:2 Obviously, this is the aspect ratio of the output file. I'm not sure it matters, when the output size is being set before.
 
* -aspect 3:2 Obviously, this is the aspect ratio of the output file. I'm not sure it matters, when the output size is being set before.
With padding suggested above, the command line would be:
 
<pre><nowiki>
 
ffmpeg -i terminal.avi -s 480x256 -vcodec mpeg4 -acodec aac -ac 1 -ar 16000 -r 13 -ab 32000 -aspect 3:2 -padtop 32 -padbottom 32 terminal.G1.mp4
 
</nowiki></pre>
 
 
While ffmpeg is running, you should see the following:
 
While ffmpeg is running, you should see the following:
 
<pre><nowiki>
 
<pre><nowiki>
第41行: 第115行:
 
   Stream #0.1: Audio: aac, 16000 Hz, mono, s16, 32 kb/s
 
   Stream #0.1: Audio: aac, 16000 Hz, mono, s16, 32 kb/s
 
</nowiki></pre>
 
</nowiki></pre>
This will tell you exactly what the output file will be in width and height, and for the G1 should '''always''' be '''480x320''' for optimum scaling. If it's anything other than 480 by 320, you WILL have stretching in the playback on the G1. May be minimal; may not even be noticeable, but it will be there.
+
Very old versions of Android Video Player incorrectly scaled video, that is, if the video size was anything but 480 by 320, you would see stretching in the playback on the G1. It is no longer a problem.
 
=== H.264 Encoding ===
 
=== H.264 Encoding ===
 
[http://en.wikipedia.org/wiki/H.264 H.264 (MPEG-4 AVC)] is a newer codec that the G1 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 with x264 support.
 
[http://en.wikipedia.org/wiki/H.264 H.264 (MPEG-4 AVC)] is a newer codec that the G1 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 with x264 support.
Due to the G1's limited feature support for H.264, the command for doing the encode is that much more complex. If you are interested in technical details, G1 supports only the [http://en.wikipedia.org/wiki/H.264#Profiles BP (Baseline Profile) dialect of H.264]; videos that use more advanced features of H.264 play incorrectly, or not at all.  In case of incorrect video encoding, the most typical error is a black screen during playback on G1 while the audio plays.   
+
Due to the G1's limited feature support for H.264, the command for doing the encode is that much more complex. If you are interested in technical details, G1 supports only the [http://en.wikipedia.org/wiki/H.264#Profiles Constrained Baseline Profile (CBP) dialect of H.264]; videos that use more advanced features of H.264 play incorrectly, or not at all.  In case of incorrect video encoding, the most typical error is a black screen during playback on G1 while the audio plays.   
Note that since we am striving for better quality, the audio encoding is also set to higher standards.  Assuming source movie has aspect ratio 3:2, the command is:
+
Note that since we are striving for better quality, the audio encoding is also set to higher standards.  Assuming source movie has aspect ratio 4:3, the command is:
 
<pre><nowiki>
 
<pre><nowiki>
ffmpeg -i source-video.avi -s 480x320 -b 384k -vcodec h264 -flags +loop+mv4 -cmp 256 -partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -subq 7 -trellis 1 -refs 5 -bf 0 -flags2 +mixed_refs -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10 -qmax 51 -qdiff 4 -acodec aac -r 13 output-video.G1.mp4
+
ffmpeg -i source-video.avi -s 432x320 -b 384k -vcodec h264 -flags +loop+mv4 -cmp 256 -partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -subq 7 -trellis 1 -refs 5 -bf 0 -flags2 +mixed_refs -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10 -qmax 51 -qdiff 4 -acodec aac output-video.G1.mp4
 
</nowiki></pre>
 
</nowiki></pre>
For example of a typical American camcoder which records at 640x480 resolution with 30 frames per second rate, we will add the padding and change the rate (-r 15) as discussed in the previous sections:
+
Some versions of ffmpeg use older syntax, that is, -vcodec libx264 and -acodec libfaac.
 +
For example of a typical American camcoder which records at 640x480 resolution with 30 frames per second rate, we will resize image and change the rate (-r 15):
 
<pre><nowiki>
 
<pre><nowiki>
ffmpeg -i myparty.avi -s 426x320 -b 384k -vcodec h264 -flags +loop+mv4 -cmp 256 -partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -subq 7 -trellis 1 -refs 5 -bf 0 -flags2 +mixed_refs -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10 -qmax 51 -qdiff 4 -acodec aac -r 15 -padleft 28 -padright 26 myparty.G1.mp4
+
ffmpeg -i myparty.avi -s 432x320 -b 384k -vcodec h264 -flags +loop+mv4 -cmp 256 -partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -subq 7 -trellis 1 -refs 5 -bf 0 -flags2 +mixed_refs -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10 -qmax 51 -qdiff 4 -acodec aac -r 15 myparty.G1.mp4
 
</nowiki></pre>
 
</nowiki></pre>
 
While ffmpeg is running, you should see the following:
 
While ffmpeg is running, you should see the following:
 
<pre><nowiki>
 
<pre><nowiki>
 
Output #0, mp4, to 'myparty.G1.mp4':
 
Output #0, mp4, to 'myparty.G1.mp4':
   Stream #0.0: Video: h264, yuv420p, 480x320, q=10-51, 384 kb/s, 15.00 fps(c)
+
   Stream #0.0: Video: h264, yuv420p, 432x320, q=10-51, 384 kb/s, 15.00 fps(c)
 
   Stream #0.1: Audio: aac, 44100 Hz, stereo, 64 kb/s
 
   Stream #0.1: Audio: aac, 44100 Hz, stereo, 64 kb/s
 
</nowiki></pre>
 
</nowiki></pre>
This will tell you exactly what the output file will be in width and height, and for the G1 should '''always''' be '''480x320''' for optimum scaling. If it's anything other than 480 by 320, you WILL have stretching in the playback on the G1. May be minimal; may not even be noticeable, but it will be there.
+
== Expert mode: Using mencoder (command line) ==
=== GUI version (using WinFF) ===
+
=== Supported operations ===
Install WinFF using the following instructions [http://ubuntuforums.org/showthread.php?t=766683 (Reposted -- Updated instructions may be available)]
+
{|border="1" cellspacing="0"
==== Video Conversion ====
+
|Source||Support Matrix
For video conversion and editing capabilities, you will first need to add a new repository to your software sources, as it will enable you to install the very useful WinFF, which is a GUI front-end for the command-line video conversion tool, FFmpeg. The command I want you to copy and paste for adding the actual repository is intended for Ubuntu 8.10 Intrepid Ibex, so if you're using a different version of Ubuntu, you will need to edit the "intrepid" part accordingly, then move the cursor back to where it was before executing the edited command.
+
|-
Copy and paste the following command into the terminal to add the new WinFF repository (EXAMPLE FOR INTREPID, SUBSTITUTE WITH YOUR VERSION):
+
|Individual file||SUPPORTED
 +
|-
 +
|DVD||SUPPORTED
 +
|}
 +
=== Introduction ===
 +
These instructions are only applicable to encoding DVD tracks into G1 compatible video format. This is not a preferred method due to its complexity.  Please read a chapter about H.264 above in the FFmpeg description.
 +
=== Installation ===
 +
Upgrade to the latest version of software using the following PPA repositories: [https://launchpad.net/~rvm/+archive/mplayer |MPlayer and MEncoder] and [https://launchpad.net/~rvm/+archive/smplayer |SMPlayer (Optional) a very handy GUI front-end for MPlayer].
 +
Additionally, install gpac package from universe repository.
 +
=== Conversion ===
 +
The following command a track number 10 into an AVI file. As mentioned previously, the source has aspect ratio of 4:3, so we choose 432x320 as output most appropriate for G1 screen.
 
<pre><nowiki>
 
<pre><nowiki>
echo "deb http://winff.org/ubuntu intrepid universe" | sudo tee /etc/apt/sources.list.d/winff.list
+
mencoder dvd://10 -dvd-device /dev/dvd -aid 128 -o output.avi -ovc x264 -x264encopts bitrate=640:nocabac:direct_pred=auto:me=umh:frameref=2:level_idc=21:partitions=all:subq=6:threads=auto:trellis=1:vbv_maxrate=768:vbv_bufsize=244:bframes=0 -oac faac -faacopts br=96:mpeg=4:object=2 -channels 1 -srate 48000 -vf scale=432:320,harddup
 
</nowiki></pre>
 
</nowiki></pre>
This second command will merely install something called a GPG Key, so will not need editing by anyone:
+
'''Warning''': Currently, mencoder is not able to produce MP4 containers usable by mobiles players.  Do not use the following mencoder option: -of lavf -lavfopts format=mp4.
 +
After that, convert AVI to MP4 containers using [http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-quicktime-7.html these instructions].
 +
Alternatively, use MP4Box utility from gpac package which strictly complies to MPEG4 standard.
 
<pre><nowiki>
 
<pre><nowiki>
wget --quiet --output-document=- "http://winff.org/ubuntu/AAFE086A.gpg" | sudo apt-key add - && sudo apt-get update
+
MP4Box -aviraw video output.avi
 +
MP4Box -aviraw audio output.avi
 +
mv output_audio.raw output_audio.aac
 +
MP4Box -add output_video.h264 -add output_audio.aac output.mp4
 +
rm output.avi
 
</nowiki></pre>
 
</nowiki></pre>
Finally, execute the command below to install the applications needed for video conversion and editing:
+
Plug-in your phone via USB and copy output.mp4 to your Android mobile device.
<pre><nowiki>
+
sudo apt-get install avidemux ffmpeg winff
+
</nowiki></pre>
+
WinFF is probably the most user-friendly tool for converting videos and extracting audio from videos in GNU/Linux. Avidemux is a popular and useful video editing application, which makes it quite simple to cut and crop videos to your liking, and much more.
+
==== G1-specific Video Conversion Instructions ====
+
{{http://winff.org/images/screenshots/winff044-ubuntu-small.jpg}}
+
* Click on Options and verify that Additional Options are selected -- they will show up on the bottom of the screen
+
* Click on Add and select one or multiple movies that you want to convert.
+
* Select Convert to: Ipod
+
* Select Device Presets: H.264 for Ipod *Linux* (4:3) for standard resolution or H.264 for Ipod *Linux* (16:9) for wide resolution
+
* In the Additional Options below, choose Video Settings and type Video Size: 432 x 320 for standard resolution and 480 x 272 for wide resolution
+
* In Audio Settings: If you are planning to listen primarily with headphones, do nothing.  If you are planning to listen on the speakerphone, select Audio Channels: 1 to create mono sound.
+
* Click on Convert toolbar icon.
+
 
== Get help ==
 
== Get help ==
 
As always, Ubuntuforums is a great place to ask for help.  Please use the [http://ubuntuforums.org/forumdisplay.php?f=335 Multimedia Production] category.
 
As always, Ubuntuforums is a great place to ask for help.  Please use the [http://ubuntuforums.org/forumdisplay.php?f=335 Multimedia Production] category.
第91行: 第169行:
 
* http://androidcommunity.com/forums/showthread.php?p=88879#post88879 - Initial post that details the procedure.
 
* http://androidcommunity.com/forums/showthread.php?p=88879#post88879 - Initial post that details the procedure.
 
* http://h264.code-shop.com/trac/wiki/Encoding - Settings for H.264 codec.
 
* http://h264.code-shop.com/trac/wiki/Encoding - Settings for H.264 codec.
 +
* [http://www.pavtube.com/video_converter/ Video converter] is the easiest way to get your video in the format you want, convert video and audio to iPod, PSP, iPhone, Zune, Xbox.
 +
* Pavtube video converter supports to [http://www.pavtube.com/video_converter/ convert video] between different video formats.
 
=== Inspired by ===
 
=== Inspired by ===
 
* [[UbuntuHelp:iPodVideoEncoding|iPodVideoEncoding]]
 
* [[UbuntuHelp:iPodVideoEncoding|iPodVideoEncoding]]
 +
* Compare prices on [http://www.pavtube.com/video_to_ipod/ best ipod video converter] for deals on more Electronics products.
 
=== Additional information ===
 
=== Additional information ===
 
* [http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html FFmpeg documentation]
 
* [http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html FFmpeg documentation]
 
* [http://blogs.amd.com/patmoorhead/archive/2008/10/27/unlock-some-secret-of-the-android-g1-video-encode-decode.aspx Unlocking Some Secrets of the Android G1 Video Capabilities]
 
* [http://blogs.amd.com/patmoorhead/archive/2008/10/27/unlock-some-secret-of-the-android-g1-video-encode-decode.aspx Unlocking Some Secrets of the Android G1 Video Capabilities]
 
* [http://benlynn.blogspot.com/2009/01/encoding-videos-for-g1.html Encoding videos for G1]
 
* [http://benlynn.blogspot.com/2009/01/encoding-videos-for-g1.html Encoding videos for G1]
 +
* Powerful,versatile [http://www.pavtube.com/video_converter/ video file converter] which convert video file between all popular video formats.
 
* [http://forums.tmonews.com/index.php?topic=3261.0 Extensive discussion of sizing videos for G1].  Excel spreadsheet for calculations is attached.
 
* [http://forums.tmonews.com/index.php?topic=3261.0 Extensive discussion of sizing videos for G1].  Excel spreadsheet for calculations is attached.
 
----
 
----
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2010年5月19日 (三) 17:24的最新版本

Encoding Video for the Android Phone, for example, HTC/Google G1

HTC/Google G1 phone can decode mpeg4, h263 and h264 codecs and can play mp4 and 3gp video formats. Since these format combinations are relatively uncommon, here are instructions to convert your videos to the compatible format. If your source is a DVD, skip to [[UbuntuHelp:[Using HandBrake (GUI)|HandBrake section]]]

Using Avidemux (GUI)

Supported operations

Source Support Matrix Workaround
Individual file SUPPORTED
DVD NOT SUPPORTED DVD::Rip

Instructions

This method has been tested in Ubuntu 9.04, adapted from this article. It will produce a movie encoded with mpeg4 codec, fast but not optimal.

  1. Install the avidemux package from the Ubuntu multiverse repository
  2. Configure video options:
    1. Click on the video dropdown on the left and select MPEG-4 ASP (lavc)
    2. Click Configure->Encoding Mode->Single Pass - Bitrate
    3. Enter in any bitrate up to 512 to be safe, then click Ok.
    4. Click Filters->MPlayer Resize->Double Click on it-> Width:432, Height:320 if source video is standard resolution.
      1. For widescreen source, choose Width:480, Height:272.
      2. Click Ok, then close.
  3. Configure audio options:
    1. Click Audio->AAC (FAAC)
    2. Configure->Bitrate 96
    3. Click Format->MP4
  4. Click Save and specify a name.mp4 for your video, encoding will start
  5. Once enconding has completed, plug in your phone via USB and transfer the video to it, anywhere. The videos can be opened directly using a file manager such as Astro.

Using WinFF (GUI)

This method will achieve superior compression using a newer video codec and higher level of control. 模板:Http://winff.org/images/screenshots/winff044-ubuntu-small.jpg

Supported operations

Source Support Matrix Workaround
Individual file SUPPORTED
DVD NOT SUPPORTED DVD::Rip

Install WinFF on Ubuntu 9.04 or later using by clicking on the following link: apt:winff. For older version of Ubuntu, please click on the link for the instructions: Instructions for WinFF installation

Instructions

  • Click on Options and verify that Additional Options are selected -- they will show up on the bottom of the screen
  • Click on Add and select one or multiple movies that you want to convert.
  • Select Convert to: Ipod
  • Select Device Presets: H.264 for Ipod *Linux* (4:3) for standard resolution or H.264 for Ipod *Linux* (16:9) for wide resolution
  • In the Additional Options below, choose Video Settings and type Video Size: 432 x 320 for standard resolution and 480 x 272 for wide resolution
  • In Audio Settings: If you are planning to listen primarily with headphones, do nothing. If you are planning to listen on the speakerphone, select Audio Channels: 1 to create mono sound.
  • Click on Convert toolbar icon.

Using HandBrake (GUI)

模板:Http://trac.handbrake.fr/raw-attachment/wiki/LinGuiScreenshots/HandBrake-Pic.jpeg

Supported operations

Source Support Matrix
Individual file SUPPORTED
DVD SUPPORTED

Installation

Summary of instructions from [1]. Ubuntu 9.10 karmic and later: add ppa:handbrake-ubuntu/ppa to your system's Software Sources. Ubuntu 9.04 and earlier: Copy and paste the following command into the terminal to add the new WinFF repository (example for JAUNTY, SUBSTITUTE WITH YOUR VERSION):

echo "For 9.04 and earlier versions only!"
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com A58BCAE3
echo "deb http://ppa.launchpad.net/handbrake-ubuntu/ppa/ubuntu jaunty main" | sudo tee /etc/apt/sources.list.d/handbrake.list
sudo apt-get update && sudo apt-get install handbrake-gtk

G1-specific Video Conversion Instructions

  1. When encoding a DVD, select File, "/dev/dvd". Name might be different.
  2. When encoding a file, click on Source and select a desired source file.
  3. Click on Preset: Apple -> iPhone & iPod Touch
  4. Click on Video tab. In Quality, reduce quality to 49 and uncheck Constant Rate Factor
  5. Click on Start.
  6. Once encoding has completed, plug in your phone via USB and transfer the video to it, anywhere. The videos can be opened directly using a file manager such as Astro.

Preset File for Import

Tested on HTC Hero: To import, choose "options" at the bottom right of the window, then import. attachment:Android_Tested_on_Hero.plist

Expert mode: Using ffmpeg (command line)

Supported operations

Source Support Matrix
Individual file SUPPORTED
DVD NOT SUPPORTED

Introduction

This method will give you the greatest control of the resulting output. For most versions of Ubuntu, ffmpeg in Medibuntu contains this "unlocked" ffmpeg. Enable Medibuntu with the instructions here.

MPEG4 (standard) encoding

The default encoding of the videos is MPEG-4 ASP (i.e. "xvid") format video using ffmpeg's mpeg4 encoder. If you are interested in higher quality encodings, which will take quite a bit more time but may result in better quality, see H.264 section below. To convert a file source-video.avi to a desired G1 format, run the following command:

ffmpeg -i source-video.avi -s 480x320 -vcodec mpeg4 -acodec aac -ac 1 -ar 16000 -r 13 -ab 32000 -aspect 3:2 output-video.G1.mp4

This is VERY basic. For full options, go to FFmpeg Documentation

  • -s is "size" of output video.
  • -vcodec Choices for G1 are mpeg4 and h263. IMHO I get better quality and marginally smaller file size with mpeg4.
  • -acodec aac is the audio codec. I know of no other choice here for this purpose.
  • Older versions of ffmpeg called this option -acodec libfaac.
  • -ac 1 Number of audio channels. Use 1 to save filesize since you only have one speaker. Unless you like wearing those painful earbuds all the time. Then use -ac 2.
  • -ar 16000 Audio sampling rate in Hertz. Some formats won't work with anything other than 8kHz. 16 kHz seems okay to me, considering what I'm watching it on. Don't expect !HiFi from a phone.
  • -r 13 Frames per second. Larger is smoother, but 30 fps requires double the file size of 15 fps. 12 is about the slowest my eyes can comfortably watch. Since DVDs are right at 25 FPS, 12.5 being half of this, I go with 13. My camera makes 30 FPS; in that case, use -r 15.
  • -ab 32000 bitrate of the audio -- 32 kbps in this case. Normally I'd balk at such low numbers, but remember, I'm trying to keep filesize low. I'm not broadcasting to a large audience with this, am I? No, it's for me. For you? Use your best judgement. Experiment a little.
  • -aspect 3:2 Obviously, this is the aspect ratio of the output file. I'm not sure it matters, when the output size is being set before.

While ffmpeg is running, you should see the following:

Output #0, mp4, to 'terminal.G1.mp4':
   Stream #0.0: Video: mpeg4, yuv420p, 480x320 [PAR 1:1 DAR 3:2], q=2-31, 200 kb/s, 13.00 tb(c)
   Stream #0.1: Audio: aac, 16000 Hz, mono, s16, 32 kb/s

Very old versions of Android Video Player incorrectly scaled video, that is, if the video size was anything but 480 by 320, you would see stretching in the playback on the G1. It is no longer a problem.

H.264 Encoding

H.264 (MPEG-4 AVC) is a newer codec that the G1 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 with x264 support. Due to the G1's limited feature support for H.264, the command for doing the encode is that much more complex. If you are interested in technical details, G1 supports only the Constrained Baseline Profile (CBP) dialect of H.264; videos that use more advanced features of H.264 play incorrectly, or not at all. In case of incorrect video encoding, the most typical error is a black screen during playback on G1 while the audio plays. Note that since we are striving for better quality, the audio encoding is also set to higher standards. Assuming source movie has aspect ratio 4:3, the command is:

ffmpeg -i source-video.avi -s 432x320 -b 384k -vcodec h264 -flags +loop+mv4 -cmp 256 -partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -subq 7 -trellis 1 -refs 5 -bf 0 -flags2 +mixed_refs -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10 -qmax 51 -qdiff 4 -acodec aac output-video.G1.mp4

Some versions of ffmpeg use older syntax, that is, -vcodec libx264 and -acodec libfaac. For example of a typical American camcoder which records at 640x480 resolution with 30 frames per second rate, we will resize image and change the rate (-r 15):

ffmpeg -i myparty.avi -s 432x320 -b 384k -vcodec h264 -flags +loop+mv4 -cmp 256 -partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -subq 7 -trellis 1 -refs 5 -bf 0 -flags2 +mixed_refs -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10 -qmax 51 -qdiff 4 -acodec aac -r 15  myparty.G1.mp4

While ffmpeg is running, you should see the following:

Output #0, mp4, to 'myparty.G1.mp4':
  Stream #0.0: Video: h264, yuv420p, 432x320, q=10-51, 384 kb/s, 15.00 fps(c)
  Stream #0.1: Audio: aac, 44100 Hz, stereo, 64 kb/s

Expert mode: Using mencoder (command line)

Supported operations

Source Support Matrix
Individual file SUPPORTED
DVD SUPPORTED

Introduction

These instructions are only applicable to encoding DVD tracks into G1 compatible video format. This is not a preferred method due to its complexity. Please read a chapter about H.264 above in the FFmpeg description.

Installation

Upgrade to the latest version of software using the following PPA repositories: |MPlayer and MEncoder and |SMPlayer (Optional) a very handy GUI front-end for MPlayer. Additionally, install gpac package from universe repository.

Conversion

The following command a track number 10 into an AVI file. As mentioned previously, the source has aspect ratio of 4:3, so we choose 432x320 as output most appropriate for G1 screen.

mencoder dvd://10 -dvd-device /dev/dvd -aid 128 -o output.avi -ovc x264 -x264encopts bitrate=640:nocabac:direct_pred=auto:me=umh:frameref=2:level_idc=21:partitions=all:subq=6:threads=auto:trellis=1:vbv_maxrate=768:vbv_bufsize=244:bframes=0 -oac faac -faacopts br=96:mpeg=4:object=2 -channels 1 -srate 48000 -vf scale=432:320,harddup

Warning: Currently, mencoder is not able to produce MP4 containers usable by mobiles players. Do not use the following mencoder option: -of lavf -lavfopts format=mp4. After that, convert AVI to MP4 containers using these instructions. Alternatively, use MP4Box utility from gpac package which strictly complies to MPEG4 standard.

MP4Box -aviraw video output.avi 
MP4Box -aviraw audio output.avi
mv output_audio.raw output_audio.aac
MP4Box -add output_video.h264 -add output_audio.aac output.mp4
rm output.avi

Plug-in your phone via USB and copy output.mp4 to your Android mobile device.

Get help

As always, Ubuntuforums is a great place to ask for help. Please use the Multimedia Production category.

Primary source

Inspired by

Additional information