-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgifify
executable file
·56 lines (49 loc) · 1.12 KB
/
gifify
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
#!/usr/bin/env bash
# Check for tool dependencies
SELF_FULLPATH=`realpath $0`
SELF_DIR=`dirname $SELF_FULLPATH`
# Override default tool list, we only need these two
TOOLS=(ffmpeg)
# Does not depend on any other scripts
SCRIPTS=NONE
if [ ! -r $SELF_DIR/toolchecker ]; then
echo "toolchecker not found."
exit 1
else
. $SELF_DIR/toolchecker
fi
SOURCE=$1
if [ -z $2 ]; then
START=0
else
START=$2
fi
if [ -z $3 ]; then
DURATION=0
else
DURATION=$3
fi
FILENAME=$(basename "$SOURCE" | sed -e 's/^\(.*\)\..*/\1/g' -e 's/\ /_/g')
PALETTE="$FILENAME.png"
GIF="$FILENAME.gif"
# QUARTER FILM
#FPS=5.99
# HALF FILM
#FPS=11.988
FPS=23.98
WIDTH=640
#WIDTH=1280
FFMPEG_TIMES=""
if [ $START -ne 0 ]; then
FFMPEG_TIMES="-ss $START"
fi
if [ $DURATION -ne 0 ]; then
FFMPEG_TIMES="$FFMPEG_TIMES -t $DURATION"
fi
echo "$SOURCE"
echo "$START"
echo "$DURATION"
echo "$FILENAME"
echo "$GIF"
$FFMPEG -y $FFMPEG_TIMES -i "$SOURCE" -vf fps=$FPS,scale=$WIDTH:-1:flags=lanczos,palettegen $PALETTE
$FFMPEG $FFMPEG_TIMES -i "$SOURCE" -i $PALETTE -filter_complex "fps=$FPS,scale=$WIDTH:-1:flags=lanczos[x];[x][1:v]paletteuse" "$GIF"