#!/bin/bash

if [[ -z "$VOC_STREAMING_AUTH" ]]
then
    echo "[ERROR] failed to start stream, credentials missing!"
    exit 1
fi
if [[ -z "$VOC_ENDPOINT" ]]
then
    echo "[ERROR] failed to start stream, encoder endpoint missing!"
    exit 1
fi


ffmpeg -y -nostdin -hide_banner -re \
    -i "tcp://$VOC_ENDPOINT:15000?timeout=3000000" \
    -c:v libx264 \
    -r:v:0 10 -async 1 \
    -preset ultrafast -tune zerolatency \
    -c:a aac -b:a 192k -ar 48000 \
    -map 0:v:0 \
    -map 0:a:0 \
    -threads 0 \
    -f flv \
    "rtmp://a.rtmp.youtube.com/live2/$VOC_STREAMING_AUTH"