You are not logged in.

#1 2011-07-19 21:43:24

wolfdogg
Member
From: Portland, OR, USA
Registered: 2011-05-21
Posts: 545

need direction to make simple script

i would like to make a script for running a couple processes.

can somebody point me in the right direction to code this
(either an online tutorial or some help would be nice)

heres a general idea of the commands i want in the script for now, ill fine tune it later once i learn the syntax.

#!/bin/bash
# ffmpeg_dvdauthor

# $ ffmpeg_dvdauthor /working/directory/path in.avi out.vob 
# $1 = working_directory_path (minus trailing slash), $2 = input.avi, $3 = output.vob
# $BASENAME=substr($3,4); #just to give an idea of what i need, filename without .vob at the end

#print message 
#"Encoding $2"

#send .avi through ffmpeg
ffmpeg -i $1/$2 -target ntsc-dvd -vcodec copy -acodec copy $1/$3

#print message 
#"Encoding completed, now authoring $3"

#create file $1/dvd_$BASENAME.xml
#file contents 
<dvdauthor>
    <vmgm />
    <titleset>
        <titles>
            <pgc>
        <vob file="/path/$3" />
            </pgc>
        </titles>
    </titleset>
</dvdauthor>

#send the encoded file through dvdauthor
$ dvdauthor -o $1/$BASENAME -x dvd.xml 

#print message 
#"Job complete, file will attempt to play..."

#mplayer play the file automatically (just for kicks)
mplayer $1/$BASENAME/VIDEO_TS/VIDEO_TS.IFO

Last edited by wolfdogg (2011-07-21 05:38:53)


Node.js, PHP Software Architect and Engineer (Full-Stack/DevOps)
GitHub  | LinkedIn

Offline

#2 2011-07-19 23:24:28

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: need direction to make simple script

Here's a start for you... Needs a lot of error handling and validation added (eg, did the `cd` command work?)
Hopefully enough to put you on the right path smile

#!/bin/bash
# ffmpeg_dvdauthor

# $ ffmpeg_dvdauthor /working/directory/path in.avi out.vob 
# $1 = working_directory_path (minus trailing slash), $2 = input.avi, $3 = output.vob

BASENAME=$(basename $3 .vob)

#print message 
#"Encoding $2"

#send .avi through ffmpeg
cd $1
ffmpeg -i $2 -target ntsc-dvd -vcodec copy -acodec copy $3

#print message 
#"Encoding completed, now authoring $3"

#create file $1/dvd_$BASENAME.xml
#file contents 
cat > dvd_$BASENAME.xml <<EOT
<dvdauthor>
    <vmgm />
    <titleset>
        <titles>
            <pgc>
        <vob file="/path/$3" />
            </pgc>
        </titles>
    </titleset>
</dvdauthor>
EOT

#send the encoded file through dvdauthor
[[ -d "$BASENAME" ]] || mkdir "$BASENAME"
dvdauthor -o $BASENAME -x dvd.xml 

#print message 
#"Job complete, file will attempt to play..."

#mplayer play the file automatically (just for kicks)
mplayer $BASENAME/VIDEO_TS/VIDEO_TS.IFO

Offline

#3 2011-07-19 23:29:37

Stebalien
Member
Registered: 2010-04-27
Posts: 1,237
Website

Re: need direction to make simple script


Steven [ web : git ]
GPG:  327B 20CE 21EA 68CF A7748675 7C92 3221 5899 410C
Do not email: honeypot@stebalien.com

Offline

#4 2011-07-19 23:45:29

sisco311
Member
From: Romania
Registered: 2008-05-23
Posts: 112

Re: need direction to make simple script

That guide is full of bugs.

@OP

Check out http://mywiki.wooledge.org/

and always quote the variables.


don't drink unwashed fruit juice.
i never make predictions, especially about the future.

Offline

#5 2011-07-20 06:33:30

wolfdogg
Member
From: Portland, OR, USA
Registered: 2011-05-21
Posts: 545

Re: need direction to make simple script

great, thanks fukawi, i needed that, now that i see the basic syntax, i can move forward.  was happy once i got it working

#!/bin/bash
# ffmpeg_dvdauthor

# $ ffmpeg_dvdauthor /working/directory/path in.avi out.vob 
# $1 = working_directory_path (minus trailing slash), $2 = input.avi, $3 = output.vob
# $2 = /path/input.avi, $3 = output.vob (no path, will be made in the same directory)

BASENAME=$(basename $3 .vob) 

#print message 
echo
echo "Encoding $2"
echo

#send .avi through ffmpeg
cd $1
ffmpeg -i $2 -target ntsc-dvd -vcodec copy -acodec copy $3

