javacv icon indicating copy to clipboard operation
javacv copied to clipboard

FFmpegFrameGrabber hangs on at the native method:av_read_frame

Open leifengfeng opened this issue 10 months ago • 4 comments

it seems to happen at the moment that camera has been turned off suddenly.

the jstack command show this:

"192.168.0.100:554" #82 prio=5 os_prio=0 cpu=3774013.63ms elapsed=97735.35s tid=0x00007fc6040012f0 nid=0x36f312 runnable [0x00007fc8469fe000] java.lang.Thread.State: RUNNABLE at org.bytedeco.ffmpeg.global.avformat.av_read_frame(Native Method) at org.bytedeco.javacv.FFmpegFrameGrabber.grabFrame(FFmpegFrameGrabber.java:1421) - locked <0x00000006e3c7a840> (a org.bytedeco.javacv.FFmpegFrameGrabber) at org.bytedeco.javacv.FFmpegFrameGrabber.grab(FFmpegFrameGrabber.java:1351) at org.bytedeco.javacv.FrameGrabber.grabAtFrameRate(FrameGrabber.java:786)

leifengfeng avatar Oct 19 '23 07:10 leifengfeng

Try to set a smaller timeout

saudet avatar Oct 19 '23 08:10 saudet

tks. would you tell me the default value of timeout please?I found that it hangs on for hours when I did not set timeout option. now I have set timeout option to 2 seconds like this: grabber.setOption("rw_timeout", "2000000"); I will watch if it works. thanks again~

leifengfeng avatar Oct 24 '23 01:10 leifengfeng

The default depends on the protocol that you're using: https://github.com/bytedeco/javacv/blob/master/samples/FFmpegStreamingTimeout.java

saudet avatar Oct 24 '23 02:10 saudet

When ffmpeg reads rtsp image frames normally, the timeout attribute is set to 1 second, rw_timeout attribute is 500 milliseconds, then If there is a network connection issue and the disconnection time exceeds this threshold, the grabber can jump out and release resources. If the network recovers before this threshold, the grabber cannot jump out and release resources

leifengfeng avatar Nov 22 '23 06:11 leifengfeng