3

I'm trying to let ffmpeg make a video of all pictures in a directory using the -pattern_type glob switch and "/foo/bar/*.jpg". This works well, if I execute the command manually für just one directory. For example:

ffmpeg -framerate 35 -pattern_type glob -i '/root/webcam_test/2018-07-21/*.jpg' -vf scale=1280:-1 -c -c:v libx264 -pix_fmt yuv420p /root/clips/out01_cut.mp4

However, if I do it in a bash script and set the path via a variable, according to ffmpegs output, the variable gets substituted correctly, but ffmpeg states that

'/root/webcam_test/2018-07-21/*.jpg': No such file or directory

The part of the script looks like this:

for D in `find /root/webcam_test/ -type d`
do
    [...]
    cmd="ffmpeg -framerate 35 -pattern_type glob -i '$D/*.jpg' -vf scale=1280:-1 -c -c:v libx264 -pix_fm                                 t yuv420p /root/clips/$d_cut.mp4"
    echo $cmd
[...]
done

Does anyone know how to make ffmpeg do its wildcard interpretation even if the path is constructed by a script and not just try to plainly use the given path? Best regards and thanks in advance

1

3 Answers 3

3

I had similar problem. My solution is to change directory before ffmpeg command and use pattern without directory. i.e.:

cd $D/;ffmpeg -framerate 35 -pattern_type glob -i "*.jpg" -vf scale=1280:-1 -c -c:v libx264 -pix_fmt yuv420p /root/clips/$D_cut.mp4
2

Either of these, quoted or not, work in my timelapse cron script:

$ ls -1 *.jpg
20190620_011712sm.jpg
$ TODAY=$(date +"%Y%m%d")
$ ffmpeg -y -v 24 -f image2 -pattern_type glob -i ${TODAY}_\*sm.jpg -r 12 -vcodec libx264 ${TODAY}.mp4 2>&1|col -b
$ ffmpeg -y -v 24 -f image2 -pattern_type glob -i "${TODAY}_*sm.jpg" -r 12 -vcodec libx264 ${TODAY}.mp4 2>&1|col -b

I don't know why, but I fought hard to use single quotes around the * char before I came upon this. ...Lack of sleep maybe?

1

By putting the bash variable inside single quotes, it does not get expanded. Try with double quotes:

ffmpeg -framerate 35 -pattern_type glob -i "$D/*.jpg" -vf scale=1280:-1 -c -c:v libx264 -pix_fmt yuv420p /root/clips/$D_cut.mp4
2
  • Hi Poshi, thanks for your input. This is why I have the command string written into $cmd first and then echoed. I'm pretty sure that this way, the variable gets expanded, because of the error output of ffmpeg I quoted in my OP '/root/webcam_test/2018-07-21/*.jpg': No such file or directory . The single quotes are needed by the the ffmpeg -pattern_type -i, which won't work without them. If I do not use the $cmd variable, the behaviour is like you describe it.
    – KlausPeter
    Aug 5, 2018 at 7:18
  • 1
    The single quotes are not needed by ffmpeg -pattern_type -i. You can check the documentation of ffmpeg and you will see that there are examples with double quotes (ffmpeg.org/ffmpeg-formats.html).
    – Poshi
    Aug 5, 2018 at 10:48

Your Answer

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

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