1

I'm working on a script that open a text file with some ffmpeg commands. ( about 10 command generated from an other project ) Each command are working when i copy paste than into the terminal manually, but when the script run, simple commands work but I am stuck on a " No such filter : ..." error.

Here is my command : -i 1.mp4 -i 2.mp4 -i 3.mp4 -i 4.mp4 -i 5.mp4 -i 6.mp4 -filter_complex '[0:0][0:1][1:0][1:1][2:0][2:1][3:0][3:1][4:0][4:1][5:0][5:1]concat=n=6:v=1:a=1:unsafe=1 [v] [a]' -map '[v]' -map '[a]' -aspect 16:9 -s 1280x720 -c:v mpeg4 -c:a libmp3lame -y track_0.mp4

I think all the problem is in the " ' " i try to escape them with " \' " but ffmpeg is telling me No such filter: '''

Here is my script assuming that the variable ARGS is set dynamically ( for the example I have set it manually ) :

#!/bin/bash
ARGS="-i 1.mp4 -i 2.mp4 -i 3.mp4 -i 4.mp4 -i 5.mp4 -i 6.mp4 -filter_complex '[0:0][0:1][1:0][1:1][2:0][2:1][3:0][3:1][4:0][4:1][5:0][5:1]concat=n=6:v=1:a=1:unsafe=1 [v] [a]' -map '[v]' -map '[a]' -aspect 16:9 -s 1280x720 -c:v mpeg4 -c:a libmp3lame -y track_0.mp4"
ffmpeg ${ARGS}

EDIT 1:

Well I forgot to precise that my text file is like that :

-loop 1 -f image2 -c:v png -i FILE_0.data -i sample.wav -map 0:v -map 1:a -t 20 -s 1280x720 -c:v mpeg4 -c:a libmp3lame  -pix_fmt yuv420p -y 4.mp4
-loop 1 -f image2 -c:v png -i black.png -i sample.wav -map 0:v -map 1:a -t 14 -s 1280x720 -c:v mpeg4 -c:a libmp3lame  -pix_fmt yuv420p -y 5.mp4
-loop 1 -f image2 -c:v png -i FILE_1.data -i sample.wav -map 0:v -map 1:a -t 20 -s 1280x720 -c:v mpeg4 -c:a libmp3lame  -pix_fmt yuv420p -y 6.mp4
-i 1.mp4 -i 2.mp4 -i 3.mp4 -i 4.mp4 -i 5.mp4 -i 6.mp4 -filter_complex '[0:0][0:1][1:0][1:1][2:0][2:1][3:0][3:1][4:0][4:1][5:0][5:1]concat=n=6:v=1:a=1:unsafe=1 [v] [a]' -map '[v]' -map '[a]' -aspect 16:9 -s 1280x720 -c:v mpeg4 -c:a libmp3lame -y track_0.mp4

And in this file I read each line and I pass the line to ffmpeg to process what i want

Can you help me ?

1 Answer 1

4

Well, let's have a look:

$ shellcheck yourscript
ARGS="-i 1.mp4 -i 2.mp4 -i 3.mp4 -i 4.mp4 -i 5.mp4 -i 6.mp4 -filter_complex '[0:0][0:1][1:0][1:1][2:0][2:1][3:0][3:1][4:0][4:1][5:0][5:1]concat=n=6:v=1:a=1:unsafe=1 [v] [a]' -map '[v]' -map '[a]' -aspect 16:9 -s 1280x720 -c:v mpeg4 -c:a libmp3lame -y track_0.mp4"
      ^-- SC2089: Quotes/backslashes will be treated literally. Use an array.

In yourscript line 3:
ffmpeg ${ARGS}
       ^-- SC2090: Quotes/backslashes in this variable will not be respected.

As suggested, let's use an array:

#!/bin/bash
args=(
  -i "1.mp4"
  -i "2.mp4" ... 
  -filter_complex '[0:0][0:1][1:0][1:1][2:0][2:1][3:0][3:1][4:0][4:1][5:0][5:1]concat=n=6:v=1:a=1:unsafe=1 [v] [a]' 
  -map '[v]' 
  -map '[a]' 
  -aspect 16:9
  ....
)
ffmpeg "${args[@]}"

Obviously this works equally well if you build the array dynamically, e.g. with

args=()
for f in 1.mp4 2.mp4
do
  args+=(-i "$f")
done
...

To explain why this works, here's what you expected would happen:

  1. Bash sees ffmpeg $ARGS
  2. Bash substitutes the variable, giving ffmpeg -i 'my arg'
  3. Bash interprets the new command, giving the argument list

    ffmpeg, -i, my arg

  4. Bash runs ffmpeg with these two arguments

This is what actually happens:

  1. Bash sees ffmpeg $ARGS
  2. Bash interprets it and splits it into the arguments

    ffmpeg $ARGS

  3. Bash sees that one of the arguments is an unquoted variable, so it splits the value of the variable on spaces and puts each word into a separate argument:

    ffmpeg, -i, 'my, file'

  4. Bash runs ffmpeg with these three arguments, which now contain garbage single quotes.

Sign up to request clarification or add additional context in comments.

5 Comments

I forgot one thing look my first post and you will understand
@GuillaumeVillena What thing?
As I said, I read a text file with all the args that I need to pass to ffmpeg, and I just post an example of my file.
@GuillaumeVillena That's a fragile and insecure way to do it. If you really, seriously want to do it anyways, you can use eval "ffmpeg $ARGS".
sorry, I did not understand what you said because I misread your very good explanation ( sorry I am french and I have some difficulties with english )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.