I am trying to grab video from a webcam (using OpenCVFrameGrabber) and record it to a local file and streaming (rtmp) it by using two recorders at the same time (FFmpegFrameRecorder). I try to use the same grabbed frame, but when server connection is down, the code seems to hang on my invocation to the method record of the streaming recorder, which results in my local file missing frames (it perhaps has the same issue as described in #967 ). If I am unable to establish a connection to the streaming server at the beginning, I am able to catch an exception, but not in this case I just described.
Any suggestion on how to go around this issue?
We could set a timeout, thanks to @d-a-gerashenko we have some documentation for that here:
https://github.com/bytedeco/javacv/blob/master/samples/FFmpegStreamingTimeout.java
Thanks for the reference. Before starting this issue I had already tried to set the stimeout, which seemed to be ignored, and timeout, which resulted in the following log:
[rtmp @ 0x7f78a5625480] Cannot open connection tcp://**IP**:1935?listen&listen_timeout=**TIME**
It seems I missed the correct one: rw_timeout. It doesn't hang infinitely now, but I am still missing some frames on the recorder responsible for writing the local file. This seems to happen between the time when the streaming recorder loses server connection and the time when the timeout kicks in.
Well, that's pretty normal. You'll need to fix your network if you need better reliability.
I used the [testWithCallback()] method, but it does not take effect. When decoding, the network is disconnected, and eventually the program is blocked. Finally, the FrameGrabber.class is inherited, and Callback_Pointer is added to the inheritance class to take effect.
I am using streaming(rtmp),but it has a error,like this:
Exception in thread "main" org.bytedeco.javacv.FrameGrabber$Exception: read() Error: Could not read frame in start().
Have anyone know why?
@jeffreyhong0217 Probably just a problem with your network. Check the error message on the console.
@saudet Thanks for your reply!We developed in the LAN, the camera can be connected, but my javacv program connection is not successful!So I'm confused!
I won't be able to help you unless you give me the error message!
@saudet I have solved!Thanks again!