summaryrefslogtreecommitdiff
path: root/toggle-screencast.sh
blob: dc26d637cb07a7ca5c02291474a6fef13c018c06 (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
#!/bin/sh

## Config
output_dir=~/videos/screencasts
sound_device=/dev/dsp6


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


## Stop recording
stop_recording() {
	pkill -2 ffmpeg
	output_file="$output_dir"/cast_"$(date '+%F-%H-%M-%S')".mkv
	mv /tmp/cast.mkv "$output_file"
	notify-send "Screencast saved" "$output_file"
	pkill -76 i3blocks
	exit
}


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