#! /usr/bin/env nix-shell
#! nix-shell -i bash -p ffmpeg
#
# Records screen and camera (in corner). Saves result to $VLOGDIR.
#
# c.f. https://gist.github.com/dpacmittal/9f0e1aea8a3732d8f7aec7b1dadc8cda
#
FILE=$(date +%Y.%m.%d..%H.%M)
DIR=${VLOGDIR:-/mnt/lake/ben/videos}
SIZE=1920x1080
if [ ! -d "$DIR" ]
then
    echo "error: $DIR does not exist"
    exit 1
fi
OUTFILE="$DIR/$FILE.mkv"
echo "recording to: $OUTFILE"
ffmpeg \
  -f alsa -i sysdefault:CARD=PCH \
  -f x11grab -video_size cif -framerate 48 -i :0.0+0.0 \
  -f video4linux2 -i /dev/video0 \
  -filter_complex '[2:v]scale=480:-1[cam];[1:v][cam]overlay=W-w-10:H-h-10' \
  -ab 192 -acodec pcm_s16le -qscale 0 \
  -c:v libx264 \
  -crf:v 18 \
  -c:a flac \
  -loglevel 40 \
  "$OUTFILE"