summaryrefslogtreecommitdiff
path: root/record
blob: 8fdbc4a7643993bcd5201882eba8210436cc33e7 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env bash

help() {
	# display help
	echo -e "
Usage: record [-h|-s|-m|-M|-n fileName]

Script to record screen. By default, this script records the primary monitor
and both microphone and headset audio.
If no file name is specified it defaults to the current timestamp.

Options:
 -h		Print this help message
 -s		Select the secondary monitor
 -m		Mute mic audio
 -M		Mute all audio
 -n		Enter file name for the video
"
}

primaryRes=$(xrandr | awk -F'[ +]' '/primary/ { print $4 }')
primaryOffset=$(xrandr | awk -F'[ +]' '/primary/ { print $5 }')
secondaryRes=$(xrandr | grep " connected" | awk -F'[ +]' '! /primary/ { print $3 }')

vidopts="-s $primaryRes -r 60 -probesize 32M -f x11grab -thread_queue_size 1024 -threads 0 -i :0+$primaryOffset"

audopts="-f alsa -thread_queue_size 1024 -ac 2 -ar 44100 -i hw:CARD=Creative,DEV=2 -f alsa -thread_queue_size 1024 -ac 2 -ar 44100 -i hw:CARD=Microphone,DEV=0 -filter_complex [1:a]volume=0.1,amix=inputs=2,aresample=async=1"

name=$(date "+%F-%H-%M-%S")

while getopts ":hsmMn:" option; do
	case $option in
		h) # print help menu
			help
			exit
			;;
		s) # select secondary screen
			vidopts="-s $secondaryRes -r 60 -f x11grab -i :0"
			;;
		m) # mute mic audio
			audopts="-f alsa -thread_queue_size 1024 -ac 2 -ar 44100 -i hw:CARD=Creative,DEV=2"
			;;
		M) # mute all audio
			audopts="-an"
			;;
		n) # enter a file name
			name=$OPTARG
			;;
		\?) # invalid option
			echo "Error: Invalid option -$OPTARG" >&2
			exit 1
			;;
		:) # empty optarg
			echo "Option -$OPTARG requires an argument" >&2
			exit
			;;
	esac
done

opts="-c:v libx265 -c:a libopus -b:a 128k -preset ultrafast"

ffmpeg $vidopts $audopts $opts "$HOME/vids/${name}.mkv"