It is currently Thu, 20 Jan 2022 09:40:42 GMT



 
Author Message
 while-loop stops looping
Hello all,

given the shell script below (it converts a bunch of mp3 files to
wav), the while loop DOES loop when I only echo filenames, but DOES
NOT loop when the conversion program 'ffmpeg' is executed: it
processes only one single file and then stops. So, only echoing gives:

processing 000003.mp3
done
processing 000004.mp3
done
processing 000005.mp3
done
processing 000006.mp3
done
processing 000007.mp3
done
processing 000008.mp3
done
processing 000008.mp3
done
all done

After uncommenting the conversion program I get:

processing 000003.mp3
Input #0, mp3, from '000003.mp3':
  Duration: 00:41:27.3, bitrate: 64 kb/s
  Stream #0.0: Audio: mp3, 44100 Hz, mono, 64 kb/s
Output #0, wav, to '000003.wav':
  Stream #0.0: Audio: pcm_s16le, 16000 Hz, mono, 256 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
Press [q] to stop encoding
size=   77729kB time=2487.3 bitrate= 256.0kbits/s  
0
done
all done

ffmpeg seems to work okay, at least it does not give any error messages and
the conversion has been accomplished succesfully. While debugging, all
mp3 files have been converted to wav now, but I am puzzled about this
behavior. Has anyone an idea what might go wrong? I looks like if the
find job is killed by ffmpeg, how can that be? By the way, I run this
script on linux with suse8.2.

#############################################
#!/bin/sh

DIR=$HOME/whatever
DATA=$DIR/data

find $DATA -follow -name "*.mp3" -print |\
while read i
do
  base=$DATA/`basename $i .mp3`
  if [ ! -s $base.wav ]
  then
    echo "processing $i"
    ffmpeg -i $i -ab 16 -ar 16000 -ac 1 $base.wav
    echo $?
    echo "done"
  fi
done
echo "all done"

-- roeland



 Sat, 09 Sep 2006 17:41:26 GMT   
 while-loop stops looping

Try verbose debugging with #!/bin/sh -xv
HTH

--
Brian Gough

Network Theory Ltd,
Publishing Free Software Manuals --- http://www.network-theory.co.uk/



 Sat, 09 Sep 2006 18:55:25 GMT   
 while-loop stops looping

Running in verbose debugging mode did not provide any clues, but thanks
anyway Brian. I am convinced now that the problem comes from ffmpeg.
When I take 'lame' instead of 'ffmpeg' the while-loop continues as
expected. My question is now:
- what is ffmepg doing that it ruins the scripts' execution
- is there a way to prevent this behavior (I would like to keep ffmpeg
as it does the decoding mp3-1616wav job right, I already tried putting
the ffmpeg line in a script of its own, without success )

#-------------------------------
#!/bin/sh
set -xv
DIR=$HOME/whatever
DATA=$DIR/data

find $DATA -follow -name "*.mp3" -print |\
while read i
do
  base=$DATA/`basename $i .mp3`
  if [ ! -s $base.wav ]
  then
    echo "processing $i"
    lame $i --decode $base.wav                                          
  # while-loop continues as expected  
    #ffmpeg -i $i -ab 16 -ar 16000 -ac 1 $base.wav            #
while-loop stops after running ffmpeg
    echo $?
    echo "done"
  fi
done
echo "all done"
#-------------------------------



 Sat, 09 Sep 2006 19:30:56 GMT   
 while-loop stops looping
  ^^^^^^^^^^^^^^^^^^^^^^^^^^
If it is attempting to read from stdin, it could be discarding the
remaining input from the original find command.

--
Brian Gough

Network Theory Ltd,
Publishing Free Software Manuals --- http://www.network-theory.co.uk/



 Sat, 09 Sep 2006 22:27:53 GMT   
 while-loop stops looping

Try using a for loop instead, e.g.:

for i in `find $DATA -follow -name "*.mp3" -print`

That way your loop won't rely on reading stdin so shouldn't care what ffmpge
does with it. Caveat: this approach wouldn't work in your file names contain
spaces.

        Ed.



 Sun, 10 Sep 2006 00:19:42 GMT   
 while-loop stops looping

Almost certainly 'ffmpeg' is reading from standard input, which is
absorbing the rest of the output from 'find'.

Append '</dev/null' to the ffmpeg line.



 Mon, 11 Sep 2006 03:49:12 GMT   
 while-loop stops looping
Dnia 2004-03-23, Roeland Ordelman napisal:

#!/bin/sh

DIR=$HOME/whatever
DATA=$DIR/data

find $DATA -follow -name "*.mp3" -exec sh -c "base=$DATA/"'`basename {} .mp3`
  if [ ! -s $base.wav ]; then
    echo processing {}
    ffmpeg -i {} -ab 16 -ar 16000 -ac 1 $base.wav
    echo $?
    echo done
  fi' \;
echo All done
EO#!

This little trick doesn't work under Solaris' find, because it
substitutes for {} only if {} is single argument, i.e.
find . -name ble -exec echo "{} is OK" \;
prints few "{} is OK" lines, not "ble is OK". But you're running SuSE,
and my "trick" works fine with GNU find :)

--
Stanislaw Klekot



 Wed, 13 Sep 2006 02:49:48 GMT   
 
   [ 7 post ] 

Similar Threads

1. Stuck in a loop, stuck in a loop, ...

2. break one loop and skip one iteration of outer loop

3. add loop control to skip comments in while loop

4. loop in a loop?

5. looping on couplets in for loop?

6. loopy loop loop

7. Stopping a loop

8. stopping the evil gdm loop

9. Mount compressed file as a loop device (mount -o loop.. )


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software