cd / mkdir REPOSITORY && cd REPOSITORY mkdir DVR && cd DVR (bash script: dvr_to_youtube.sh) nano dvr_to_youtube.sh #!/bin/bash ######### Lock checker ########### myName="`echo $0 | awk '{print $NF}' FS='/'`" lockDir="/var/lock/" lockFile=$lockDir$myName.pid currentPID=$$ oldPID="`cat $lockFile`" oldderExist=` kill -0 $oldPID 2>/dev/null ; echo $? ` if [ "$oldderExist" == "0" ]; then echo "An Other Instance Is Running...! PID:$oldPID" ; exit ; else echo $currentPID > $lockFile ; fi ######### Lock checker ########### while true do if [ -z "$1" ]; then RTSPIP=<my_opened_ip_to_connect_with_camera> USER=<name>; PASS=<password> RTSPPORT=<enabled_port> else IP_ADDRESS=$1 fi RTSPNAME=camera2 DIR=/REPOSITORY/DVR URL=https://a.upload.youtube.com/http_upload_hls STREAM=<your_key_from_youtu.be> # FFMPEG command for creating segments from RTSP stream ffmpeg -rtsp_transport tcp -i rtsp://$USER:$PASS@$RTSPIP:$RTSPPORT/trackID=2 -f lavfi -i anullsrc -c:v copy -c:a aac -map 0:v -map 1 -f hls -hls_time 4 -hls_playlist_type event -method PUT 'https://a.upload.youtube.com/http_upload_hls?cid=$STREAM©=0&file=stream.m3u8' sleep 5 done (making service) nano dvr_youtube.service [Unit] Description=DVR to YOUTUBE [Service] ExecStart=/REPOSITORY/DVR/dvr_to_youtube.sh Restart=on-failure [Install] WantedBy=multi-user.target chmod +x /REPOSITORY/DVR/dvr_to_youtube.sh ln -s /REPOSITORY/DVR/dvr_youtube.service /lib/systemd/system/dvr_youtube.service systemctl enable dvr_youtube.service systemctl start dvr_youtube.service systemctl status dvr_youtube.service