Gianluca
Gianluca

Reputation: 33

Close FFMPEG if connection with ipcam lost

this is my scrit that transmit a live camera rtsp stream to youtube rtmp stream.

The Script before start verify if connection with camera is alive.

The problem is during the process, if network connection lost ffmpeg remain in locked state.

It's possibile to close ffmpeg or restart task if connection with camera lost?

:LOOP
timeout /t 10
ping 192.168.1.11
IF ERRORLEVEL 1 goto exit
IF ERRORLEVEL 0 goto START
:START

ffmpeg  -f lavfi -i anullsrc -rtsp_transport tcp -i rtsp://192.168.1.11:10554/tcp/av0_0 -tune zerolatency -vcodec libx264 -t 12:00:00 -pix_fmt + -c:v copy -c:a aac -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/(secret code)

goto LOOP

Upvotes: 1

Views: 1860

Answers (2)

ffmpeg
ffmpeg

Reputation: 1

I found that ffmpeg compiled with cygwin will not be hung and will exit after timeout.

https://cygwin.com/packages/summary/ffmpeg.html

Upvotes: 0

Gianluca
Gianluca

Reputation: 33

This is the solution:

CHECK Task run every minutes If there is a problem with the connetection of camera, the process kill all istance off ffmpeg and restart the primary task.

@echo off
set "host=192.168.1.11"

ping -n 1 "%host%" | findstr /r /c:"[0-9] *ms"

if %errorlevel% == 0 (
    echo Success.
) else (
echo Camera offline il %date% alle ore %time% >>C:\Users\Gianluca\Desktop\script\log.txt
WMIC PROCESS WHERE "COMMANDLINE LIKE '%%ffmpeg%%'" call terminate
schtasks /Run /TN "webcam"

)

The primary task check the connetection of camera and if connection lost, close the windows.

:LOOP
set "host=192.168.1.11"

ping -n 1 "%host%" | findstr /r /c:"[0-9] *ms"

if %errorlevel% == 0 (
   goto START
) else (

exit

)
pause


:START

ffmpeg  -f lavfi -i anullsrc -rtsp_transport tcp -i rtsp://%host%:10554/tcp/av0_0 -tune zerolatency -vcodec libx264 -t 12:00:00 -pix_fmt + -c:v copy -c:a aac -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/code

goto LOOP

Upvotes: 1

Related Questions