FFmpeg in a bash script ( quotes ) -


i'm working on script open text file ffmpeg commands. ( 10 command generated other project ) each command working when copy paste terminal manually, when script run, simple commands work stuck on " no such filter : ..." error.

here 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 problem in " ' " try escape them " \' " ffmpeg telling me no such filter: '''

here script assuming variable args set dynamically ( example have set 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 forgot precise text file :

-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 file read each line , pass line ffmpeg process want

can me ?

well, let's have 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 treated literally. use array.  in yourscript line 3: ffmpeg ${args}        ^-- sc2090: quotes/backslashes in variable not respected. 

as suggested, let's use 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 works equally if build array dynamically, e.g.

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

to explain why works, here's expected happen:

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

    ffmpeg, -i, my arg

  4. bash runs ffmpeg these 2 arguments

this happens:

  1. bash sees ffmpeg $args
  2. bash interprets , splits arguments

    ffmpeg $args

  3. bash sees 1 of arguments unquoted variable, splits value of variable on spaces , puts each word separate argument:

    ffmpeg, -i, 'my, file'

  4. bash runs ffmpeg these three arguments, contain garbage single quotes.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -