[MEncoder-users] [DONE] my first bash encoding script

ronnie escobedo tenminuteslater at hotmail.com
Mon Dec 13 05:27:01 CET 2004


just fixed some formatting and spelling  script below




#!/bin/bash

############## MEncoder Chapter Encoder #########################
# author: ronnie r escobedo					#
# contact: rescobedo at mixsessions.com				#
# created: 12-11-2004						#
#								#
# -this script was created because I needed a better		#
#  method for encoding several chapters from several		#
#  different DVDs and not having to worry about			#
#  remembering the name of the last file			#
#								#
# -allows you to specify which chapters per dvd to encode	#
# -will automatically name the files using a number naming	#
#  convention							#
# Everything is well commented. The only necessary change	#
# are to 'videodir'. This is where all your encoded files	#
# will be saved. The other changes that must be made are	#
# to MEncoder. Remember to change -dvd-device, set your		#
# encoding quality, video filter and crop options.		#
#								#
#								#
# Run script with appropriate permissions. When you launch	#
# the script you will be prompted to enter the chapters		#
# for encoding. Enter 'ALL' the chapters you would like to	#
# encode. The prompt will only run once.			#
#								#
# When the file encoding is complete Mplayer will play the	#
# audio of the 1st avi file encoded to let you know all		#
# encoding is complete. You can comment out Mplayer or		#
# specify your own audio file.					#
#################################################################

#line break
echo ""

#########################################################
# Prompt						#
#########################################################

#prompt to enter chapters
echo -en "\033[1;34menter chapters to encode ex: chapters 1-3 enter 1-3 
[enter]\033[0m"; tput sgr0
read chapter_encodes



### if user input is blank
if [ -z "$chapter_encodes" ];then
echo ""
echo -en "\033[1;31myou must enter chapters to proceed, enter chapters: 
[enter]\033[0m"; tput sgr0
read chapter_encodes
fi
###


# line break
echo ""

# prints chapters that will be encoded
echo -e "\033[1;34m     encoding chapter(s) $chapter_encodes\033[0m"; tput 
sgr0

#exit

#########################################################
# end of prompt						#
#########################################################



#################################################
# directory where encoded videos are saved	#
# specify your directory here			#
#################################################

videodir="/mnt/xdrive/video/"

#################################################
# end of video directory			#
#################################################


# line break
echo ""

# displays directory saving files to
echo -e "\033[1;34m     saving to 
directory\033[0m""\033[1;31m'$videodir'\033[0m"; tput sgr0

# line break
echo ""

# prints encoding beginning
echo -e "\033[1;31m     encoding 
beginning....\033[0m""\033[1;34m...\033[0m""\033[1;31m.............\033[0m""\033[1;34m...\033[0m"; 
tput sgr0

# pause for 4 seconds
sleep 4



#########################################
# you can input chapters manually	#
# comment out the prompt section	#
# remove $chapter_encodes &		#
# insert chapters to encode ex: 1-1 2-3	#
#########################################

for chapter in $chapter_encodes; do

#########################################
# end of chapter input			#
#########################################


# change to video directory
cd $videodir

# check if ls-r.txt file exist
if test -e ls-r.txt

# if it does exist proceed
then

# pause 2 seconds
sleep 2

# reads the first line of the txt file
# first line will always be the last file numerically
vidnum=$(head -1 ls-r.txt)

#print file name
#echo $vidnum

# setting IFS to oldIFS
oldIFS=$IFS

# field seperator
IFS=.

# not sure what this does but it makes it work - if you know let me know
set -- $vidnum

# before field seperator (should be a number)
v1=$1

# after field seperator (should be file extention - avi)
v2=$2

# sets oldIFS back
IFS=$oldIFS

# prints number of file name
#echo $v1

#initialize prex to v1
x=$v1

#### this adds the prefix 0 to the avi file for numbers 1-9
if [ "$x" -ge 9 ];then
prx=""
else
prx=0
fi
###

# remove ls-r.txt
rm -f ls-r.txt

# if ls-r.txt files does not exist then proceed from here
else

#initialize x & prx to 0
x=0

### will add the prefix 0 to 1.avi ex: 01.avi - to conform to naming 
convention
prx=0

# pause 1 second
sleep 1

fi
###

# increments the value of x by 1
x=$(expr $x + 1)
x=$prx$x


#################################
# mencoder commands and options	#
#################################


mencoder -dvd-device /dev/hda dvd://1 -oac pcm -ovc lavc -lavcopts 
vcodec=mpeg4:vqscale=2:vhq:v4mv:trell:autoaspect -ofps 29.97 -vf 
crop=692:464:14:8,pp=fd -noskip -chapter $chapter -o 
/mnt/xdrive/video/$x.avi


#################################
# end of mencoder options	#
#################################



# outputs recursive ls info to a txt file
ls -r *.avi > ls-r.txt

# pause 2 second
sleep 2

# end of loop
done

# line break
echo ""

# prints encoding complete
echo -e "\033[1;31m     ....\033[0m""\033[1;34m....encoding 
complete\033[0m"; tput sgr0

# line break
echo ""


#################################
# encoding done			#
#################################



# change to video directory
cd $videodir

# press Q to end Mplayer
echo -e "\033[1;31m     press [q] to quit Mplayer\033[0m"; tput sgr0

# pause 3 seconds
sleep 3

# press Q to end Mplayer
echo -e "\033[1;31m     press [q] to quit Mplayer\033[0m"; tput sgr0

# line break
echo ""

# play audio from 01.avi - just incase you walk away you know your encoding 
is now done =)
# comment out mplayer if you do not want to play 01.avi audio
mplayer -vo null 01.avi

# line break
echo ""

# press Q to end Mplayer
echo -e "\033[1;31m     press [q] to quit Mplayer\033[0m"; tput sgr0

# line break
echo ""





More information about the MEncoder-users mailing list