-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvid2gif
executable file
·38 lines (27 loc) · 971 Bytes
/
vid2gif
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
#!/bin/sh
set -x
if [ $# != 4 ]; then
echo "Usage: $0 start duration movie gif"
exit 1
fi
start="$1" # 00:00:00.000
duration="$2" # 00:00:10.000
movie="$3"
gif="$4"
# tweak ffmpeg
# export AV_LOG_FORCE_NOCOLOR=1
# export FFREPORT="level=warning:"
# set -x
width=$(ffmpeg -i "${movie}" 2>&1 | grep -i video | perl -pe 's/^.* (\d\d\d+)x\d\d\d+[, ].*/${1}/;')
# temp files
palette="`mktemp -t vid2gif`.png"
filters="fps=15,scale=${width}:-1:flags=lanczos"
# get best pallette
ffmpeg -hide_banner -accurate_seek -loglevel warning -ss "${start}" -t "${duration}" -i "${movie}" \
-vf "${filters},palettegen" -y $palette
ffmpeg -hide_banner -accurate_seek -loglevel warning -ss "${start}" -t "${duration}" -i "${movie}" \
-i "${palette}" -filter_complex "${filters} [x]; [x][1:v] paletteuse" -y "${gif}"
# ffmpeg -accurate_seek -ss "${start}" -t "${duration}" -i "${movie}" -pix_fmt rgb24 -r 30 "${gif}"
echo "Finished $gif"
# clean up temp files
rm "${palette}"