How can I complete a repetitive task?

I’m making gifs where I first extract .png from a video (using ffmpeg) then I convert those .png to gif
(using gifski) then I wanna remove those .png using (rm *.png) .someone told me I can do repetitive task with scripts but I don’t how to write a script
I know there could be many ways to make gifs but at this point I’m thinking it’s finally time to learn script
I have following commands

ffmpeg -ss 00:05:24.635 -i vid.mp4 -t 01.999 /mnt/dght/directory%01d.png

gifski -o /mnt/dght/directory/a1.gif -r 20 -Q 100 -W 600 -H 337 /mnt/dght/directory/*.png 

rm *.png

But everytime -ss and -t value will be different in ffmpeg. And gif name will be different in gifski command

The short answer is arguments or parameters

Example - a script taking one argument

#!/bin/bash
if [[ -z $1 ]]; then
    echo "Argument 1 is missing"
    exit
fi

echo "Hi there ..."
echo "I am the first argument '$1'"

To use your example - you already decided which is variable - you could create a file like

#/bin/bash
# ss is $1
# t is $2
#filename is $3

#ffmpeg -ss 00:05:24.635 -i vid.mp4 -t 01.999 /mnt/dght/directory%01d.png
ffmpeg -ss $1 -i vid.mp4 -t $2 /mnt/dght/directory%01d.png
#gifski -o /mnt/dght/directory/a1.gif -r 20 -Q 100 -W 600 -H 337 /mnt/dght/directory/*.png 
gifski -o /mnt/dght/directory/$3 -r 20 -Q 100 -W 600 -H 337 /mnt/dght/directory/*.png 

rm *.png

Then call it

my-script '00:05:24.635' '01.999' 'a1.gif'
1 Like

Thank you so much

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.