[FFmpeg-user] Batch Join multimono to multichannel Auido (wav /

Oliver Fromme oliver at fromme.com
Thu Jul 10 17:52:39 CEST 2014


Luigi Rensinghoff wrote:
 > i found the solution:
 > 
 > #!/bin/sh
 > 
 > for f in *C.aif;
 > do
 > 
 > #echo "Processing $f"
 > 
 > 
 > prefix=${f%}
 > pre=`echo $prefix | sed 's/.\{6\}$//'`
 > L=`echo $pre-\(L\).aif`
 > R=`echo $pre-\(R\).aif`
 > C=`echo $pre-C.aif`
 > LFE=`echo $pre-\LFE\.aif`
 > Ls=`echo $pre-S\(L\).aif`
 > Rs=`echo $pre-S\(R\).aif`
 > 
 > out=`${pre}_6ch.wav`
 > 
 > ffmpeg -i $L -i $R -i $C -i $LFE -i $Ls -i $Rs -filter_complex "[0:a][1:a][2:a][3:a][4:a][5:a]amerge=inputs=6[aout]" -map "[aout]" ${f%-C.aif}_6ch.wav
 > 
 > rm $L
 > rm $R
 > rm $C
 > rm $LFE
 > rm $Ls
 > rm $Rs
 > 
 > done
 > 
 > But i am sure it can be achieved more elegant - Suggestions ???

*sigh*
This is somewhat off-topic, but anyway, here is how I would do it:


#!/bin/sh

channels="L R C LFE Ls Rs"
filter="[0:a][1:a][2:a][3:a][4:a][5:a]amerge=inputs=6[aout]"

for f in *-C.aif; do
        #echo "Processing $f"

        pre="${f%-C.aif}"
        set --
        for c in $channels; do
                set -- -i "$pre-$c.aif"
        done
        out="${pre}_6ch.wav"

        ffmpeg "$@" -filter_complex "$filter" -map "[aout]" "$out"
        if [ $? -ne 0 ]; then
                echo "****  ffmpeg failed!  Not removing input files!"
                exit 1
        fi

        for c in $channels; do
                echo rm -- "$pre-$c.aif"
        done
done


Note that it is written in a way that all variables are protected
by quotes, so this works even if file names contain "unusual"
characters like spaces, tabs or newlines.

Also note that the rm command has been disabled by an echo
command.  I recommend you enable it only if you've tested the
script and you are sure that it does the right thing.  Unless
you have backup copies of the input files anyway, of course.

Best regards
   Oliver

-- 
``We are all but compressed light'' (Albert Einstein)


More information about the ffmpeg-user mailing list