#!/usr/bin/env sh
VIDEO_SIZE="1920x1080"
DISPLAY_NUM=":0.0"
AUDIO_SOURCE="default"
FPS="60"
OUTPUT_FILE="recording_$(date +%Y%m%d_%H%M%S).mkv"
AUDIO_BITRATE="128k"
record() {
    local out_file="${1:-$OUTPUT_FILE}"
    echo "Starting screen + mic recording..."
    echo "Resolution: $VIDEO_SIZE @ ${FPS}fps"
    echo "Audio source: $AUDIO_SOURCE"
    echo "Output: $out_file"
    ffmpeg -y \
        -thread_queue_size 1024 \
        -f x11grab -framerate "$FPS" -video_size "$VIDEO_SIZE" -i "$DISPLAY_NUM" \
        -thread_queue_size 1024 \
        -f pulse -i "$AUDIO_SOURCE" \
		-c:v h264_nvenc -preset p1 -rc vbr -cq 23 \
        -pix_fmt yuv420p \
        -c:a aac -b:a "$AUDIO_BITRATE" \
        -vsync 1 \
        "$out_file"
}
show_help() {
    echo "Usage: $0 record [output_file]"
}
if [ "$1" = "--record" ]; then
    record "$2"
else
    show_help
fi