#print message 
echo
echo "Encoding completed, now authoring $3"
echo


#create file $1/dvd_$BASENAME.xml
#file contents 
cat > dvd_$BASENAME.xml <<EOT
<dvdauthor>
    <vmgm />
    <titleset>
        <titles>
            <pgc>
        <vob file="$1/$3" />
            </pgc>
        </titles>
    </titleset>
</dvdauthor>
EOT

#send the encoded file through dvdauthor
[[ -d "$BASENAME" ]] || mkdir "$BASENAME"
dvdauthor -o $1/$BASENAME -x dvd_$BASENAME.xml 

#print message 

echo
echo "Job complete, file will attempt to play..."


#mplayer play the file automatically (just for kicks)
mplayer $BASENAME/VIDEO_TS/VIDEO_TS.IFO

the file does re-encode, then dvd is authored, then dvd does play, thats cool.   i going to work on changing the script around so that the path is taken from the input file path if one is indicated otherwise, directory is ./ this will eliminate one of the variables.

then i will introduce some validation. :-)

thanks Stebalien and sisco311, funny sisco i was just on that page yesterday for another job, but the link you sent me is hard to find the table of contents, until messing around with it for a while.  appreciated however!

just a note for anybody who tries this script, the -vcodec and -acodec copy need to be removed if your working with a non-dvd compliant .avi file.

Last edited by wolfdogg (2011-07-20 06:36:33)


Node.js, PHP Software Architect and Engineer (Full-Stack/DevOps)
GitHub  | LinkedIn

Offline

#6 2011-07-20 12:49:35

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: need direction to make simple script

wolfdogg wrote:

i going to work on changing the script around so that the path is taken from the input file path if one is indicated otherwise, directory is ./ this will eliminate one of the variables.

man basename
man dirname

wink
EDIT: oh, and one of the most useful pages that I refer to regularly is http://tldp.org/LDP/abs/html/string-manipulation.html

Last edited by fukawi2 (2011-07-20 12:50:06)

Offline

#7 2011-07-20 17:12:12

sisco311
Member
From: Romania
Registered: 2008-05-23
Posts: 112

Re: need direction to make simple script

fukawi2 wrote:

EDIT: oh, and one of the most useful pages that I refer to regularly is http://tldp.org/LDP/abs/html/string-manipulation.html

Hmmm,  It CAN be used as a reference, but only if you know how to filter the junk.

