The mistery of the script and the disappearing pipe.

Hi,

I have a little mystery.

I’m trying to convert a list of .mpg files to .avi using ffmpeg. For this, I’m using this construction:

while read FILES ; do
ffmpeg call
done < $0.lista

The list contains (for testing) 3 files, but it only does the first one. It seems as if the ffmpeg
call is capturing the pipe. If I replace that line with an echo, it runs perfect. If the ffmpeg call
has a syntax error and fails, the script runs correctly, passing the three files. But if ffmpeg
runs, then only one file is processed.

I have tried several incantations. I have replaced that line with a call to a second script; if that
second script contains the call to ffmpeg, then only one file is processed.

The complete script is this (simplified for testing purposes):


#!/bin/bash

PARAMETROS="-async 1 -t 3 -deinterlace -vcodec libxvid -acodec libmp3lame "
FINALPARAMS=" "
QSCALE=3


COUNT=0
TOTAL=0
while read FILES  ; do
# Loop to count the total number of files to process and checks that they exist.
# It also removes the destination.avi file (or ffmpeg stops).
FUENTE="$FILES.mpg"
DESTINO="$FILES.avi"
TOTAL=`expr $TOTAL + 1`

if ! test -f "$FUENTE" ; then
echo " Not found $TOTAL: "  $FUENTE
COUNT=`expr $COUNT + 1`
else
if test -f "$DESTINO" ; then
rm $DESTINO
fi
fi
done < $0.lista

# Aborts it one was not found
if test $COUNT -gt 0 ; then
echo "$COUNT files not found."
exit
else
echo "Found $TOTAL files."
fi


echo

TOTAL=0
while read FILES  ; do
# procesar los ficheros de cuatro en cuatro (cuatro cores)

FUENTE="$FILES.mpg"
DESTINO="$FILES.avi"
TOTAL=`expr $TOTAL + 1`
# echo "=====> " $COUNT.$TOTAL": " $FUENTE

echo $TOTAL" ===> " ffmpeg -i "$FUENTE" -qscale $QSCALE $PARAMETROS "$DESTINO" $FINALPARAMS
echo
time ffmpeg -i "$FUENTE" -qscale $QSCALE $PARAMETROS "$DESTINO" $FINALPARAMS


echo
echo

done < $0.lista


wait

echo
echo
echo "========== Done a total of " $TOTAL "files"



Cheers / Saludos,

Carlos E. R.
(from 11.2 x86_64 “Emerald” at Telcontar)

Not much help with ffmpeg but I’ve also seen this sort of thing happen with handbrake CLI program. I suspect it messes up the bash shell’s file descriptors or something. Sorry, no solution.

On 2010-10-26 02:36, ken yap wrote:
>
> Not much help with ffmpeg but I’ve also seen this sort of thing happen
> with handbrake CLI program. I suspect it messes up the bash shell’s file
> descriptors or something. Sorry, no solution.

Now it is just a curiosity, as I have made it by a roundabout way: I store the filenames in an
array, and use a for() loop to traverse the array.

So you have seen it with another program? Well, it is something that it is not me alone. Yesterday I
was pulling hairs.


Cheers / Saludos,

Carlos E. R.
(from 11.2 x86_64 “Emerald” at Telcontar)