-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_to_gif.sh
executable file
·43 lines (37 loc) · 1.19 KB
/
convert_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
#!/bin/bash
# Author: Mikhail Nosov ([email protected])
# Convert video to HQ gif
# convert_to_gif.sh <source_video> <destination_gif> <start_time> <duration>
# Example usage:
# convert_to_gif.sh source_video.mp4 out_animation.gif "00:00:14" "00:00:10"
INFILE=${1}
OUTFILE=${2}
PALETE="/tmp/$(makepasswd --chars=20).png"
STARTPOS=${3:-"00:00:00"}
DURATION=${4:-"NONE"}
FPS=15
#SCALE=",scale=400:-1"
SCALE=",scale=-1:-1"
function convert {
INFILE=${1}
if [ ${DURATION} != "NONE" ];then
ffmpeg -ss ${STARTPOS} -t ${DURATION} -i "${INFILE}" -vf \
fps=${FPS}${SCALE}:flags=lanczos,palettegen ${PALETE}
ffmpeg -ss ${STARTPOS} -t ${DURATION} -i "${INFILE}" -i ${PALETE} \
-filter_complex "fps=${FPS}${SCALE}:flags=lanczos[x];[x][1:v]paletteuse" "${OUTFILE}"
else
ffmpeg -ss ${STARTPOS} -i "${INFILE}" -vf \
fps=${FPS}${SCALE}:flags=lanczos,palettegen ${PALETE}
ffmpeg -ss ${STARTPOS} -i "${INFILE}" -i ${PALETE} \
-filter_complex "fps=${FPS}${SCALE}:flags=lanczos[x];[x][1:v]paletteuse" "${OUTFILE}"
fi
}
if [ $# -gt 1 ];then
convert "${INFILE}"
else
echo $#
echo "Usage: $0 <input_file> <output_file>"
exit
fi
echo "Output file: ${OUTFILE}"
rm -v ${PALETE}