diff options
Diffstat (limited to 'bin/guiscripts/record')
| -rwxr-xr-x | bin/guiscripts/record | 86 | 
1 files changed, 86 insertions, 0 deletions
diff --git a/bin/guiscripts/record b/bin/guiscripts/record new file mode 100755 index 0000000..778e02e --- /dev/null +++ b/bin/guiscripts/record @@ -0,0 +1,86 @@ +#!/bin/sh + +# record - record an area of the screen + +lock="/tmp/record.lock" + +# dependencies: ffmpeg, hacksaw (part), xwininfo & lsw (window), xdotool (active)  +# optional: +# 	- hacksaw: part +# 	- xwininfo, lsw, commander: window +# 	- xdotool: active +# 	- xdg-user-dir + +# $1: width +# $2: height +# $3: x +# $4: y +# $5: output dir +# $6: output name +record_cmd() +{ +	if [ -f "$lock" ]  +	then +		>&2 printf 'already recording, please stop recording first\n' +		exit 1 +	else +		touch "$lock" +	fi + +	herbe "started recording." & +	w=$(($3 + $3 % 2)) +	h=$(($4 + $4 % 2)) +	ffmpeg               \ +	    -v 16            \ +	    -r 30            \ +	    -f pulse -ac 2 -i default   \ +	    -f x11grab       \ +	    -s "${w}x${h}"   \ +	    -i ":0.0+$1,$2"  \ +	    -preset slow     \ +	    -c:v h264        \ +	    -pix_fmt yuv420p \ +	    -crf 20          \ +	    "$5/$6.mp4" +	printf '%s\n' "$5/$6.mp4" +	rm -f "$lock" +	herbe "stopped recording." &  +} + +if [ -d "$1" ] +then +	dir="$1"  +	shift +else  +	dir="$(which xdg-user-dir > /dev/null 2>&1 && xdg-user-dir VIDEOS)" +	[ "$dir" ] && dir="$dir/records" || dir="$HOME/vids/records" +fi +mkdir -p "$dir" + +current=$(date +%F_%H-%M-%S) + +[ "$1" ] && option="$1" || option="$(printf 'active\nwindow\npart\nstop\nfull\n' | commander -c)" +case "$option" in +    active) +        record_cmd $(xwininfo -id "$(xdotool getactivewindow)" | +            sed -e '/Absolute\|Width:\|Height:/!d;s/.*:\s*//' | tr '\n' ' ') $dir $current +        ;; + +    window) +    	winid="$(lsw | commander -cxl | cut -d' ' -f1)" +    	[ "$winid" ] || exit 1 +    	values="$(xwininfo -id "$winid" | sed -e '/Absolute\|Width:\|Height:/!d;s/.*:\s*//' | tr '\n' ' ')" +	[ "$values" ] || exit 1 +        record_cmd $values $dir $current +        ;; +         +    part)  +        hacksaw | { +            IFS=+x read -r w h x y +            record_cmd $w $h $x $y $dir $current +        } +        ;; +    stop) kill "$(pgrep ffmpeg | xargs ps | grep 'x11grab' | awk '{print $1}')"; rm -f "$lock" ;; +    full) record_cmd 0 0 1920 1080 $dir $current ;; +    help|*) >&2 printf 'record [dir] (active|window|part|stop|full)\n' ;; +esac  | 
