[FFmpeg-user] help with quotes in bash script

Oliver Fromme oliver at fromme.com
Wed May 21 09:59:04 CEST 2014


Elliott Balsley wrote:
 > I have a bash script for running ffmpeg, which broke when I added more
 > than one video filter (which required adding quotes).  Basically I
 > have several commands which append options to a long string called
 > $ffopts, then I call ffmpeg like this:
 > 
 > ffmpeg $ffpreopts -i "$f" -acodec libfdk_aac -b:a 128k $ffopts
 > "$output_dir/$base.mp4"
 > 
 > But it gives the below error.
 > 
 > [NULL @ 0x7f8473809200] Unable to find a suitable output format for
 > 'format=pix_fmts=rgb24,'
 > format=pix_fmts=rgb24,: Invalid argument
 > 
 > I think this is something to do with my use of quotes, but I can't
 > figure it out.  If I add a line in the script to echo $ffopts right
 > before running ffmpeg, it shows like this:
 > 
 > -vf "scale=hd720, format=pix_fmts=rgb24,
 > lut3d=file=/Users/elliott/scripts/BMD_LogC_709.dat,
 > format=pix_fmts=yuv420p" -vcodec libx264 -preset veryfast -tune film
 > -crf 20 -level 31 -profile:v high -g 8 -maxrate 4M -bufsize 10M

You need to get rid of the spaces inside the filter specification
of your $ffopts string, because the shell will split the arguments
at those spaces, breaking the filter chain.  Therefore you have to
look carefully where spaces are required and where they should not
be used.

For example, the following would work fine:

filter="scale=hd720"
filter="${filter},format=pix_fmts=rgb24"
filter="${filter},lut3d=file=/Users/elliott/scripts/BMD_LogC_709.dat"
filter="${filter},format=pix_fmts=yuv420p"

ffopts="-vf $filter -vcodec libx264 -preset veryfast -tune film"
ffopts="${ffopts} -crf 20 -level 31 -profile:v high -g 8"
ffopts="${ffopts} -maxrate 4M -bufsize 10M"

ffmpeg ... $ffopts "$output_dir/$base.mp4"

By the way, this is not bash-specific.  It works the same with
every bourne shell (a.k.a. POSIX shell).

Best regards
   Oliver

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


More information about the ffmpeg-user mailing list