dotfiles/bin/screenrecord

34 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
PID_FILE="/tmp/screencast.pid"
SCREENCAST_FILE="$HOME/Videos/$(date +'%Y-%m-%d_%H:%M').mp4"
if [ ! -e ~/.dummy.aac ]; then
ffmpeg -f lavfi -i anullsrc=r=11025:cl=mono -t 1 -acodec aac ~/.dummy.aac
echo "[+] dummy.aac generated"
fi
if [ -e $PID_FILE ]; then
kill -s INT "$(cat $PID_FILE)"
notify-send "Screen record was ended" -t 2000
# https://github.com/mwh/dragon
dragon "$(cat /tmp/screencast.filename)"
rm -- "${PID_FILE}"
else
geometry=$(slop -c 0.7411764705882353,0.5764705882352941,0.9764705882352941,0.1 \
-b 1.5 --color=255,0,255 -o -D -f "-video_size %wx%h -i :0.0+%x,%y")
if [ $? -eq 0 ] ;then
notify-send "Screen recording started" -i "$HOME/.config/dunst/icons/record.png" -t 1000
ffmpeg -y -thread_queue_size 65536 \
-f x11grab $geometry -i ~/.dummy.aac -c:a copy \
-c:v libx264 -vf "scale=force_original_aspect_ratio=decrease:force_divisible_by=2" -preset slow -crf 18 -pix_fmt yuv420p \
-fflags +bitexact -flags:v +bitexact -flags:a +bitexact \
"${SCREENCAST_FILE}" >/dev/null 2>/dev/null &
echo $! > $PID_FILE
echo "${SCREENCAST_FILE}" > /tmp/screencast.filename
else
notify-send "Screen record was canceled" -i "$HOME/.config/dunst/icons/cancel.png" -t 2000
fi
fi