-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathvid2gif.sh
executable file
·41 lines (41 loc) · 1 KB
/
vid2gif.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
usage="Convert video clip to GIF.
Usage: $(basename $0) [options] DEST
-i input video clip file.
-s (optional) resize, in W:H.
-r (optional) frame rate.
-b (optional) input video clip begins at position.
-t (optional) limit input video clip to duration.
"
while getopts ":hi:o:s:r:" opt; do
case "${opt}" in
h)
echo "${usage}"
exit
;;
i)
inputfile="${OPTARG}"
;;
s)
IFS=':' read -r -a size <<< "${OPTARG}"
;;
r)
fps="${OPTARG}"
;;
b)
ssopt=("-ss" "${OPTARG}")
;;
t)
topt=("-t" "${OPTARG}")
;;
\?)
echo "${opt} is not recognized."
echo "${usage}"
exit
;;
esac
done
shift $((OPTIND -1))
dest=$@
ffmpeg -i "${inputfile}" ${ssopt[@]} ${topt[@]} -vf "scale=${size[0]}:${size[1]}:flags=lanczos,palettegen=stats_mode=full" palette.png
ffmpeg -i "${inputfile}" -i palette.png ${ssopt[@]} ${topt[@]} -lavfi "fps=${fps},scale=${size[0]}:${size[1]}:flags=lanczos [x]; [x][1:v] paletteuse=dither=sierra2_4a" "${dest}"