-
Notifications
You must be signed in to change notification settings - Fork 0
/
video_to_gif.sh
executable file
·66 lines (54 loc) · 1.36 KB
/
video_to_gif.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
input_file=
output_file=
skip_seconds=
to_seconds=
fps=15
scale=480
while getopts ":i:o:s:t:f:z:" opt; do
case $opt in
i) input_file="$OPTARG" #input
;;
o) output_file="$OPTARG" #output
;;
s) skip_seconds="$OPTARG" #skip seconds
;;
t) to_seconds="$OPTARG" #to seconds
;;
f) fps="$OPTARG" #fps
;;
z) scale="$OPTARG" #zoom / scale
;;
\?) echo "Invalid option -$OPTARG" >&2
exit 1
;;
esac
case $OPTARG in
-*) echo "Option $opt needs a valid argument"
exit 1
;;
esac
done
if [[ $# -eq 0 ]]; then
help_message="Use the following options:
-i: input file [mandatory]
-o: output file [mandatory]
-s: skip seconds [optional, default none]
-t: to seconds [optional, default none]
-f: fps [optional, default 15]
-z: scale [optional, default 480]"
echo "$help_message"
exit 0
fi
if [[ -z $input_file ]]; then
echo "input file required. use -i"
exit -1
fi
if [[ -z $output_file ]]; then
echo "output file required. use -o"
exit -1
fi
echo "Generating to gif..."
ffmpeg -y -ss $skip_seconds -to $to_seconds -i $input_file -filter_complex "fps=$fps,scale=$scale:-1:flags=lanczos,split[s0][s1];[s0]palettegen=max_colors=32[p];[s1][p]paletteuse=dither=bayer" $output_file
file_size=$(stat -c %s $output_file)
echo "Output file size: $file_size bytes"