Author Topic: Encoding Videos For Zaurus  (Read 15115 times)

vrejakti

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • http://www.animecharactersdatabase.com
Encoding Videos For Zaurus
« on: July 11, 2006, 12:56:28 am »
It's been a while since I posted my first encoding video for the Zaurus script, so here's an updated Version 2 of it. Enjoy.

Code: [Select]
#!/bin/sh
# Declare some variables
INFILE=$1
OUTFILE=$2
WIDTH=640
HEIGHT=480

# Check for input video.
if [ -z "$1" ]
then echo "#########################"
echo "# ERROR! NO INPUT FILE. #"
echo "#########################"
echo
echo "Usage"
echo --------------------
echo "$0 INPUT OUTPUT width_option height_option"
echo
echo "Example"
echo --------------------
echo "$0 Funny_Clip.avi Funny_Clip_Resized.avi 320 240"
exit
fi

# Check for output file name.
if [ -z "$2" ]
then echo "##########################"
echo "# ERROR! NO OUTPUT FILE. #"
echo "##########################"
echo
echo "Usage"
echo --------------------
echo "$0 INPUT OUTPUT width height"
echo
echo "Example"
echo --------------------
echo "$0 Funny_Clip.avi Funny_Clip_Resized.avi 320 240"
exit
fi

# Change to custom height and width
if [ -n "$3" ]
then WIDTH=$3
fi

if [ -n "$4" ]
then HEIGHT=$4
fi

# Print some information
echo Video Encoding for Sharp Zaurus Playback
echo By Vrejakti
echo http://www.lan358.com
echo
echo
echo "Default 640x480"
echo "Full screen [4:3]  use 640x480 [default]."
echo "Wide screen [16:9] use 640x360."
echo --------------------
echo "   Input: $1"
echo "  Output: $2"
echo "   Width: $WIDTH"
echo "  Height: $HEIGHT"
echo --------------------

# Check responce
echo "Is this correct? [Yes/No] "
read answer
# VERY USEFUL CODE: This accepts "Yes", "yes", "Y", and "y".
if [ $answer == "Yes" ] || [ $answer == "yes" ] || [ $answer == "Y" ] || [ $answer == "y" ]
then
# Start mencoder magic
mencoder "$INFILE" -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=300:vpass=1 -lameopts cbr:br=64:mode=3 -vf scale=$WIDTH:$HEIGHT -oac mp3lame -o $OUTFILE
mencoder "$INFILE" -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=300:vpass=2 -lameopts cbr:br=64:mode=3 -vf scale=$WIDTH:$HEIGHT -oac mp3lame -o $OUTFILE
echo "Converted file is $OUTFILE"

else echo "Encoding canceled!!!"
fi

Please post any suggestions for improvements. I'm still learning how to write bash scripts, so there's bound to be room for improvement.  Version 3 will allow for encoding multiple files.

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

Edit notes: *shudder* The above is version 2, that is more of a proof of concept. I'm posting version 4.0 below for a side by side comparison.  Many new features have been added in version 4.0 as well as a great number of simplifications.

i) Script is easier to run. Install it as vrecoder to /usr/local/bin then run `vrecoder -i AVI_File'
ii) All options have been added as switches. See `vrecoder -h' for the details.
iii) The `-a' switch attempts to resize your video keeping the correct aspect ratio.
iv) `-s' uses an experimental smartcoder that will encode every AVI file in the current directory.



Code: [Select]
#!/bin/bash

# Encoding Video for Zaurus Playback
# Script version 4.5
# Attributions:
# Vrejakti   LAN358 Inc, http://lan358.com: Head Developer
# XorA       Open Zaurus Project: Produced original mpencoder code
# Da_Blitz   OESF Forums:  additional mencoder code, and shell code
# Xamindar   OESF Forums:  feature suggestions

MAX_WIDTH="640"    # Default max width
WIDTH="640"        # Default width
HEIGHT="480"       # Default height
encoder="vrecoder" # Default encoder
BITRATE="600"      # Default quality / bit rate
CODEC="mpeg4"      # Default codec

help () {
cat << EOF
vrecoder: Video Encoding for Sharp Zaurus Playback

Usage: vrecoder [-h] [-a] [-s] [-i infile] [-o outfile]
  [-x size] [-y size] [-b bitrate]

-h,  Display this help menu
-a,  Auto calculate resized video resolution
-s,  Use smartcoder
-i,  Input File
-o,  Output File
-x,  Change width
-b,  Change bitrate. 300 default, 6000 would be smooth
-y,  Change height
--quick  No confirms, jump to encoding.

:: Encoders ::
vrecoder:   Default encoder. Works on a signle input file.
smartcoder: Experimental encoder. Atempts to encode every AVI file in the
            current directory.
:: Notes ::
[-a] depends on awk >= 3.1.5, file >= 4.3.0, grep >= 2.5.1.
     Use at your own risk.
[-s] depends on file >= 4.18, find >= 4.3.0.
     Use at your own risk.

EOF
exit
}

if [ -z "$1" -o "$1" = "-h" ]
then
help
fi

for ARG in $@; do
    case $ARG in
  -x) WIDTH="$2";    shift;;
  -y) HEIGHT="$2";      shift;;  
  -i) IN="$2";    shift;;
  -o) OUT="$2";    shift;;
  -a) autores="yes";      shift;;
  -b) BITRATE="$2";      shift;;
  -s) encoder="smartcoder";  shift;;
  --quick) rush="x";      shift;;
  *) shift;;
    esac
done

if [ "$encoder" == "vrecoder" ]
then
if [ -z "$IN" ]
then
printf "Whoops! No input found.
Did you forget to input a file with -i file.avi?\n"
exit
fi
fi

if [ -z "$OUT" ]
then
OUT="Zaurus-"$IN""
# /*
# * Why is this switch true when -i is a complex file name?
#  */
fi

if [[ "$encoder" == "smartcoder" ]]
then
rush="x"
fi

if [[ "$rush" == "x" ]]
then
answer="yes"
else

#####calculate res#############################
case "$autores" in
    "Yes" | "yes" | "Y" | "y" )
# /*
#  * Anyone have a suggestion
#  * how to better impliment this function?
#  */
    printf "Enter screen width (ie. 640): "
    read MAX_WIDTH
    height=`file $IN | awk -F, '{print $3}' | awk -F" " '{print $1}'`
    width=`file $IN | awk -F, '{print $3}' | awk -F" " '{print $3}'`
    first="$[$width*100/$height]"     # fake float
    second="$[$MAX_WIDTH*$first/100]" # restore int
    WIDTH="$MAX_WIDTH"
    HEIGHT="$second"
;;
esac
###############################################

echo
echo "Please confirm:"
echo "------------------------------"
echo "       Input: $IN"
echo "      Output: $OUT"
echo "       Width: $WIDTH"
echo "      Height: $HEIGHT"
echo "     Encoder: $encoder"
echo "     Bitrate: $BITRATE"
echo "------------------------------"

printf "Start encoding?
[Yes/No] "
read answer
fi

####functions##################################
function vrecoder ()
{
    mencoder "$IN" -ovc lavc -lavcopts vcodec=$CODEC:\
    vbitrate=$BITRATE:vpass=1 -vf scale=$WIDTH:$HEIGHT -oac copy -o "$OUT"
#--------------------
    mencoder "$IN" -ovc lavc -lavcopts vcodec=$CODEC:\
    vbitrate=$BITRATE:vpass=2 -vf scale=$WIDTH:$HEIGHT -oac copy -o "$OUT"
}

function smartcoder ()
{
    i=1
    while read "F"
    do
    T=$(file -zibkp "$F")
    if [[ $T == 'video/x-msvideo' ]]
    then
    OUT="Zaurus-"$F""
#    mencoder "$F" -ovc lavc -lavcopts vcodec=$CODEC:vbitrate=\
#    $BITRATE:vpass=1 -vf scale=$WIDTH:$HEIGHT -oac copy -o "Output_"$F""
#    mencoder "$F" -ovc lavc -lavcopts vcodec=$CODEC:vbitrate=\
#    $BITRATE:vpass=2 -vf scale=$WIDTH:$HEIGHT -oac copy -o "Output_"$F""
    mencoder "$F" -ovc lavc -lavcopts vcodec=$CODEC:\
    vbitrate=$BITRATE:vpass=1 -vf scale=$WIDTH:$HEIGHT -oac copy -o "$OUT"
    #--------------------
    mencoder "$F" -ovc lavc -lavcopts vcodec=$CODEC:\
    vbitrate=$BITRATE:vpass=2 -vf scale=$WIDTH:$HEIGHT -oac copy -o "$OUT"
# /*
# * Can someone please tell me the difference between the commented lines
# * and the uncommented lines?
#  */

    i=$[$i+1]
    fi
    done < <(find -maxdepth 1 -printf "%f\n")
}
####/functions#################################


