#!/bin/sh

#PID=$(pidof ffmpeg)
#if [ -n "$PID" ]; then
#  pkill -SIGINT ffmpeg
#  pkill -SIGRTMIN+2 dwmblocks
#  notify-send "recording saved" -i :
#  exit
#fi
#
#SCREEN="ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi -s 3440x1440 -f x11grab -r 60 -i :0.0+0,0 "
#SYSTEM_AUDIO="-f pulse -i alsa_output.pci-0000_00_1f.3.iec958-stereo.monitor"
#MICROPHONE="-f pulse -i default:monitor"
#COMPRESSION="-c:a flac -vf format=nv12,hwupload -c:v av1_vaapi"
#FILENAME="$HOME/wdraidz/media/game-videos/$(date +%m-%d-%Y_%R:%S).mkv"
#SIGSEND="pkill -SIGRTMIN+2 dwmblocks"
#
#if [ $1 = 1 ]; then
#  $SCREEN $SYSTEM_AUDIO $COMPRESSION $FILENAME&
#  notify-send "recording started with no mic" -i :
#else
#  $SCREEN $SYSTEM_AUDIO $MICROPHONE -filter_complex "[1:0][2:0]amerge=inputs=2[a]" -map 0:v -map "[a]" $COMPRESSION $FILENAME&
#  notify-send "recording started" -i :
#fi
#
#$SIGSEND

# gpu-screen-recorder
GSRPID=$(pidof gpu-screen-recorder)
AUDIO="-ac opus -a default_output|default_input"
AUDIONOMIC="-ac opus -a default_output"
VIDEO="-w DisplayPort-1 -k av1 -c mkv -fm content -bm vbr"
OUTPUT="-o $HOME/wdraidz/media/game-videos/$(date +%m-%d-%Y_%R:%S).mkv"

if [ -n "$GSRPID" ]; then
  pkill -SIGINT -f gpu-screen-recorder
  pkill -SIGRTMIN+2 dwmblocks
  notify-send "recording saved" -i :
  exit
fi

if [ $1 = 1 ]; then 
  gpu-screen-recorder $VIDEO $AUDIONOMIC $OUTPUT&
  notify-send "recording started with no mic" -i :
else
  gpu-screen-recorder $VIDEO $AUDIO $OUTPUT&
  notify-send "recording started" -i :
fi

pkill -SIGRTMIN+2 dwmblocks
