[FFmpeg-user] strange ffmpeg effect on bash
cbeerse at gmail.com
cbeerse at gmail.com
Mon Apr 4 22:59:57 CEST 2011
On 4-4-2011 21:50, Lars Täuber wrote:
> Hi,
>
> I've got a problem with ffmpeg in a shell script.
> It's a bash script to be precise.
> The script looks like this:
>
> ===================
> #!/bin/bash
>
> LOG=${0%.sh}.log
> ERR=${0%.sh}.err
> JOBS=jobs.lst
>> "$LOG"
>> "$ERR"
> while read LINE
> do
> FILE=""
> NAME=""
> eval $LINE
>
> test -z "$NAME" -o ! -r "$FILE"&& continue
>
> ffmpeg -an -sn -i "$FILE" -vcodec ffvhuff -t 30 -f matroska -y "$NAME.mkv">>"$LOG" 2>>"$ERR"
> # mencoder -ovc copy -oac pcm -o "$NAME.avi" -endpos 30 "$FILE">>"$LOG" 2>>"$ERR"
> echo $?>> "$LOG"
>
> done< "$JOBS"
> echo "Ende">> "$LOG"
> ===================
>
> With the ffmpeg command the script ends after the first line read from "$JOBS". Somehow bash interpretes its completion like a »break« command.
> When you replace the ffmpeg command with the (commented out) mplayer command (or any other programm) all lines from "$JOBS" are read and interpreted as expected.
>
> The "$JOBS" file looks like this:
> ===================
> FILE=a.avi;NAME=b
> FILE=c.avi;NAME=d
> FILE=e.avi;NAME=e
> ===================
>
> How comes?
> What's the special thing here with ffmpeg?
I think (close to being sure) that ffmpeg does something with stdin and
stdout. Hence as you use that too, that can somehow somewhere get mixed
up the wrong way.
If you rewrite your script to read the file not using the stdin but
using one of the other I/Os:
while read -fd 3 LINE
do
# your code here is the same..
done 3< "$JOBS"
while read LINE <&3
do
# your code here is the same..
done 3< "$JOBS"
Or use the for command (might behave different with blanks/spaces in the
lines):
|
|for LINE in `cat "$JOBS"`
do
# your code here is the same
done
The above is rough code, not tested. It is about using one of the other
file descripters. e.g. advanced scripting.
> Maybe I should ask this on a bash mailing list?
I bet the bash list will point you to ffmpeg. However, the use of
alternate file descripters is definitly using bash. The question there
should be: I'd like to use my code but I expect ffmpeg is using the std
i/o. Ho can I get around that?
CBee
More information about the ffmpeg-user
mailing list