Register
It is currently Mon Oct 20, 2014 11:58 am

While loop NOT looping


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Thu Dec 02, 2010 12:10 pm   

Joined: Tue Nov 16, 2010 4:11 am
Posts: 5
Sorry if this is simple but I'm learning still so please keep the flaming to a minimum that would be brill.

What I'm trying to do is batch convert files with ffmpeg so far i know that the while loop is working (as i have tested it with echo(S) and i used the same algorithm to Mass install / uninstall software with the apt-get command) but whenever i try and interact with ffmpeg it crashes out of the loop after doing one conversion. I have a feeling it is that ffmpeg is still working on something when it goes through the loop again, i have tried adding a wait and a sleep to no avail.

any help would be gratefully received,
thanks again

code:

`ls *.MPG >>TMP`
CNT=1
FILENAME="TMP"
while read APP
do
echo "File $APP converted to vid$CNT"
ffmpeg -i $APP VID$CNT.WMV
wait
echo "Done $CNT"
CNT=$(( CNT + 1 ))
done < $FILENAME
rm TMP
exit

PS: This is just a snippet of the code;


Top
 Profile  
 PostPosted: Thu Dec 02, 2010 1:15 pm   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
A tiny bit of flaming first: please use [ code ] tags when pasting your code. It makes it so much easier to read...
The code below is not tested, I just typed it in here... I hope it works better for you.

Code:
#!/bin/bash

CNT=0;
for SRC in *.MPG; do
  DST="VID$((CNT+=1)).WMV"
  echo "$(date +%T) Converting file $SRC to $DST"
  ffmpeg -i "$SRC" "$DST"
  echo "$(date +%T) File $SRC converted to $DST"
done


Top
 Profile  
 PostPosted: Thu Dec 02, 2010 2:05 pm   

Joined: Tue Nov 16, 2010 4:11 am
Posts: 5
Flame away my man all you like you have Fixed it! never thought of using a for loop!

Worked a charm! Could I ask where was I going wrong? I couldn't figure out no errors and it worked when I was echo's ?

PS. Love the terror from MTG!


Top
 Profile  
 PostPosted: Fri Dec 03, 2010 2:09 am   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
Sintex wrote:
Could I ask where was I going wrong? I couldn't figure out no errors and it worked when I was echo's ?

Did some file names contain spaces?


Top
 Profile  
 PostPosted: Fri Dec 03, 2010 7:55 am   

Joined: Tue Nov 16, 2010 4:11 am
Posts: 5
No the 2 test I/P files where ;
M2U00617.MPG
M2U00618.MPG

thanks


Top
 Profile  
 PostPosted: Wed Jul 06, 2011 3:46 am   

Joined: Wed Jul 06, 2011 3:44 am
Posts: 1
ffmpeg reads from stdin so the loop doesn't get fed. Adding < /dev/null to the ffmpeg command would have fixed this problem.

There's a full explanation at http://mywiki.wooledge.org/BashFAQ/089


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP