-
Notifications
You must be signed in to change notification settings - Fork 3
/
asciicast2gif
executable file
·110 lines (90 loc) · 2.59 KB
/
asciicast2gif
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env bash
set -e
export DEBUG=${DEBUG:-1}
path_to_self="${BASH_SOURCE[0]}"
# Detect path
if [ -L "$path_to_self" ]; then
asciicast2gif_dir="$(cd "$(dirname "$path_to_self")"/"$(dirname "$(readlink "$path_to_self")")" && pwd)"
else
asciicast2gif_dir="$(cd "$(dirname "$path_to_self")" && pwd)"
fi
if ! type "node" >/dev/null 2>&1; then
echo "error: Node.js not installed? Executable 'node' not found"
exit 1
fi
if [[ ! -f "${asciicast2gif_dir}/main.js" ]]; then
echo "error: ${asciicast2gif_dir}/main.js not found. Build it with: lein cljsbuild once main"
exit 1
fi
if [[ ! -f "${asciicast2gif_dir}/page/page.js" ]]; then
echo "error: ${asciicast2gif_dir}/page/page.js not found. Build it with: lein cljsbuild once page"
exit 1
fi
theme="asciinema"
speed=1
scale=2
width=""
height=""
while getopts ":w:h:t:s:S:" opt; do
case $opt in
t)
theme=$OPTARG
;;
s)
speed=$OPTARG
;;
S)
scale=$OPTARG
;;
w)
width=$OPTARG
;;
h)
height=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
shift $((OPTIND-1))
if (($# != 1)); then
echo "asciicast2gif - Generate GIF animations from asciicasts (asciinema recordings)"
echo
echo "usage: asciicast2gif [-t theme] [-s speed] [-S scale] [-w columns] [-h rows] <input-json-path-or-url>"
echo
echo "options:"
echo " -t <theme> color theme, one of: asciinema, tango, solarized-dark, solarized-light, monokai (default: asciinema)"
echo " -s <speed> animation speed (default: 1)"
echo " -S <scale> image scale / pixel density (default: 2)"
echo " -w <columns> clip terminal to specified number of columns (width)"
echo " -h <rows> clip terminal to specified number of rows (height)"
exit 1
fi
if [[ -n $width ]]; then
export WIDTH=$width
fi
if [[ -n $height ]]; then
export HEIGHT=$height
fi
case_id=$(basename -s .cast ${1})
tmp_dir=$HOME'/data/playlog/'$case_id
echo tmp_dir:${tmp_dir}
node \
$NODE_OPTS \
"${asciicast2gif_dir}/main.js" \
"${1}" \
$tmp_dir \
$theme \
$speed \
$scale
python time_process.py $tmp_dir"/tmp.time"
mp4_out_path=$tmp_dir'/result.mp4'
echo out_file:${mp4_out_path}
ffmpeg -f concat -safe 0 -i $tmp_dir'/result.time' -plays 0 $mp4_out_path -y
echo -e "\x1b[32m==> \x1b[0mDone."