For example, the following code from your link contains the 3 most common errors (see BashPitfalls #1 #2 and #3 ) that bash programmers make:

for i in $(ls *.$SUFF)
do
  mv -f $i ${i%.$SUFF}.$suff
done 

# Thank you, Rory Winston.

@OP
Ones again QUOTE your variables and add some error handling:

cd "$1" || exit 1
if [[ -f "$2"]]; then
    ffmpeg -i "$2" ...
else
    :
fi

And you can use Parameter Expansion to get the basename and dirname:

dir="${path%/*}"
file="${path##*/}"

Last edited by sisco311 (2011-07-20 17:13:19)


don't drink unwashed fruit juice.
i never make predictions, especially about the future.

Offline

#8 2011-07-20 23:16:58

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: need direction to make simple script

sisco311 wrote:

Hmmm,  It CAN be used as a reference, but only if you know how to filter the junk.
.....

dir="${path%/*}"
file="${path##*/}"

That's the kind of thing I use it for reference about... I can never remember the different {%} and {%%} {#} etc tongue

Offline

#9 2011-07-20 23:59:17

sisco311
Member
From: Romania
Registered: 2008-05-23
Posts: 112

Re: need direction to make simple script

fukawi2 wrote:

That's the kind of thing I use it for reference about... I can never remember the different {%} and {%%} {#} etc tongue

`man bash' is your friend wink

man bash | less +/"^ +Parameter Expansion"

Last edited by sisco311 (2011-07-20 23:59:37)


don't drink unwashed fruit juice.
i never make predictions, especially about the future.

Offline

#10 2011-07-21 03:18:06

crouse
Arch Linux f@h Team Member
From: Iowa - USA
Registered: 2006-08-19
Posts: 907
Website

Re: need direction to make simple script

I wish I had written this: http://bashcurescancer.com/10-steps-to- … ripts.html
Explains bash parameter expansion.... I copied that page into my personal wiki.... didn't change a thing.
I refer to it quite a bit, as I can't every remember the exact syntax right off the top of my head.  wink

Offline

#11 2011-07-21 05:13:56

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: need direction to make simple script

sisco311 wrote:

`man bash' is your friend wink

Meh, that means another terminal window or closing vi... My web browser is already open and there's a shortcut on my bookmark bar tongue

Offline

#12 2011-07-21 05:30:57

wolfdogg
Member
From: Portland, OR, USA
Registered: 2011-05-21
Posts: 545

Re: need direction to make simple script

i havent worked on it today, got too busy staging and pre-processing the loads of .avi's that i have on my hard drive.  last night i got the code working pretty good, im open to suggestions.  i got stuck on the dvd.xml trying to get the chapters to work, the thing i think i made a mistake on is i was trying to test them by playing the completed VIDEO_TS.VOB's, as well as the video_ts.ifo on my media players, by clicking on the 'next' button, until i noticed that the actual text on that button was not 'next chapter' but 'next file in the list' or something like that. also, i believe that unless the video is loaded through a menu, which im not doing yet, then the chapters dont work(unless played on a dvd player?).  so i will burn one sometime before or after working on the script more to see if the chapters work.

i made some validation checks, and removed one of the variables on the command, (the path) and if one is included on teh input file, the path if simply pulled from that. although that part is mostly done, i still have to figure out why when the path IS included on the input file line, its not filling in that variable.  #i have a few notes about that on the script incase anybody sees anything.  also, im trying to universalize this script more so that it might be useful for someone else besides just myself. :-)

 
#!/bin/bash
# ffmpeg_dvdauthor

#OLD
# $ ffmpeg_dvdauthor /working/directory/path/in.avi out.vob 
# $1 = working_directory_path (minus trailing slash), $2 = input.avi, $3 = output.vob
#[[ $1 ]] || {$1=./;#set current directory as working directory cd $1; #move to the location}

#NEW
# $ ffmpeg_dvdauthor /working/directory/path in.avi out.vob 
# $1 = /path/input.avi, $2 = output.vob (no path, will be made in the same directory)

BASENAME=$(basename $2 .vob) 

# if path was included 
if [[ "${1%/*}" ]] 
then #set path and file from it 
  $path="${1%/*}"; #path is not working
  $file="${1%#$path/}";
else #just set file
  $path=""  #tried ./ and \./ wont work, need solution here
  $file="$1"
fi

#print message 
echo
echo "Encoding $1"
echo

# check if file exists
[[ -e "$2" ]]  && { echo "file $2 already exists, choose another output name"; exit; }

#send .avi through ffmpeg
ffmpeg -i $1 -target ntsc-dvd -vcodec copy -acodec copy $2

# check if .vob created successfully (-s if exists and is not empty)
[[ -s "$2" ]]  || { echo; echo "file creation failed"; echo; exit; }

#print message 
echo
echo "Encoding completed, now authoring $2"
echo
 
#create file $pathdvd_$BASENAME.xml
#file contents 
cat > dvd_$BASENAME.xml <<EOT
<dvdauthor>
  <titleset>
    <titles>
      <pgc>
        <vob file="$path$2" chapters="0,05:00,10:00,15:00,20:00,25:00,30:00,35:00,40:00,45:00,50:00,55:00,1:00:00,1:05:00,1:10:00,1:15:00,1:20:00,1:25:00,1:30:00,1:35:00,1:40:00,1:45:00,1:50:00,1:55:00,2:00:00,,2:05:00,2:10:00,2:15:00,2:20:00,2:25:00,2:30:00,2:35:00,2:40:00,2:45:00,2:50:00,2:55:00,3:00:00,3:05:00,3:10:00,3:15:00,3:20:00,3:25:00,3:30:00" />
      </pgc>
    </titles>
  </titleset>
</dvdauthor>
EOT

#send the encoded file through dvdauthor
export VIDEO_FORMAT=NTSC
[[ -d "$BASENAME" ]] || mkdir "$BASENAME"
#-x dvd_$BASENAME.xml (for using xml file)
#-t -c 0,5:0 chapters $path$2 (for manually setting options)
dvdauthor -o $path$BASENAME -x dvd_$BASENAME.xml 

# check if output was made
[[ -s "$path$BASENAME/VIDEO_TS/VTS_01_1.VOB" ]]  || { echo; echo "dvdauthor was not able to write the file, check any errors above, or dvd_$BASENAME.xml for clues"; echo; exit; }

#print message 
echo
echo "Job complete, file will attempt to play..."

#mplayer play the file automatically (just for kicks)
xine DVD:/$path$BASENAME/VIDEO_TS/

Last edited by wolfdogg (2011-07-21 05:34:29)


Node.js, PHP Software Architect and Engineer (Full-Stack/DevOps)
GitHub  | LinkedIn

Offline

Board footer

Powered by FluxBB