Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Ipod/G1 Videoencoder v0.3 by Shady
- # Features:
- # Calculates new aspect ratios depending on video file. Never will you get a stretched out video!
- # Skips videos already encoded
- # Adds subtitles wether it is softsub from .mkv or a seperate same-named.srt.
- # Specify Language preferences for both Audio and Subtitles
- # Recursively finds videos and encodes them.
- # Made to work especially well on the Andoid OS!
- #-------------
- #Set home where to put log.
- home="/home/shady"
- #--------Subtitle And Language
- #Set to where font is to use in subtitles
- subfontpath="/home/shady/myriadwebpro-condensed.ttf"
- #Set to what scale to use in font.
- subfontscale="3.2"
- #Subtitle options, will pick the english language sub first, if not there then the
- #dutch sub file, otherwise the undefined (dont know language sub).
- #Set to "" if you don't want subtitles. Mind that if your video doesnt have subtitles nothing will happen.
- suboptions="-slang eng,dut,und -font $subfontpath -subfont-text-scale $subfontscale"
- #edit down here if you know what your doing. Check bottom for mencoder options.
- #Audiooptions, set to "" if you don't need audiosettings.
- audiooptions="-alang jpn,eng,und"
- #----------
- #bash doesn't do float calculations, found this on inet somewhere.
- function fgt() {
- LHS=$1
- RHS=$2
- min=`(echo $LHS ; echo $RHS) | sort -n | head -1`
- if [ "$min" = "$LHS" ]; then
- return 1
- else
- return 0
- fi
- }
- function flt () {
- LHS=$1
- RHS=$2
- min=`(echo $LHS ; echo $RHS) | sort -n | head -1`
- if [ "$min" = "$LHS" ]; then
- return 0
- else
- return 1
- fi
- }
- function true_or_false () {
- FUNC=$1
- ARG1=$2
- ARG2=$3
- $FUNC $ARG1 $ARG2
- if [ $? -eq 0 ]; then
- echo TRUE
- else
- echo FALSE
- fi
- }
- find "$1" \( -name *.avi -o -name *.mkv -o -name *.mp4 -o -name *.ogm \) -a \( ! -iname "*Mobile*" \) -type f -print > $home/.genmob.log
- cat $home/.genmob.log | while read LINE
- do
- #File information and check
- #TODO check if there is a mobile directory inside the directory we are looking.
- vfile=$(basename "$LINE")
- vdir=$(dirname "$LINE")
- wext=$(echo "$vfile" | awk -F . '{print $NF}')
- vfilewext=$(basename "$vfile" ."$wext")
- newfile="$vdir/Mobile/NOTREADYYET-Mobile-$vfilewext".mp4
- if [ ! -d "$vdir/Mobile" ] && [ ! -f "$vdir/Mobile/Mobile-$vfilewext.mp4" ] && [ "$(basename "$vdir")" != "Mobile" ]
- then
- mkdir "$vdir/Mobile"
- #echo $newfile
- #Find aspect ratio
- #Movie info:
- #yes i know this is ugly as hell, i dunno how to split string or whatever in bash.
- vwidth=`expr substr $(mplayer -identify "$LINE" -ao null -vo null -frames 0 2>/dev/null | grep ^ID_VIDEO_WIDTH=) 16 5`
- vheight=`expr substr $(mplayer -identify "$LINE" -ao null -vo null -frames 0 2>/dev/null | grep ^ID_VIDEO_HEIGHT=) 17 5`
- vaspect=`echo "$vwidth / $vheight " | bc -l`
- if [ $(true_or_false fgt $vaspect 1.2) = "TRUE" -a $(true_or_false flt $vaspect 1.4) = "TRUE" ]
- then
- newaspect="4:3"
- newoptions="scale=432:324,crop=432:320"
- else
- if [ $(true_or_false fgt $vaspect 1.64) = "TRUE" -a $(true_or_false flt $vaspect 1.81) = "TRUE" ]
- then
- newaspect="16:9"
- newoptions="scale=480:270,expand=480:272"
- else
- if [ $(true_or_false fgt $vaspect 1.83) = "TRUE" -a $(true_or_false flt $vaspect 1.87) = "TRUE" ]
- then
- newaspect="37:20"
- newoptions="scale=480:259,expand=480:272"
- else
- if [ $(true_or_false fgt $vaspect 2.3) = "TRUE" -a $(true_or_false flt $vaspect 2.5) = "TRUE" ]
- then
- newaspect="47:20"
- newoptions="scale=480:204,expand=480:208"
- fi
- fi
- fi
- fi
- echo "Encoding: $vwidth x $vheight with ratio $newaspect : $vfile"
- #Edit this line with your own options
- mencoder "$LINE" -o "$newfile" -of lavf -lavfopts format=mp4 -ss 1 -vf pp=ci,$newoptions,harddup -ovc x264 -x264encopts crf=30.0:nocabac:level_idc=30:global_header:threads=2 -ofps 30000/1001 -oac faac -faacopts mpeg=4:object=2:br=128:raw -channels 2 -srate 44100 -af volnorm $suboptions -sub "$vdir/$vfilewext".srt $audiooptions -msglevel all=-1:statusline=5
- mv "$newfile" "$vdir/Mobile/Mobile-$vfilewext".mp4
- else
- echo "Skipping: $vfile already is in a Mobile directory or already has a Mobile directory."
- fi
- :
- done
- #4:3=1.33
- #Ex: 640x480
- #scale=432:324,crop=432:320
- #16:9=1.7778
- #Ex: 848x480
- #scale=480:270,expand=480:272
- #37:20=1.8500
- #Ex: 1280x688
- #scale=480:259,expand=480:270
- #47:20=2.4000
- #Ex: 1920x800
- #scale=480:204,expand=480:208
Advertisement
Add Comment
Please, Sign In to add comment