LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 04-06-2010, 06:07 PM   #1
slinkoff
LQ Newbie
 
Registered: Nov 2007
Posts: 3

Rep: Reputation: 0
Why is ffmpeg stopping after the first encode when using my bash script?


I'm trying to create a script that will trawl through a directory structure looking for VOB files, convert them to AVI and place them in a ./converted/ sub-directory of the the original source folder. I've knocked up the script below which appears to work fine when I place an "echo" in front of the actual ffmpeg encode line, I get the output on the screen with ffmpeg finding all the VOB files in the directories and looking to convert them to the correct sub-directory. Yet, when I remove the echo and run the script for real, ffmpeg converts the first file and then stops. No errors. Is this something to do with ffmpeg or a problem with my script below?

Code:
#!/bin/bash
#
#  Define the starting search point:
#
start="/mnt/disk1/toconvert"

#
#  Loop over directories looking for VOB files
#
while read file
do
  DIR=$(dirname "$file")
  if [ ! -d "$DIR/converted" ]
     then
     mkdir "$DIR/converted"
  fi  
  ORIGINAL=`basename "$file" .VOB`
  NEWNAME=${ORIGINAL}.avi
  ffmpeg -i "$file" -f avi -vcodec mpeg4 -b 5000k -g 300 -bf 2 -ab 192k "$DIR/converted/$NEWNAME"
done < <(find $start \( -iname \*.VOB \))
Thanks for your help

slink
 
Old 04-06-2010, 08:10 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Hi Slink, maybe you would show us maybe 3 or so lines with the echo output?

Also, you may change the following:

Quote:
ORIGINAL=`basename "$file" .VOB`
NEWNAME=${ORIGINAL}.avi
ffmpeg -i "$file" -f avi -vcodec mpeg4 -b 5000k -g 300 -bf 2 -ab 192k "$DIR/converted/$NEWNAME"
to

Code:
ffmpeg -i "$file" -f avi -vcodec mpeg4 -b 5000k -g 300 -bf 2 -ab 192k "$DIR/converted/${file%vob}avi"
Just a suggestion
 
Old 04-07-2010, 02:21 AM   #3
slinkoff
LQ Newbie
 
Registered: Nov 2007
Posts: 3

Original Poster
Rep: Reputation: 0
sure, here's the output when I run it on 2 test directories containing a total of 3 files, 2 in 1, 1 in the other.

Code:
ffmpeg -i /mnt/disk1/downloads/convert/test/1/VTS_07_1.VOB -f avi -vcodec mpeg4 -b 5000k -g 300 -bf 2 -ab 192k /mnt/disk1/downloads/convert/test/1/converted/VTS_07_1.avi
ffmpeg -i /mnt/disk1/downloads/convert/test/1/VTS_05_1.VOB -f avi -vcodec mpeg4 -b 5000k -g 300 -bf 2 -ab 192k /mnt/disk1/downloads/convert/test/1/converted/VTS_05_1.avi
ffmpeg -i /mnt/disk1/downloads/convert/test/2/VTS_05_1.VOB -f avi -vcodec mpeg4 -b 5000k -g 300 -bf 2 -ab 192k /mnt/disk1/downloads/convert/test/2/converted/VTS_05_1.avi

Last edited by slinkoff; 04-07-2010 at 02:22 AM.
 
Old 04-07-2010, 04:40 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
So my initial thought is that when the second ffmpeg gets kicked off it buggers up the first one.

So maybe throw && at the end of the command which will wait until each one finishes before progressing.
 
Old 04-07-2010, 05:52 AM   #5
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
ffmpeg does some strange things to stdin. Try piping /dev/null into it, so it doesn't mess up the while loop.

ffmpeg -i "$file" -f avi -vcodec mpeg4 -b 5000k -g 300 -bf 2 -ab 192k "$DIR/converted/${file%vob}avi" </dev/null
 
Old 04-07-2010, 04:37 PM   #6
slinkoff
LQ Newbie
 
Registered: Nov 2007
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Guttorm View Post
ffmpeg -i "$file" -f avi -vcodec mpeg4 -b 5000k -g 300 -bf 2 -ab 192k "$DIR/converted/${file%vob}avi" </dev/null
Yep, that does the trick! Thanks. I'm new to scripting, could you briefly explain what that does/how it fixes the problem?

Thanks
 
Old 07-06-2011, 04:27 AM   #7
phaemon
Member
 
Registered: Jul 2011
Posts: 40

Rep: Reputation: 5
I hit this problem yesterday. ffmpeg reads from stdin and therefore reads what the loop is supposed to get, so the loop gets nothing more. There's a site that explains it all, but I can't post it because it's my first post. I'll try with a followup.

---------- Post added 07-06-11 at 09:28 AM ----------

The full explanation (including why this applies to ssh too) is at: http://mywiki.wooledge.org/BashFAQ/089
 
1 members found this post helpful.
  


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
bash script, special charaters stopping cp zebrapositions Programming 11 09-20-2009 03:04 AM
A Personal BASH FFmpeg Batch Script (WIP) kDest Programming 9 04-24-2009 10:11 AM
Can't get ffmpeg to encode to msvideo1 dougwo Linux - Software 2 11-06-2008 09:51 AM
Bash script stop CTRL+C stopping joshiggins Linux - Software 2 06-12-2008 03:45 AM
Encode wma using ffmpeg ordealbyfire83 Linux - Software 2 09-15-2007 04:32 AM

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

All times are GMT -5. The time now is 12:23 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