####main#######################################
case "$answer" in
    "Yes" | "yes" | "Y" | "y" )
  $encoder
  printf "\nEncoding completed at `date`\n"
    exit;;

    "op" )
  printf "Minutes: [hh:mm:ss] "
  read minutes
  mencoder "$IN" -ovc lavc -lavcopts vcodec=$CODEC:vbitrate=\
  $BITRATE -vf scale=$WIDTH:$HEIGHT -oac copy -endpos \
  $minutes -o "$OUT"
    exit;;

esac
###############################################

printf "\nEncoding has been cancled.\n"


Todo:
Fix script so everything will work on complex file names as well as normal file names.
Have script work on each file on the command line, not just the one file included with the `-i' switch.
Replace experimental code with real portable code.
Rewrite the entire script in x86 ASM using mencoder shared libraries. (Yeah right. ;-) )
« Last Edit: December 28, 2006, 08:13:54 pm by vrejakti »

Da_Blitz

  • Hero Member
  • *****
  • Posts: 1579
    • View Profile
    • http://www.pocketnix.org
Encoding Videos For Zaurus
« Reply #1 on: July 11, 2006, 04:31:23 am »
have you tried making moives with org vorbis, i am thinking that it might be worth trying out the integer decoding on the Z and see how it compares to libmad

i havent been into the video encoding scene in awhile but i belive that some of the other formats may be more Z friendly. i hear one of the design goals of mkv was fast seeking

just some sugestions. i dont have the time to fiddle with video encoding at the moment and i dont watch videos on my Z but i wonder if we can get some more performance out of these little things by changing somthing so slightly
Personal Blog
Code
Twitter

Gemini Order: #95 (roughly)
Current Device: Samsung Chromebook Gen 3
Current Arm Devices Count: ~30
Looking to acquire: Cavium Thunder X2 Hardware

vrejakti

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • http://www.animecharactersdatabase.com
Encoding Videos For Zaurus
« Reply #2 on: July 11, 2006, 05:20:40 am »
Quote
have you tried making moives with org vorbis, i am thinking that it might be worth trying out the integer decoding on the Z and see how it compares to libmad

i havent been into the video encoding scene in awhile but i belive that some of the other formats may be more Z friendly. i hear one of the design goals of mkv was fast seeking

just some sugestions. i dont have the time to fiddle with video encoding at the moment and i dont watch videos on my Z but i wonder if we can get some more performance out of these little things by changing somthing so slightly
[div align=\"right\"][a href=\"index.php?act=findpost&pid=134653\"][{POST_SNAPBACK}][/a][/div]

Hmm, hmm... to be honest, I have very little knowledge on the actual mencoder settings. You are absolutely right, the mencoder settings I have can be tweaked for much better performance. I think MKV support under Linux is still in developing stages [It wasn't until four months ago mplayer with mkv support enabled would emerge under Gentoo], but if it can be done, I'll happily make it the default in my next update.

I'm also thinking I'll add the option to customize most encoding settings as part of running the script.

Da_Blitz

  • Hero Member
  • *****
  • Posts: 1579
    • View Profile
    • http://www.pocketnix.org
Encoding Videos For Zaurus
« Reply #3 on: July 11, 2006, 05:46:38 am »
i would say that mkv is bleeding edge in linux, i use it for most of the files i "aquire"

i might take a look in an hour or two as i have to do some video encoding soon and might be able to teweak it a bit but i think that some benchmarks at diffrent bitrates for payback of aac, mp3 and org are in oder, lets say 96, 128 and 192kbps, 2 channel 16 bit audio, with both abr (average bit rate, normally confused with varible bit rate) and cbr (constant bit rate)

perhaps set up a script that encodes one file to all 3 formats at all 3 bit rates, then take it to the z and have another script run
Code: [Select]
#!/bin/bash
TEMP=$(date)
for I in *.[aac|mp3|ogg]; do
   time mplayer $I >| benchmark-$TIME
;done
echo done
then post the results as that will tell us what is happening cpu wise
« Last Edit: July 11, 2006, 05:47:03 am by Da_Blitz »
Personal Blog
Code
Twitter

Gemini Order: #95 (roughly)
Current Device: Samsung Chromebook Gen 3
Current Arm Devices Count: ~30
Looking to acquire: Cavium Thunder X2 Hardware

chrget

  • Full Member
  • ***
  • Posts: 129
    • View Profile
Encoding Videos For Zaurus
« Reply #4 on: July 11, 2006, 04:16:29 pm »
Quote
[...] i think that some benchmarks at diffrent bitrates for payback of aac, mp3 and org are in oder, lets say 96, 128 and 192kbps, 2 channel 16 bit audio, with both abr (average bit rate, normally confused with varible bit rate) and cbr (constant bit rate)
[div align=\"right\"][{POST_SNAPBACK}][/a][/div]
While it's over a year old and was originally in a different context, [a href=\"https://www.oesf.org/forums/index.php?showtopic=8142&st=0&p=70757&#entry70757]a posting I wrote[/url] lays down the basic observations I have made w/regard to A/V-encoding and playback in the many days I have tinkered with it. It should still hold true today, and while I haven't done any specific benchmarking for quite some time now, there is nothing that indicates otherwise.

Maybe this can give you some idea of what to expect.

Best regards,
Chris.
SL-5500G running a modified 3.13 Sharp ROM
Extrememory 1GB SD / Netgear MA701 WLAN
Audiovox RTM-8000 GSM/GPRS CF Card

xamindar

  • Hero Member
  • *****
  • Posts: 803
    • View Profile
    • http://www.radnimax.com
Encoding Videos For Zaurus
« Reply #5 on: July 11, 2006, 04:40:26 pm »
BTW, what's this "org" you guys are talking about?  Is it some new variation of "ogg"?

I used to have ogg encoded videos run on my 5600 but when I tried those same videos on my 3100 with kino2 they would not play.  Has ogg support been removed?
« Last Edit: July 11, 2006, 04:41:13 pm by xamindar »
SL-C3100 happily Dualbooting Japanese Rom 1.02 and Debian Eabi
Replaced internal CF with 8gb seagate cf hard drive
Ambicom CF GPS
CyberPower battery powered USB hub
D-link DCF-650W (MAN THIS THING IS HUGE!!)

Da_Blitz

  • Hero Member
  • *****
  • Posts: 1579
    • View Profile
    • http://www.pocketnix.org
Encoding Videos For Zaurus
« Reply #6 on: July 12, 2006, 01:19:09 am »
yeah we are talking about ogg

had a quick read and it probelly does still hold true today. i would still like to see a retest just to confirm everything (just in case they improved the code)

you do have some good points there. i use to cut the framerate in half for animation as it would improve things alot. i did notice that setting up your processing filters and changing the order has a huge impact of performance

the order i would do it in was
deinterlace
denoise
crop
shrink
rotate

that gives the best visual results but takes longer to do than other orders of post processing

is there a guide around here to what the maximum video capabilities of each model are. could be handy and allow us to chose several diffirnt profile (ie c700 low, med, high and c3000 low medium high)

i heard MKV has support for varible frame rates. for animation this could be handy due to the high amount of static images in some animaiton. in others the difrence between the frames is small enough that it should encode to be tiny anyway
Personal Blog
Code
Twitter

Gemini Order: #95 (roughly)
Current Device: Samsung Chromebook Gen 3
Current Arm Devices Count: ~30
Looking to acquire: Cavium Thunder X2 Hardware

SadaraX

  • Newbie
  • *
  • Posts: 28
    • View Profile
Encoding Videos For Zaurus
« Reply #7 on: July 16, 2006, 11:26:23 pm »
Quote
I think MKV support under Linux is still in developing stages [It wasn't until four months ago mplayer with mkv support enabled would emerge under Gentoo], but if it can be done, I'll happily make it the default in my next update.

Its funny that mkv is still perceived as the bleeding edge. Someone else mentioned AAC audio, which is considerably newer than the mkv project. That format just been pushed everywhere and implemented in many things, so it seems less bleeding edge.

About the video encoding this, I would be interested if anyone has comments about the ogg media container (OGM) and vorbis audio in their videos for the Zaurus series.

That script looks rather handy. I will probably write a similar script that can use Avidemux to encode videos....

Da_Blitz

  • Hero Member
  • *****
  • Posts: 1579
    • View Profile
    • http://www.pocketnix.org
Encoding Videos For Zaurus
« Reply #8 on: July 17, 2006, 03:07:09 am »
i have been getting alot of stuff with subtitles and multitrack audio in the mkv format. the reason i say its bleeding edge is because they are still extening (or mabey not. havent looked at it scince i went from winCE to lin and left betaplayer behind)

i have used OGM on windows and found the ffmpeg stuff rather poorley intergrated (sits next to the clock) however its good under linux.

i think we will probelly end up with ogg audio, must do some testing tomorrow  (libav gives me headaches under mplayer, its to damn comprehensive )
Personal Blog
Code
Twitter

Gemini Order: #95 (roughly)
Current Device: Samsung Chromebook Gen 3
Current Arm Devices Count: ~30
Looking to acquire: Cavium Thunder X2 Hardware

xamindar

  • Hero Member
  • *****
  • Posts: 803
    • View Profile
    • http://www.radnimax.com
Encoding Videos For Zaurus
« Reply #9 on: July 17, 2006, 05:01:03 pm »
Great script vrejakti!  Thanks.  It makes videos that play the best I have seen on my zaurus.

I have an idea.  Is it possible to just specify the width, for example 640, and then have the height automaticly set according to the aspect ratio of the input video?  It seems a few of my videos have strange aspect so I have to open them up in xine, check the aspect, then calculate it myself.  And sense I am never interested in streching the video this would be very usefull.

You know what I mean?  
W/640=H/h
where:
W= original width
640= new width
H= Original height
h= new height
SL-C3100 happily Dualbooting Japanese Rom 1.02 and Debian Eabi
Replaced internal CF with 8gb seagate cf hard drive
Ambicom CF GPS
CyberPower battery powered USB hub
D-link DCF-650W (MAN THIS THING IS HUGE!!)

vrejakti

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • http://www.animecharactersdatabase.com
Encoding Videos For Zaurus
« Reply #10 on: September 11, 2006, 03:24:22 am »
Hey everyone, I have some free time, so I'll be re-writing this script to add the option of custimizing the video and audio formate easily. I was going to post an updated script... a couple months ago    but I gave up figureing out how mencoder works. I can write bash scripts with ease, but what mencoder does is all magic to me.

If anyone can explain how mencoder chooses the video codex and/or audio codex, I'd be happy to write a script that includes all the options you can provide me.

Well, I'd like to keep my development code secret, but here's what we're looking at for the next script:
Code: [Select]
# Declare some variables
INFILE=$1
OUTFILE=$2
WIDTH=640
HEIGHT=480
AUDIO=mp2
VIDEO=lavc
VIDEO_CODEC=mpeg4


echo Choose an audio codec
echo "[mp2] // MPEG Layer 2"
echo "[ac3] // AC3, AKA Dolby Digital"
echo "[adpcm_ima_wav] // IMA adaptive PCM (4 bits per sample, 4:1 compression)"
echo "[sonic] // experimental lossy/lossless codec"


 # Start mencoder magic
#mencoder "$INFILE" -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=300:vpass=1 -lameopts cbr:br=64:mode=3 -vf scale=$WIDTH:$HEIGHT -oac copy -o $OUTFILE
#mencoder "$INFILE" -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=300:vpass=2 -lameopts cbr:br=64:mode=3 -vf scale=$WIDTH:$HEIGHT -oac mp3lame -o $OUTFILE
mencoder "$INFILE" -ovc $VIDEO -lavcopts vcodec=$VIDEO_CODEC:vbitrate=300:vpass=1 -lameopts cbr:br=64:mode=3 -vf scale=$WIDTH:$HEIGHT -oac lavc -lavcopts acodec=$AUDIO -o $OUTFILE
mencoder "$INFILE" -ovc $VIDEO -lavcopts vcodec=$VIDEO_CODEC:vbitrate=300:vpass=2 -lameopts cbr:br=64:mode=3 -vf scale=$WIDTH:$HEIGHT -oac lavc -lavcopts acodec=$AUDIO -o $OUTFILE

All I need is some options to code in for $VIDEO_CODEC and $AUDIO.

I wish it was as simple as VIDEO_CODEC=mkv AUDIO=ogg - it seems a fair bit more complicated.

vrejakti

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • http://www.animecharactersdatabase.com
Encoding Videos For Zaurus
« Reply #11 on: September 11, 2006, 03:34:41 am »
Quote
Great script vrejakti!  Thanks.  It makes videos that play the best I have seen on my zaurus.

I have an idea.  Is it possible to just specify the width, for example 640, and then have the height automaticly set according to the aspect ratio of the input video?  It seems a few of my videos have strange aspect so I have to open them up in xine, check the aspect, then calculate it myself.  And sense I am never interested in streching the video this would be very usefull.

You know what I mean? 
W/640=H/h
where:
W= original width
640= new width
H= Original height
h= new height
[div align=\"right\"][a href=\"index.php?act=findpost&pid=135441\"][{POST_SNAPBACK}][/a][/div]

Thanks xamindar.   I'm sorry for taking so long to reply to you - that's an excellent idea to have the script calculate the the height given the aspect ratio.

I have the formual A/B = C, B*C=A written on my wall so I always remember how to calculate the right ratio. *laughs* Might as well code that math into the next script.  I'll see what I can do. ^^

Da_Blitz

  • Hero Member
  • *****
  • Posts: 1579
    • View Profile
    • http://www.pocketnix.org
Encoding Videos For Zaurus
« Reply #12 on: September 11, 2006, 03:43:46 am »
i belive that mencoder has settings to adjust it automajically, but i have had problems when applying it to DVDs

if you want some help, email me and i will see what i can do
Personal Blog
Code
Twitter

Gemini Order: #95 (roughly)
Current Device: Samsung Chromebook Gen 3
Current Arm Devices Count: ~30
Looking to acquire: Cavium Thunder X2 Hardware

vrejakti

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • http://www.animecharactersdatabase.com
Encoding Videos For Zaurus
« Reply #13 on: September 11, 2006, 08:26:24 pm »
If you guys liked my first scripts, you're going to LOVE this one! I simplified the heck out of it, and the auto resolution calculation works so nicely.

All you have to do is type
./script video.avi
Yes
Yes

And it does the rest. :-D

Code: [Select]
#!/bin/sh
# Encoding Video for Zaurus Playback
# Script version 3
# Attributions:
#
# Vrejakti of LAN358 Inc (http://lan358.com): Main contributor of Bash code
# XorA of the Open Zaurus Project: Produced original mencoder code
# Da_Blitz from OESF Forums: Provided additional mencoder code
# Xamindar from OESF Forums: Provided feature suggestions


# Declare some variables
INFILE=$1
OUTFILE=Zaurus-$1
WIDTH=640
HEIGHT=480
AUDIO=mp2
VIDEO=lavc
VIDEO_CODEC=mpeg4
#--------------------
ERROR1="#########################
# ERROR! NO INPUT FILE. #
#########################

(Usage) $0 INPUT OUTPUT width_option height_option
--------------------
(Ex) $0 Funny_Clip.avi 320 240\n"

#--------------------
# Check for input video.
if [ -z "$1" ]
then printf "$ERROR1"
exit
fi

# Change to custom height and width
if [ -n "$2" ]
then WIDTH=$2
fi

if [ -n "$3" ]
then HEIGHT=$3
fi

# Print some information
printf "Video Encoding for Sharp Zaurus Playback\n\n"

printf "Would you like to use experimental auto resolution calculation? [Yes/No] "
read custom
case "$custom" in
 "Yes" | "yes" | "Y" | "y" )
height=`file $INFILE | gawk -F, '{print $3}' | gawk -F" " '{print $1}'`
width=`file $INFILE | gawk -F, '{print $3}' | gawk -F" " '{print $3}'`
first="$[$width*100/$height]"
second="$[640*$first/100]"
WIDTH=640
HEIGHT=$second
;;
esac

#--------------------
#--------------------
MAGIC1="mencoder "$INFILE" -ovc $VIDEO -lavcopts vcodec=$VIDEO_CODEC:vbitrate=300:vpass=1 -lameopts cbr:br=64:mode=3 -vf scale=$WIDTH:$HEIGHT -oac lavc -lavcopts acodec=$AUDIO -o $OUTFILE"
#--------------------
MAGIC2="mencoder "$INFILE" -ovc $VIDEO -lavcopts vcodec=$VIDEO_CODEC:vbitrate=300:vpass=2 -lameopts cbr:br=64:mode=3 -vf scale=$WIDTH:$HEIGHT -oac lavc -lavcopts acodec=$AUDIO -o $OUTFILE"
#--------------------
#--------------------

echo "Full screen [4:3]  use 640x480 [default]."
echo "Wide screen [16:9] use 640x360."
echo --------------------
echo "       Input: $INFILE"
echo "      Output: $OUTFILE"
echo "       Width: $WIDTH"
echo "      Height: $HEIGHT"
echo " Audio Codec: $AUDIO"
echo " Video Codec: $VIDEO_CODEC"
echo --------------------
echo " First mendoder command: $MAGIC1"
echo --------------------
echo " Second mencoder command: $MAGIC2"


# One last chance to bail out
printf "\nStart encoding? [Yes/No] "
read answer

# Start mencoder magic
case "$answer" in
  "Yes" | "yes" | "Y" | "y" )
$MAGIC1
$MAGIC2
printf "\n\nConverted file is $OUTFILE"
exit;;
esac

printf "\nEncoding has been cancled.\n"
« Last Edit: September 11, 2006, 08:44:45 pm by vrejakti »

Da_Blitz

  • Hero Member
  • *****
  • Posts: 1579
    • View Profile
    • http://www.pocketnix.org
Encoding Videos For Zaurus
« Reply #14 on: September 12, 2006, 09:35:13 am »
got your email and am looking into the mkv stuff

however i dont mean to cast your work in a bad light but here is some code i whipped up quickly (still needs to be debugged and finnished). at the moment its just the setup code however it might be handy to you as it is

Featuers:
Easy to maintian command line parsing
built in help
profile support to quickly encode diffrent files in diffrent ways (for example decimate the framrate by 2 and apply the xvid cartoon settings for anime)
ability to override built in varibles from the command line to assist in testing and activate advanced features (-o <somthing>=<val>)
supports config files (user and system)
rotation support (any angle)
Multiple file support (even when only one file is specified, this is so there are no special hacks for multipass files and so that they can be treated in the same manner as single pass)

planned features:
accept files as command line args or as part of a pipe (INFILE="-")

Code: [Select]
# Copyright: Jay Coles 2006
# Licsence: GPL v2
# Version 0.9

# ######## Cut and paste from here into config file ##########
# ***** File Vars *******
ENCODER=mencoder
# File to be converted
INFILE=""
# Save file as
OUTFILE=""


# ****** Encoding Vars ******
# nice easy policys for encoding diffrent media
# added because it was easy to hack together :)
# note that you might want to add a policy_ to the
# front of your funtions to avoid clobbering
# the internal code
POLICY=policy_anime

policy_anime() {
    V_CODEC="xvid"
    A_CODEC="mp3"

    V_BITRATE="300"
    A_BITRATE="96"

    #Diffrent encoding policies (ie cbc abr vbr multipass)
    V_POLICY="multipass"
    A_POLICY="cbr"

    # allow recording at diffrent rates/fps
    # this really helps with anime by decimating the fps
    # by 2, allows for huge reductions in size with a small
    # loss in percived quality (ie motion is slightly more
    # jagged)
    V_RATE="0.5"
    A_RATE="22050"

    # Allow overiding of ratio blank for keep original
    RATIO=""
    KEEP_RATIO="y"
    # Note that these are max vals that will never be exceeded
    # while still maintiaining asspect ratio
    X_RES="640"
    Y_RES="480"

    #Amount of degrees to rotate video (helps increse performance)
    ROTATION=90
}

################ End cut and paste ################

if [ -f /etc/zencoder.conf ]; then
    . /etc/zencoder.conf
fi

if [ -f ~/zencoder.conf ]; then
    . ~/zencoder.conf
fi

# Auto sources Policy
$POLICY

help () {
cat << EOF
zencoder: encodes moives for small media players

Usage: zencoder [-h | --help] [-o =] [-a

enjoy, hopefull i should be about 80% compleate  tommorrow on it (and actually have files encoding with it), also wont be that hard to get it to just do audio encoding (ie audio CD to mp3 aka ripping, specify INFILE as cdda://1)

*** edit added file as the CODE statement on the fourms clobbers the formatting  *******
***** edit this fourm dosent like files with no extension or the .sh extension, sorry about the tar.gz'ing, i relise the tar is unnecsarry (blame gnome  *****
« Last Edit: September 12, 2006, 09:40:34 am by Da_Blitz »
Personal Blog
Code
Twitter

Gemini Order: #95 (roughly)
Current Device: Samsung Chromebook Gen 3
Current Arm Devices Count: ~30
Looking to acquire: Cavium Thunder X2 Hardware