blob: 79365e0613eea4aaddfc827480fbe61c0d2cd5c2 (
plain)
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
|
#!/bin/bash
set -eo pipefail
pidfile=/tmp/screencast.lock
if [ -e $pidfile ]; then
pid=$(cat $pidfile)
echo "Already running as ID $pid, now quitting"
rm $pidfile
kill -15 $pid
exit 0
fi
if [[ "$1" == "" ]]; then
echo "Usage: ${0##*/} <window-id>"
exit 2
fi
windowId=$1
tmpFile=/tmp/screencast-$(date +%s).mkv
paletteFile=/tmp/palette-$(date +%s).png
gifFile=/tmp/screencast-$(date +%s).gif
size=$(xdotool getwindowgeometry $windowId | grep Geometry | awk '{print $2}')
posX=$(xwininfo -id $windowId | grep 'Absolute upper-left X' | awk '{print $4}')
posY=$(xwininfo -id $windowId | grep 'Absolute upper-left Y' | awk '{print $4}')
pos="$posX,$posY"
ffmpeg -hide_banner -loglevel info -f x11grab -show_region 1 -video_size $size -i :0+$pos $tmpFile &
ffPID=$!
echo $ffPID >$pidfile
wait $ffPID && echo
ffmpeg -y -i $tmpFile -vf fps=10,palettegen $paletteFile
ffmpeg -i $tmpFile -i $paletteFile -filter_complex "paletteuse" $gifFile
rm $paletteFile $tmpFile
|