Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to complete a batch of 3 videos to leave it there till morning processing but it seems there are special characters in it... I try it "raw" in the terminal and it works but in bash script it stops working


args1="-r 29.97 -t 00:13:30 -vsync 0 -vpre libx264-medium -i"
args12="-r 29.97 -ss 00:40:30 -vsync 0 -vpre libx264-medium -i"
args2="[in] scale=580:380 [T1],[T1] pad=720:530:0:50 (other arguments with lots of [ and ]"

In the output it says

Unable to find a suitable output format for 'scale=580:380' not sure why... like I said, the command runs fine in the command-line, just not in the script

/usr/local/bin/ffmpeg "$args1" "${file}"  -vf "$args2" "$args3" "${args[0]}_${startingfrom}_0001_02.mp4"
share|improve this question
Can you post a large section of your script? Seems to me like your problem is how you use args2. Do you write it out as $args2, or "$args2"? - definitely the square and round brackets could be a problem if unquoted. – asoundmove Apr 23 '11 at 4:14
I added the command I'm using, I'm still new in bash scripting so it's weird. Most of it is a loop and running that command with a counter, rm/mv commands – allenskd Apr 23 '11 at 4:28
You show us how you define args1,args12,args2 but you use args1,args2,args3 in your command. Which is correct? – glenn jackman Apr 23 '11 at 17:14
they are all correct, args3 just states the audio codec and video codec, nevertheless, I couldn't find the problem therefore I just migrated the script to python using os.system, got everything working in less than an hour... Bash script is interesting but sure takes time to know it.... – allenskd Apr 24 '11 at 0:03

Don't put more than one argument in a variable, it will work for very simple cases, but otherwise give you nothing but grief. Use arrays instead. E.g.

outfile=${infile%.*}.mp4  # video.mp4
    -r 29.97 
    -t 00:13:30 
    -vsync 0 
    -vpre libx264-medium 
    -vf "[in] scale=580:380 [T1],[T1] pad=720:530:0:50"
ffmpeg -i "$infile" "${args[@]}" "$outfile"

(The quotes are important)

In this case though, you might want a function instead. It's hard to say, since your question is a bit vague.

See BashFAQ 50

share|improve this answer

In this case, where you want $argsN to be passed to ffmpeg as multiple arguments you actually don't want to quote it. To be clear, you do want to quote the line where you are setting it, so:

args1="-r 29.97 -t 00:13:30 -vsync 0 -vpre libx264-medium -i" 

Is correct. But the ffmpeg line should look something like this:

/usr/local/bin/ffmpeg $args1 "${file}"  -vf $args2 $args3 "${args[0]}_${startingfrom}_0001_02.mp4"

The problem here is that ffmpeg is expecting an array of arguments like this:

0: /usr/local/bin/ffmpeg
1: -r
2: 29.97
3: -t

When you quote the variable containing the arguments they are all sent in as a single argument like this:

0: /usr/local/bin/ffmpeg
1: -r 29.97 -t 00:13:30 -vsync 0 -vpre libx264-medium -i

Since ffmpeg has no single option, -r 29.97 -t 00:13:30 -vsync 0 -vpre libx264-medium -i it rightfully complains.

If you want to play around with being able to see how exactly your arguments are being passed you can use this simple shell script which prints each argument passed to it on a separate line:

echo "0: $0"
for argument in "$@"; do
    echo "${i}: $argument"
share|improve this answer
The problem starts with this line specifically, args2="\"[in] scale=580:380 [T1],[T1] pad=720:530:0:50\"" I tried using the escape backslash, several things, none works, the arguments are inside the bash script, not outside :( really troublesome, I also added the ffmpeg line you edited it didn't work – allenskd Apr 23 '11 at 16:01

Maybe you should try to define your args thus:

args2='[in] scale= .....'

(note the single quote as opposed to the double quote). Say how you get on.

share|improve this answer

It looks like $args1 and $args12 contain several options but $args2 looks like it should be a single value for the -vf option. So you should omit the quotes from $args1 and $args12 so they are subject to word splitting, but continue to quote $args2.

However, the error message you report "Unable to find a suitable output format for 'scale=580:380'" looks like it is coming from ffmpeg and not the shell.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.