LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Loop ends unexpectedly after one run! (https://www.linuxquestions.org/questions/programming-9/loop-ends-unexpectedly-after-one-run-381763/)

trex_dk 11-10-2005 08:10 AM

Loop ends unexpectedly after one run!
 
Hey!

I'm trying to make my life a whole lot easier by making a bash-script, who reads a directory and greps the files that ends on mpg and mpeg, defined in a pattern.temp written by the script.
The script was designed for converting musicvideos into compliant DVD-files.

When reading (a lot of) files, the script runs smoothly the first time, but when trying to run the commands on the second file, ffmpeg somehow enforces the script to quit.
I've tried to comment out the ffmpeg line, and then the script runs just fine (even though it is useless without the ffmpeg command).

Could it be an issue with the way ffmpeg interprets the syntax's?
Hope some of you can help me, because it is starting to drive me crazy :P

Best regards
trex_dk

Code:

#!/bin/sh

if [ "$1" = "" ]; then
        echo "Specify directory containing mpegs"
else
        if [ ! -d $1 ]; then
                echo "Directory does not exist!"
                exit 0
        fi

        if [ -e patterns.temp ]; then
                rm patterns.temp
        fi
        touch patterns.temp
        echo ".mpg" > patterns.temp
        echo ".mpeg" >> patterns.temp

        numVideos=`ls $1 | grep -f patterns.temp | wc -l`

        i=1
        ls $1 | grep -f patterns.temp | while read file; do
                if [ -f "$1/$file" ]; then
                        echo "-- $file ($i / $numVideos) --"
                        echo "> Processing audio"
                        ffmpeg -i "$1/$file" -ab 256 -ar 48000 -ac 2 -acodec ac3 -y "$1/$file.ac3"
                        echo "> Processing video"
                        mpegdemux -d -s 0xe0 "$1/$file" "$1/$file.m2v"
                        echo "> Multiplexing"
                        mplex -f 8 -o "$1/final_$file" "$1/$file.m2v" "$1/$file.ac3"
                        rm -f "$1/$file.ac3" "$1/$file.m2v"
                        echo "> DONE!"
                        i=`expr $i + 1`
                fi
        done

        rm patterns.temp
fi

exit 0


chrism01 11-10-2005 10:58 PM

Do you get any error msgs ?
You could also try using
set -xv
at the top of the prog which will show you in detail what's happening.

bigearsbilly 11-11-2005 03:49 AM

do as chrism says

and try this at the top also:
Code:

set +o errexit
set -o nounset



All times are GMT -5. The time now is 06:30 PM.