S
S
Sergey Savostin2013-08-26 17:10:08
bash
Sergey Savostin, 2013-08-26 17:10:08

FFMPEG and incoming HTTP (mjpeg) stream break?

Can you please tell me how to implement an exit from ffmpeg when the incoming http stream from the ip-camera breaks?
Those. there is, say, the concept of a session: the camera turned on -> recording started, the camera turned off -> recording stopped, went into standby mode.
Now implemented like this:

#!/bin/bash
while true; do
    while true; do
        ping -c1 -o -n -W 1 192.168.1.4 > /dev/null 2>&1 && break;.
        sleep 5s;
    done
    now=`date +"%Y-%m-%d-%H-%M-%S"`
    ffmpeg -f mjpeg -shortest -i "http://192.168.1.4/stream.cgi" -timeout 30 cam1-${now}.avi
done

But neither timeout nor shortest give the desired effect - ffmpeg freezes completely when the stream disappears and only Ctrl-C saves.
You can record for 1 minute with the "-t 60" key, but I would not want to produce so many files, then glue them together, etc.
You can send ffmpeg to background with pid saved and send SIGINT when ping disappears, but you don't like it either.
I did not find the treasured key for ffmpeg.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
demimurych, 2013-08-26
@demimurych

hm. strange situation. Literally a month ago, I wrote from the camera just mjpeg, which stably fell off as soon as the connection was lost.
ffmpeg version 0.8.2.git, Copyright © 2000-2011 the FFmpeg developers
built on Sep 14 2011 18:29:34 with gcc 4.1.2 20080704 (Red Hat 4.1.2-50)

A
AlexeyNovikov, 2013-09-04
@AlexeyNovikov

Maybe the following information will help you
FreeBSD 9.1 ffmpeg 0.7.15,1 I
recently played ffmpeg with writing to a file. ffmpeg, like ffmpeg1, when an rtsp stream disappears for less than about 25 seconds, it resumes operation when it appears. The stream is interrupted by a reconnection of a non-PoE ethernet tail. If more than about 25 seconds pass with no communication with the camera, then ffmpeg exits on its own.
If ffmpeg is terminated not by pressing 'q', but by pressing 'ctrl+z', then it remains running and its subsequent launches with exits by 'ctrl+z' produce hanging ffmpeg processes. To get rid of them I use:
# killall -9 ffmpeg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question