LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-10-2005, 08:10 AM   #1
trex_dk
LQ Newbie
 
Registered: Aug 2005
Distribution: Ubuntu
Posts: 6

Rep: Reputation: 0
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
 
Old 11-10-2005, 10:58 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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.
 
Old 11-11-2005, 03:49 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
do as chrism says

and try this at the top also:
Code:
set +o errexit
set -o nounset
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
files the ends with .c maginotjr Programming 15 07-24-2005 01:06 PM
What would cause a while loop to unexpectedly end? farmerjoe Programming 5 04-29-2005 02:57 PM
how i supose to run file that ends with ".c" ? SlackwareMan Linux - Software 2 08-08-2004 11:14 PM
mysqld_safe ends compu73rg33k Linux - Software 5 04-04-2004 04:23 PM
When support ends.... what to do? bxb32001 Red Hat 15 11-02-2003 06:27 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration