#!/bin/bash

SERVICE="ffmpeg"
RTSP_URL="rtsp://192.168.0.119:554/video.pro1"
YOUTUBE_URL="rtmp://a.rtmp.youtube.com/live2"
YOUTUBE_KEY="dn7v-5g6p-1d3w-c3da"

COMMAND="sudo ffmpeg -f lavfi -i anullsrc -rtsp_transport tcp -i ${RTSP_URL} -tune zerolatency -vcodec libx264 -t 12:00:00 -pix_fmt + -c:v copy -c:a aac -strict experimental -f flv ${YOUTUBE_URL}/${YOUTUBE_KEY}"

if sudo /usr/bin/pgrep $SERVICE > /dev/null
then
        echo "${SERVICE} is already running."
else
        echo "${SERVICE} is NOT running! Starting now..."
        $COMMAND
fi