#!/usr/bin/env bash
# shellcheck disable=SC1091

. "/home/oleg/.youtube-stream-key.sh"

ffmpeg                                                                                                  \
    -f x11grab -video_size 1920x1080 -r 30 -thread_queue_size 512 -i "$DISPLAY"                         \
    -f pulse -ac 2 -thread_queue_size 512 -i 'alsa_input.pci-0000_00_1b.0.analog-stereo'                \
    -f pulse -ac 2 -thread_queue_size 512 -i 'alsa_output.pci-0000_00_1b.0.analog-stereo.monitor'       \
    -filter_complex amix                                                                                \
    -y                                                                                                  \
    -c:v libx264                                                                                        \
    -qp 0                                                                                               \
    -pix_fmt yuv420p                                                                                    \
    -b:v 9000k                                                                                          \
    -g 60                                                                                               \
    -c:a libmp3lame -ar 44100                                                                           \
    -q:a 3                                                                                              \
    -r 30                                                                                               \
    -threads 4                                                                                          \
    -preset ultrafast                                                                                   \
    -f flv "rtmp://a.rtmp.youtube.com/live2/$KEY"
