Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Mobile
User Name
Linux - Mobile This forum is for the discussion of all topics relating to Mobile Linux. This includes Android, Tizen, Firefox OS, Sailfish OS, Maemo, MeeGo, Ubuntu Mobile, WebOS, Open Mobile Alliance and other similar projects and products.
A reminder that LQ now has a dedicated Android sister site:


  Search this Thread
Old 11-29-2008, 07:05 PM   #1
CJ Chitwood
Registered: Dec 2006
Location: Northern Half of Florida
Distribution: PCLinuxOS at home, openSuSE and Fedora23 at work. Antibuntu all the way.
Posts: 143

Rep: Reputation: 28
Android/G1 and video converted via ffmpeg / h263

Hello to the group...

I have an Android G1 on which I'd like to play video. Perhaps the bug I'm seeing is a result of Android's decoder, but I wanted to run this by here first.

I have a video that's in widescreen format. I don't know exactly which widescreen, but it ain't 4x3 and that's the point. The G1 screen is 480 by 320 in landscape, so I use a CIF resolution of 352 by 288 because it's the largest standard resolution that will fit inside the confines of the screen.

When I transcode the video from the AVI container into 3gp or mpeg-4, the phone stretches the video top to bottom and no matter what I do everything looks taller and thinner than it should.

It seems that no matter what I do in the ffmpeg command line, I get the same result. Even if I tell ffmpeg to do a specific aspect ratio, or to do a specific pad-size top-and-bottom, no matter what, it comes out 4x3 with stretched vertically.

My command line:
$ ffmpeg -i ./infile.avi -s cif -vcodec mpeg4 -acodec libfaac -ac 1 -ar 8000 -r 25 -ab 32000 -aspect 16:9 -padtop 0 -padbottom 0 -aic -umv -y ./outfile.mp4
I've tried it in various sizes (cif and qvga specifically, as well as manually-entered WxH), and I've tried setting specific aspect ratios (4:3 and 16:9 both) and with padding of 0, 16 top and bottom, and 50 top and bottom. I've tried it with and without the -aic and -umv (not knowing if it would make any difference). In every case, I get -- even with the letterbox padding -- stretched video.

In mplayer before copying the file to the phone, it looks normal, and regardless of which of the 4 or 5 video players I have on the phone, the video plays stretched the same way. So I'm thinking it's a result of the codec on the phone, but does anyone know of a way around this in the transcode process?

FWIW, when I run ffmpeg with no args so you can see the config I used (btw, compiled from source including non-free AMR codecs):

$ ffmpeg
FFmpeg version SVN-r15955, Copyright (c) 2000-2008 Fabrice Bellard, et al.
  configuration: --enable-gpl --enable-libamr_nb --enable-libamr_wb --enable-libmp3lame --enable-libvorbis --enable-libfaac --enable-libfaad --enable-nonfree --enable-decoder=h263 --enable-encoder=h263
  libavutil     49.12. 0 / 49.12. 0
  libavcodec    52. 4. 0 / 52. 4. 0
  libavformat   52.23. 1 / 52.23. 1
  libavdevice   52. 1. 0 / 52. 1. 0
  built on Nov 29 2008 11:42:06, gcc: 4.3.1
At least one output file must be specified


Many thanks in Advance!
Old 11-29-2008, 08:30 PM   #2
CJ Chitwood
Registered: Dec 2006
Location: Northern Half of Florida
Distribution: PCLinuxOS at home, openSuSE and Fedora23 at work. Antibuntu all the way.
Posts: 143

Original Poster
Rep: Reputation: 28

When I add a 50 px pad to the top AND bottom, there is now a letterbox style black bars top and bottom (this IS what I want) however, the player (all of them) scales the ENTIRE video down to fit the same 4:3 video *inside* the black bars, which of course makes the entire video no longer go full width. I notice now, too, that mplayer plays this video the same way as my phone now. I'm going to try now with bars AND setting the AR to 16:9 and some other settings, and I'll be paying much closer attention to them this time.


using 50 px top and bottom and setting aspect 4:3 makes mplayer play it about right, but the phone has the 4:3 inside the letterbox with side bars too, just like the 50px with no AR setting... Next is 50px with 16:9...


