-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
xvfb.sh
executable file
·113 lines (103 loc) · 2.54 KB
/
xvfb.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
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
111
112
113
#!/bin/bash -eux
set -o pipefail
display=99
wxhxd=${WxHxD:-800x600x24}
bin=${BIN:-./bin/voidstar}
file=${FILE:-"$bin"}
out=video.${OUT:-webm}
case "$file" in
http://*|https://*)
curl -fsSLo /file "$file"
file=/file
;;*) ;;
esac
step=1024
filesize=$(stat --printf=%s "$file")
[[ "$filesize" -ge 9999999999 ]] && ((step*=2))
[[ "$filesize" -ge 999999999 ]] && ((step*=2))
[[ "$filesize" -ge 99999999 ]] && ((step*=2))
[[ "$filesize" -ge 9999999 ]] && ((step*=2))
[[ "$filesize" -ge 999999 ]] && ((step*=2))
rm -rf /tmp/xvfb-run.*
xvfb-run \
--server-num="$display" \
--error-file=/dev/stdout \
-s "-screen 0 $wxhxd" \
"$bin" \
--move \
--exit-at-fin \
--slide-step "$step" \
"$file" &
xvfb=$!
touch ~/.Xauthority
attempts=0
until ls /tmp/xvfb*/Xauthority >/dev/null; do
set +o errexit
xauth generate :0 . trusted
failed=$?
set +o errexit
xauth list
((attempts++))
[[ $attempts -eq 20 ]] && exit 2
[[ $failed -ne 0 ]] && sleep .1
done
touch stop
case "$out" in
*.webm)
<./stop \
XAUTHORITY=$(echo /tmp/xvfb*/Xauthority) \
ffmpeg \
-r 30 \
-f x11grab \
-draw_mouse 0 \
-s "$(cut -dx -f1-2 <<<"$wxhxd")" \
-i :"$display" \
-c:v libvpx \
-quality realtime \
-cpu-used 0 \
-b:v 384k \
-qmin 10 \
-qmax 42 \
-maxrate 384k \
-bufsize 1000k \
-an \
"$out" &
companion=$!
;;
*.mp4)
# WRT -pix_fmt yuv420p https://bugzilla.mozilla.org/show_bug.cgi?id=1368063#c7
<./stop \
XAUTHORITY=$(echo /tmp/xvfb*/Xauthority) \
ffmpeg \
-r 24 \
-f x11grab \
-draw_mouse 0 \
-s "$(cut -dx -f1-2 <<<"$wxhxd")" \
-i :"$display" \
-c:v libx264 \
-b:v 64k \
-crf 36 \
-preset veryslow \
-tune zerolatency \
-pix_fmt yuv420p \
-an \
"$out" &
companion=$!
;;
*)
echo "Unhandled video format for $out"
exit 1
esac
wait $xvfb
echo q >stop # https://stackoverflow.com/a/21032143/1418165
wait $companion
max_seconds=60
# Must be shorter than $max_seconds
duration=$(ffprobe -v error -show_format -show_streams -i "$out" | grep 'duration=' | head -n 1 | sed 's%duration=%%')
if [[ "$(echo "$duration < $max_seconds" | bc)" = 0 ]]; then
ffmpeg \
-i "$out" \
-filter:v "setpts=PTS/$(echo "1 + $duration / $max_seconds" | bc)" \
/tmp/"$out"
mv -v /tmp/"$out" "$out"
fi