Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash script stops execution of ffmpeg in while loop - why?

I have this bash script for converting .mp4 video to .mp3 audio. It runs, but does the loop only once, though there are more mp4 files in /home/myname/mp4dir.

The script converts the first .mp4 file it finds to .mp3, unless there is already an .mp3 file. This should be done in a loop, but after the first call to ffmpeg the script stops.

Why?

#!/bin/bash
find /home/myname/mp4dir -name "*.mp4" | while read f
do
        fOut=`echo $f | sed s/mp4/mp3/`
        echo "convert $f => $fOut"
        if ! test -f $fOut
        then
                ffmpeg -i $f -vn -f mp3 $fOut
        fi
done
like image 311
Alex Monthy Avatar asked Dec 06 '22 12:12

Alex Monthy


2 Answers

The answer is to add -nostdin to ffmpeg (wouldn't answer to an old question like this, but still tops on related Google searches).

like image 133
Sandor Marton Avatar answered Dec 23 '22 21:12

Sandor Marton


try this in terminal

create bash nohup.sh and paste in this

#!/bin/sh
while true
do
 /var/www/bash/Someother-bash-script-goes-here.sh
 sleep 60
done

in terminal type where nohup.sh is located

nohup sh nohup.sh >/dev/null 2>&1 &

nohup, will execute every 60 seconds, you can grep service check like this

 #!/bin/sh
SERVICE='ffmpeg'

if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
    echo "$SERVICE service running, will not bother ffmpeg yet"
else
    echo "$SERVICE is not running"
    echo "$SERVICE is not running!" | /var/www/bash/start_service.sh
fi
like image 28
kendosan Avatar answered Dec 23 '22 21:12

kendosan