using 50 px top and bottom and setting aspect 16:9 makes the entire thing -- including the letterbox -- fit inside a 16:9 ratio, and therefore the actual video portion is now stretched too long left-right in mplayer but is played in the phone the same as the last two... so it really appears to be a phone codec issue. Next I'll do some math... the phone's screen at 480 by 320 is a 3:2 ratio rather than a 16:9 or 4:3. I'll see if there's not some algebraic trickery involved...

Last edited by CJ Chitwood; 11-29-2008 at 08:41 PM.
Old 11-30-2008, 04:52 PM   #3
CJ Chitwood
Registered: Dec 2006
Location: Northern Half of Florida
Distribution: PCLinuxOS at home, openSuSE and Fedora23 at work. Antibuntu all the way.
Posts: 143

Original Poster
Rep: Reputation: 28
SOLVED - HOWTO - avi video encoded for G1


The following is a post I made at regarding this subject. I figured out what I needed to know.

Originally from

For those of us using Linux:

Download the source code for ffmpeg and the amr_wb and amr_nb libraries (from what I could tell, the amr provide h263, which is all the G1 can decode). You'll have to google these last two -- it's how I found them, and they weren't exactly hiding, but they're not "free" as in speech like most Linux software, so they can't be redistributed. You will also want libmp3lame if you don't already have it, as well as libfaac0 and libfaad0.

When compiling ffmpeg, use the following command for the configuration:

./configure  --enable-gpl --enable-libamr_nb --enable-libamr_wb --enable-libmp3lame --enable-libvorbis --enable-libfaac --enable-libfaad --enable-nonfree --enable-decoder=h263 --enable-encoder=h263

You may wish to have "checkinstall" installed. It provides an easy method of removing programs that were compiled from source (saves you from having to have the source around to run "make uninstall", which doesn't always work anyway).

After ffmpeg is installed, with all the above-mentioned libraries, the command is straightforward.

 ffmpeg -i source-video.avi -s 480x320 -vcodec mpeg4 -acodec libfaac -ac 1 -ar 16000 -r 13 -ab 32000 -aspect 3:2 output-video.G1.mp4
This is VERY basic. For full options, go to

-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.
-vcodec Choices for G1 are mpeg4 and h263. IMHO I get better quality and marginally smaller file size with mpeg4.
-acodec libfaac is the audio codec. I know of no other choice here for this purpose.
-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.
-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.

There are a few more options you'll need to know, but you have to do the math. Just like with the Windows side, your 16:9 or 4:3 isn't going to fit without stretching unless you pad it out.

-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 [/drool] 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.

$ ffmpeg -i terminal.avi -s 480x256 -vcodec mpeg4 -acodec libfaac -ac 1 -ar 16000 -r 13 -ab 32000 -aspect 3:2 -padtop 32 -padbottom 32 terminal.G1.mp4

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? 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.

So, -s is the output size BEFORE applying crop and pad arguments.

I think I get it....

Addendum: While ffmpeg is running, you should see the following:

Output #0, mp4, to 'Braveheart.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: libfaac, 16000 Hz, mono, s16, 32 kb/s
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.

Hope it helps somebody...

Last edited by CJ Chitwood; 11-30-2008 at 04:53 PM.
1 members found this post helpful.
Old 08-17-2010, 06:41 PM   #4
LQ Newbie
Registered: Aug 2010
Posts: 4

Rep: Reputation: 0
thanks man


android, convert, ffmpeg, g1, mp4, mpeg4, transcode, video

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tovid .30 ffmpeg video = arse? athens101 Linux - Desktop 1 02-16-2007 02:05 PM
Error writing converted video file to dvd d00bid00b Linux - General 2 11-27-2006 01:20 AM
splitting video files with ffmpeg triXlife Linux - Software 0 12-27-2005 07:29 PM
i want to sync my video using ffmpeg Jeon, Chang-Min Linux - Software 0 11-17-2005 03:04 PM
H263 Compression maldini1010 Linux - Software 0 01-12-2005 04:38 PM > Forums > Linux Forums > Linux - Mobile

All times are GMT -5. The time now is 03:44 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration