KlausPeter
KlausPeter

Reputation: 31

ffmpeg with "-pattern_type glob" and variable in bash script

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

Upvotes: 3

Views: 7049

Answers (3)

Steve
Steve

Reputation: 31

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?

Upvotes: 2

Trebla
Trebla

Reputation: 81

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

Upvotes: 3

Poshi
Poshi

Reputation: 5762

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

Upvotes: 1

Related Questions