[FFmpeg-user] Trouble with ffmpeg in bash script
Gerion Entrup
gerion.entrup at t-online.de
Sun May 4 11:03:36 CEST 2014
Am Freitag 02 Mai 2014, 18:43:43 schrieb Georgi Chorbadzhiyski:
> On 02.5.2014 г. 16:13, Cortman wrote:
> > I have written a Bash script to recursively convert files of <format> to
> > mp3. I originally wrote it using an avconv command, but as I have compiled
> > ffmpeg for other purposes on the machine I would like to use ffmpeg in the
> > script instead.
> >
> > Here is the code of my script:
> >
> > #! /bin/bash
> >
> > set -e
> >
> > extension=$1
> >
> > if [ -z "$1" ] ; then
> > echo "You must provide the file extension as an argument"
> > fi
> >
> > files=$(find . -type f -name "*.$extension")
> >
> > while read -r line ; do
> > ffmpeg -i "$line" -c:a libmp3lame -q:a 0 "${line/%$extension/mp3}"
> > done <<< "$files"
>
> Always use
>
> ffmpeg .... < /dev/null
>
> in such scripts (loops with stdin input). ffmpeg also tries to read
> from stdin and this is where it goes wrong for you.
>
>
If this tip doesn't work, replace the ffmpeg line with echo "$line" and paste
the relevant part of "files" (echo $files) here.
Maybe settings the subshell command ($(find...) in "" also works.
Another hint: Always set $extension and $1 in "". This is user input, so an
evil user can insert shell code or other strings with whitespace here.
More information about the ffmpeg-user
mailing list