Jul 10 2006, 08:56 PM
Post
#1
|
|
![]() Group: Members Posts: 21 Joined: 8-December 05 Member No.: 8,686 |
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 #!/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. -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- 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. 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 #!/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. ;-) ) |
|
|
|
vrejakti Encoding Videos For Zaurus Jul 10 2006, 08:56 PM
Da_Blitz have you tried making moives with org vorbis, i am... Jul 11 2006, 12:31 AM
vrejakti QUOTE(Da_Blitz @ Jul 11 2006, 02:31 AM)have y... Jul 11 2006, 01:20 AM
SadaraX QUOTE(vrejakti @ Jul 11 2006, 01:20 AM)I thin... Jul 16 2006, 07:26 PM
Da_Blitz i would say that mkv is bleeding edge in linux, i ... Jul 11 2006, 01:46 AM
chrget QUOTE(Da_Blitz @ Jul 11 2006, 11:46 AM)[...] ... Jul 11 2006, 12:16 PM
xamindar BTW, what's this "org" you guys are ... Jul 11 2006, 12:40 PM
Da_Blitz yeah we are talking about ogg
had a quick read an... Jul 11 2006, 09:19 PM
Da_Blitz i have been getting alot of stuff with subtitles a... Jul 16 2006, 11:07 PM
xamindar Great script vrejakti! Thanks. It makes vide... Jul 17 2006, 01:01 PM
vrejakti QUOTE(xamindar @ Jul 17 2006, 03:01 PM)Great ... Sep 10 2006, 11:34 PM
vrejakti Hey everyone, I have some free time, so I'll b... Sep 10 2006, 11:24 PM
Da_Blitz i belive that mencoder has settings to adjust it a... Sep 10 2006, 11:43 PM
vrejakti If you guys liked my first scripts, you're goi... Sep 11 2006, 04:26 PM
Da_Blitz got your email and am looking into the mkv stuff
... Sep 12 2006, 05:35 AM
vrejakti nice code Da_Blitz, very nice! Admittedly, I a... Sep 13 2006, 02:59 PM
Da_Blitz thanks for that
when i switched to linux i did it... Sep 14 2006, 01:28 AM
vrejakti Phew, looks like I don't have to implement ogg... Sep 15 2006, 04:24 PM
Da_Blitz thanks as i said it causes problems but as its har... Sep 17 2006, 12:16 AM
Da_Blitz Here is version 2.0, fixed a problem with the comm... Sep 23 2006, 11:21 PM
johnny_a The script above gives me this error:
CODE./zenc... Oct 4 2006, 11:49 AM
vrejakti QUOTE(johnny_a @ Oct 4 2006, 01:49 PM)The scr... Oct 4 2006, 02:13 PM
johnny_a Thanks!
I didn't bother to read through ... Oct 4 2006, 09:05 PM
Da_Blitz i thoght that the ####### cut here ##### was obvio... Oct 5 2006, 10:31 PM
vrejakti I've tweaked my script once again. Code is cle... Oct 28 2006, 12:44 PM
Da_Blitz not bad at all, never did like interactive stuff i... Oct 29 2006, 11:13 PM
vrejakti Combining scripts is an interesting idea. For now,... Oct 30 2006, 06:22 AM
vrejakti Several tweaks later... I've got your script e... Oct 30 2006, 07:29 AM
vrejakti In a couple days I'll be releasing a new versi... Oct 31 2006, 09:09 PM
Da_Blitz any particular reason for zsh? i try hard to keep ... Nov 1 2006, 04:13 AM
vrejakti QUOTE(Da_Blitz @ Nov 1 2006, 06:13 AM)any par... Nov 1 2006, 04:02 PM
grog QUOTE(vrejakti @ Nov 1 2006, 06:02 PM)QUOTE(D... Nov 1 2006, 06:27 PM
nilch QUOTE(vrejakti @ Jul 10 2006, 11:56 PM)It... Nov 1 2006, 07:37 AM
vrejakti You're right about this thread being all over ... Nov 1 2006, 08:24 AM
Da_Blitz well the problem that you are getting is related t... Nov 1 2006, 06:53 PM
vrejakti It would be nice if quoting was the solution---(ra... Nov 1 2006, 07:29 PM
Da_Blitz it happens, the most common problem is the null ar... Nov 2 2006, 03:29 AM![]() ![]() |
|
Lo-Fi Version | Time is now: 25th May 2013 - 06:10 AM |