summaryrefslogtreecommitdiff
path: root/sh/reco
blob: 3580b966d3a04810b896acfc0e7ea7f5206090b8 (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
38
39
40
41
42
#!/bin/sh

# useful urls:
# https://github.com/LukeSmithxyz/voidrice/blob/master/.local/bin/dmenurecord
# https://wiki.archlinux.org/title/FFmpeg#Screen_capture
# https://trac.ffmpeg.org/wiki/Capture/Desktop

infofile="/tmp/recoinfo"
recodir="$XDG_VIDEOS_DIR/recordings/"
tmpdir="$recodir/tmp/"
mkdir -p "$recodir" "$tmpdir"

if [ -e "$infofile" ]; then
	read -r pid tmpfile < "$infofile"
	kill "$pid"
	notify-send 'finish recording, start converting'
	ffmpeg -i "$tmpfile" "$recodir/$(time-uuid).mkv"
	notify-send 'finish converting'
	rm "$tmpfile" "$infofile"
else
	tmpfile="$tmpdir/$(time-uuid).mkv"
	# arch wiki way, no audio, less cpu use during capturing (fast?), large file size, need convert afterward
	{
		case "$1" in
			# fullscreen
			'-f')
				printf '%s %s 0 0' "$SCR_WIDTH" "$SCR_HEIGHT"
				;;
			'')
				notify-send 'select recording region with mouse'
				xrectsel '%w %h %x %y'
				;;
			*) exit 1;;
		esac
		notify-send 'start recording after 2 seconds'
		sleep 2
		dunstctl close-all
	} | xargs sh -c 'ffmpeg -y -loglevel quiet -f x11grab -framerate 25 -s "$2x$3" -i "$DISPLAY+$4,$5" -c:v ffvhuff "$1" & echo $!' shell "$tmpfile" | xargs -I {} printf '%s\t%s' '{}' "$tmpfile" > "$infofile"
	# another way to get subshell ffmpeg child pid
	#xrectsel '%w %h %x %y' | xargs sh -c 'ffmpeg -y -f x11grab -framerate 25 -s "$2x$3" -i "$DISPLAY+$4,$5" -c:v ffvhuff "$1"' shell "$tmpfile" &
	#printf '%s\t%s' "$(ps -o pid= --ppid $!)" "$tmpfile" > "$infofile"
fi