FYI easy high quality video encoding for android

41 views
Skip to first unread message

lbcoder

unread,
Jan 29, 2009, 12:03:50 AM1/29/09
to Android Discuss
The script below, though primitive, demonstrates use of mencoder (free
open source) for encoding high quality videos with compatibility with
existing android hardware.

Hopefully this will help anyone having troubles encoding....


#!/bin/bash

# filename=andvidenc

#USAGE:
# andvidenc low "input.video"
# andvidenc high "input.video"
#
# --output: "input.video.mp4"
#
# Note 1: if input video is INTERLACED, add "kerndeint" to -vf,
# i.e. ... -vf kerndeint,dsize....
#
# Note 2: if 2-pass encoding is not desired, comment out the FIRST
mencoder line
# from each case and remove "-passlogfile "$2.log"" and ":pass=2" from
remaining
# mencoder lines.
#
# Note 3: for testing purposes, I have verified that HTC dream is able
to play high
# bitrate files without trouble. Tested with bitrate up to 1024.
Visual difference
# between 512 and 1024 is minimal. Up to you to choose a bitrate that
balances
# quality with size.

# yes, this script is really stupid and has a lot of room for
enhancement. Feel free
# to improve it.

#EITHER:

if [ $1 = "low" ]; then
mencoder "$2" -o "$2.tmp.mp4" -vf dsize=480:352:2,scale=-8:-8,harddup
-oac faac -faacopts mpeg=4:object=2:raw:br=128 -of lavf -lavfopts
format=mp4 -ovc x264 -passlogfile "$2.log" -x264encopts
nocabac:level_idc=30:bframes=0:bitrate=512:threads=auto:turbo=1:pass=1
mencoder "$2" -o "$2.tmp.mp4" -vf dsize=480:352:2,scale=-8:-8,harddup
-oac faac -faacopts mpeg=4:object=2:raw:br=128 -of lavf -lavfopts
format=mp4 -ovc x264 -passlogfile "$2.log" -x264encopts
nocabac:level_idc=30:bframes=0:bitrate=512:threads=auto:pass=2


#OR:

else
mencoder "$2" -o "$2.tmp.mp4" -vf dsize=480:352:2,scale=-8:-8,harddup
-oac faac -faacopts mpeg=4:object=2:raw:br=128 -of lavf -lavfopts
format=mp4 -ovc x264 -passlogfile "$2.log" -sws 9 -x264encopts
nocabac:level_idc=30:bframes=0:bitrate=512:threads=auto:turbo=1:pass=1:global_header:threads=auto:subq=5:frameref=6:partitions=all:trellis=1:chroma_me:me=umh
mencoder "$2" -o "$2.tmp.mp4" -vf dsize=480:352:2,scale=-8:-8,harddup
-oac faac -faacopts mpeg=4:object=2:raw:br=128 -of lavf -lavfopts
format=mp4 -ovc x264 -passlogfile "$2.log" -sws 9 -x264encopts
nocabac:level_idc=30:bframes=0:bitrate=512:threads=auto:pass=2:global_header:subq=5:frameref=6:partitions=all:trellis=1:chroma_me:me=umh
fi

#THEN:

ffmpeg -i "$2.tmp.mp4" -vcodec copy -acodec copy "$2.mp4"
rm -f "$2.tmp.mp4" "$2.log"

Eric

unread,
Jan 29, 2009, 5:14:03 PM1/29/09
to Android Discuss
Hi,

You mean you can use memcoder within Android? to transcode and
playback the video in real time?
(sorry, I am not a programmer.....)

Thanks
Eric
Portable Electronics Ltd
www.hdmp4.com

LB Coder

unread,
Jan 30, 2009, 3:10:26 PM1/30/09
to android...@googlegroups.com
I mean exactly what I said. Not something different.

Eric Wong (hdmp4.com)

unread,
Jan 30, 2009, 6:39:43 PM1/30/09
to Android Discuss
mm, in that case. There are also other video conversion software that
one can use.....

Memcoder is just one of them then.......

Cheers
Eric

On Jan 31, 7:10 am, LB Coder <lbco...@gmail.com> wrote:
> I mean exactly what I said. Not something different.
>

LB Coder

unread,
Feb 2, 2009, 12:35:35 AM2/2/09
to android...@googlegroups.com
Anyone who understands this will understand that this is not *just some other* video conversion software - the vast majority will either be incapable of generating files that will actually play, will be incapable of generating a file of decent quality (i.e. pixelated or blocky, lack of A/V sync, very large file sizes), will be downright impossible to use, or will charge your left testicle for licensing. The remaining (very few) options will require a graphical interface, and as such, will be very cumbersome to use.

If you don't understand or are not interested, please keep out of this thread.



Oh, and BTW: the first time you screwed it up I figured it was just a typo, but by repeating "memcoder", you sound like one of those "FIRST" comment posters from the market. Its "MENCODER", as in "M(edia)ENCODER".

Muthu Ramadoss

unread,
Feb 2, 2009, 2:44:51 AM2/2/09
to android...@googlegroups.com
>> will be downright impossible to use, or will charge your left testicle for licensing.

Rats! Hope Android licensing do not involve any such terms. GAA.. Never thought programming involved such risks when I happily signed up for programming classes ;)

take care,
Muthu Ramadoss.

http://linkedin.com/in/tellibitz +91-9840348914
http://androidrocks.in - Android Consulting.

Jiri Tyr

unread,
Feb 9, 2009, 12:31:59 PM2/9/09
to Android Discuss
It works great for me! Thank you for this script!

Cheers,
Jiri
Reply all
Reply to author
Forward
0 new messages