4

I have an ffmpeg process which saves a stream from wowza server, but when the stream in wowza is interrupted for a second or so sometimes ffmpeg cycles in:

[segment @ 0x671a10] st:0 PTS: 9600015 DTS: 9600015 < 9629949 invalid, clipping
[segment @ 0x671a10] st:0 PTS: 9601935 DTS: 9601935 < 9629950 invalid, clipping
[segment @ 0x671a10] st:0 PTS: 9603855 DTS: 9603855 < 9629951 invalid, clipping
[segment @ 0x671a10] st:0 PTS: 9605775 DTS: 9605775 < 9629952 invalid, clipping
[segment @ 0x671a10] st:0 PTS: 9607695 DTS: 9607695 < 9629953 invalid, clipping
[segment @ 0x671a10] st:0 PTS: 9609615 DTS: 9609615 < 9629954 invalid, clipping
[segment @ 0x671a10] st:0 PTS: 9611535 DTS: 9611535 < 9629955 invalid, clipping
[segment @ 0x671a10] st:0 PTS: 9613455 DTS: 9613455 < 9629956 invalid, clipping
[segment @ 0x671a10] st:0 PTS: 9615375 DTS: 9615375 < 9629957 invalid, clipping
[segment @ 0x671a10] st:0 PTS: 9632160 DTS: 9614160 < 9649231 invalid, clipping
[segment @ 0x671a10] st:0 PTS: 9624960 DTS: 9617760 < 9649232 invalid, clipping
[segment @ 0x671a10] st:0 PTS: 9621360 DTS: 9621360 < 9649233 invalid, clipping

It never survives, even when the source is healthy and missed only a few seconds. It would be great if the ffmpeg can exit or restart (It is enough to exit on error. I can execute it in an endless while.) My command is:

ffmpeg -shortest -re -y -err_detect aggressive -i rtmp://127.0.0.1/movies/my.stream timeout=10 -codec copy -map 0 -bsf:v h264_mp4toannexb,dump_extra -f segment -segment_time 60 /video/my.stream#%09d.ts

I have tested with -err_detect explode/careful/compliant/aggressive and on error in the input stream ffmpeg did not stop. Sometimes it gets a timeout (because the timeout option I set for the rtmp), but some time it keep printing:

[segment @ 0x671a10] st:0 PTS: 9621360 DTS: 9621360 < 9649233 invalid, clipping

It never survives - no exits, no output, so I have no saved stream until I manually restart the ffmpeg!

4
  • What do you mean by "and never survives"? Does the video fail to produce anything or does it simply stop encoding? It isn't exactly clear what the error you are getting is from your description.
    – AJ Henderson
    Mar 7, 2014 at 1:38
  • The ffmpeg never stops and the there is no video produced. It just keep printing such lines....
    – neoX
    Mar 7, 2014 at 9:49
  • You should include the first ~50 lines and the last ~50 lines of your ffmpeg console output if possible.
    – llogan
    Mar 7, 2014 at 19:03
  • 1
    could you pipe stderr to another process that kills and restarts ffmpeg if it detects the "invalid, clipping" comment?
    – stib
    Mar 7, 2014 at 22:34

1 Answer 1

7

Although I am not sure if stderr will really help here because of the way that ffmpeg does its reporting, I can recommend the following pattern.

Use the -progress [url] flag and parse it with the tool of your choice every 100ms or so. Here is something to get you started that (with a little tweaking) might do what you want:

#!/bin/bash

touch /tmp/ffmpeg.log

ffmpeg -shortest -re -y -err_detect aggressive -i \ 
rtmp://127.0.0.1/movies/my.stream timeout=10 -codec copy \
-map 0 -bsf:v h264_mp4toannexb,dump_extra -f segment \
-segment_time 60 -progress /tmp/ffmpeg.log /video/my.stream#%09d.ts &

pid=$!

while true
    do
         # you'll might have to change "invalid" 
         # for whatever is being put into the progress log
         # just look at /tmp/ffmpeg.log to figure out what
         # grep should try to find 
         error=$(grep -n "invalid" /tmp/ffmpeg.log)

         # is the length of the error more than 0 / did grep find it???
         if (( ${#error} > 0 ))
             then
                 kill -9 $pid
                 ffmpeg -shortest -re -y -err_detect aggressive -i \ 
                 rtmp://127.0.0.1/movies/my.stream timeout=10 -codec copy \
                 -map 0 -bsf:v h264_mp4toannexb,dump_extra -f segment \
                 -segment_time 60 -progress /tmp/ffmpeg.log /video/my.stream#%09d.ts &
             pid=$!
         else
             usleep 100
         fi
    done
exit 0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.