This works in command line for a sequence of jpg to convert to a video.

cat *.jpg  | ffmpeg -f image2pipe -framerate 5 -i - -s 1280x720  ./HD720_out.mp4    

but doesn't work (except for first jpg) in a executable script temp.sh containing:

eval  cat "$1"  | ffmpeg -f image2pipe -framerate 5 -i - -s 1280x720  "./HD720_out.mp4" 

e.g. ./temp.sh *.jpg gives only the first file to video, not the sequence. What am I doing wrong? The command line works perfectly.


Simplified: $1 gets expanded to the first commandline argument of a script.

But before your script interprets the shell running temp.sh will first expand the asterisk * in ./temp.sh *.jpg, effectively resulting a in a commandline:

./temp.sh first.jpg second.jpg third.jpg 
             \_  $1

You have two options to get around this. The first (and preferred):

cat "$@" | ... 

will just use all command line paramters, not only the first one. You don't need eval for this one and shouldn't use it.

The second (where eval comes into play):

eval cat "$1"  |  

while calling the script with quoted parameters to avoid expansion:

 ./temp.sh '*.jpg' 
  • @Sven Thanks for amending my short explanation as you did. I was on mobile and a bit terse. – HBruijn Jun 2 '18 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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