sanchop22
sanchop22

Reputation: 2809

Starting Multiple FFmpeg Sessions

I want to start multiple FFmpeg sessions in a for loop. Here is my script:

# start recording for all cams
for i in `seq 1 ${CAM_NO}`
do
    /home/aydu/bin/ffmpeg -f video4linux2 -i /dev/video${i} -y -c:v libx264 -r 5 -s 320x240 -vf format=gray $DIR/CAM${i}_${DTIME}.avi -r 1/5 -vf format=gray -f image2 -updatefirst 1 $DIR/webcam${i}.jpeg
done

Problem is sessions don't start sequentially. For example second process starts if and only if the first process stops, closes, finishes or terminates.

How can i start multiple sessions?

Upvotes: 0

Views: 2089

Answers (1)

paxdiablo
paxdiablo

Reputation: 882206

If you want to run processes in parallel, you need to place an ampersand & at the end of the process execution line, to inform the shell you want it running in the background.

For example, this command runs the five processes in sequence (about ten seconds):

$ date;for i in 1 2 3 4 5;do sleep 2;done;date
Tue, Sep 10, 2013  4:05:32 PM
Tue, Sep 10, 2013  4:05:43 PM

Whereas this one only takes two seconds because they're running in parallel:

$ date;for i in 1 2 3 4 5;do sleep 2 & done;wait;wait;wait;wait;wait;date
Tue, Sep 10, 2013  4:05:45 PM
[1] 6116
[2] 4940
[3] 7040
[4] 6944
[5] 3592
[1]   Done                    sleep 2
[2]   Done                    sleep 2
[3]   Done                    sleep 2
[4]-  Done                    sleep 2
[5]+  Done                    sleep 2
Tue, Sep 10, 2013  4:05:47 PM

Upvotes: 2

Related Questions