Wide Screen video encoding for qcif

Well, many of you are probably wondering how to convert a non 4:3 type of video into qcif (176×144) and keep the aspect ratio of the video. This is a bit tricky and isn’t an exact science due to the nature mpeg. Most mobile phones can handle qcif resolution but anything smaller or bigger could cause issues and since we are trying to support as many handsets as possible here is my proposed solution.

First you figure out what resolution your current video is as. So im going to use the super man trailer I have been testing with as an example which is at 1280×544, which is in some sort of wide screen video format.

Step one is to divide the width of the source with the width of qcif.

1280/176 = 7.27 ...

Next divide the result from step one by the height of the original video which is 544.

btw I rounded up to 7.3

544/7.3 = 74.5...

So giving these 2 calculations we now have the new height of the video based upon a qcif resolution.

176 x 75 (I rounded up)

Here is where the issue lies if you encode your video with ffmpeg at that resolution your breaking qcif compliance which most phones require so your going to immediately break playback on most phones.

So what you do is use the padtop and padbottom options in ffmpeg to add black bars to your video but be carefull as you will see in our example they needs to be multiples of 2.

(144-75)/2 = 34.5

So since 34.5 isn’t valid pad value for ffmpeg you have to fudge your numbers a bit.

(144-76)/2 = 34

Which now gives you a valid number thats divisible by two.

So your end result when encoding this video would be

ffmpeg -i yourvideo.avi -f 3gp -vcodec h263p -r 7.4925 -s 176x76 -padtop 34 -padbottom 34 -acodec amr_nb -ac 1 -ar 8000 -ab 12 -b 32k output.3gp

you will notice a few things right off the bat, you cannot use -vcodec h263 since it wont let u encode anything non qcif resolution -vcodec mpeg4 doesn’t have this limitation but you need to encode for h263 this is what you use. Pad top and bottom add the black bars to the video how ever your not done because this video will not -hint with MP4Box and it will actually remove the video stream if you try it.

MP4Box -hint -3gp output.3gp
Converting to 3GP file...
[3GPP convert] Video format not supported by 3GP - removing track ID 1
[3GPP convert] Setting major brand to 3GPP V5 file
Hinting file with Path-MTU 1450 Bytes
Hinting track ID 2 - Type “samr:samr” (AMR) - BW 13 kbps
Saving output.3gp: 0.500 secs Interleaving

What you need to do then is re-encode that video that was just created again with the proper qcif format. I know this sucks and re-encoding a video again looses some quality but currently this is the only solution I found for h263, so far my tests for mpeg4 and h264 don’t require this additional re-encoding.

You can see the result if your point your phone over to http://mvstreaming.mobi

So given this formula will help you keep the proper aspects of wide screen videos, it may look a lot smaller on the mobile phone screen and you may not care and just encode it all to 176×144 wide screen or not.

On another note, if anyone builds a php, or perl script that can do this calculation I would be interested in looking at it.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Netvouz
  • description
  • ThisNext
  • MisterWong
  • Wists
  • Netscape
  • NewsVine
  • Reddit
  • Slashdot
  • StumbleUpon
  • Taggly

Leave a Reply

You must be logged in to post a comment.