summaryrefslogtreecommitdiff
path: root/toggle-screencast.sh
blob: d99b32ec83b4b70a54bb2a2dcbe22aa5b96f4001 (plain) (blame)
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
#!/bin/sh
output_dir=~/videos/screencasts
#sound_device=/dev/dsp4.0
#-thread_queue_size 512 -f oss -i "$sound_device" \

prompt_transcode() {
	choice=$(dmenu -p "Transcode now?" << EOF
no
yes
EOF
	)
	output_file="$output_dir"/cast_"$(date '+%F-%H-%M-%S')"
	if [ $choice == "yes" ]
	then
		transcode_now "$output_file".mp4
	else
		transcode_later "$output_file".mkv
	fi
}

transcode_now() {
	notify-send "Transcoding..." "$1"
	ffmpeg -i /tmp/cast.mkv "$1" && rm /tmp/cast.mkv
	notify-send "Transcode done!" "$1"
}

transcode_later() {
	mv /tmp/cast.mkv "$1"
	notify-send "Screencast saved!" "$1"
}

start_recording() {
	touch /tmp/cast.mkv
	notify-send -t 3000 "Starting screencast." "3...2...1..."
	sleep 4
	pkill -76 i3blocks
	ffmpeg -video_size 2560x1440 \
		-framerate 25 \
		-thread_queue_size 512 -f x11grab -i :0.0+0,0 \
		-vcodec libx264rgb -crf 0 -preset:v ultrafast \
		-acodec pcm_s16le \
		-af aresample=async=1:first_pts=0 \
		-y \
		/tmp/cast.mkv
}

stop_recording() {
	pkill -2 ffmpeg
	notify-send "Screencast stopped."
	prompt_transcode
	pkill -76 i3blocks
	exit
}

# main
mkdir -p "$output_dir"
[ -f /tmp/cast.mkv ] && stop_recording || start_recording