Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail With JavaCV not Responding RTSP in frameGrabber.start() #648

Closed
willagner opened this issue Mar 23, 2017 · 8 comments
Closed

Fail With JavaCV not Responding RTSP in frameGrabber.start() #648

willagner opened this issue Mar 23, 2017 · 8 comments
Labels

Comments

@willagner
Copy link

I have one program to get one video in protocol rtsp using JavaCV:

My program is like this:

public static void main(String[] args){

    FrameGrabber frameGrabber = new 

    FFmpegFrameGrabber("rtsp://ip:port/login&password");

    CanvasFrame canvasFrame = new CanvasFrame("Test");

    frameGrabber.start();

    for(int i = 0; i<frameGrabber.getLengthInFrames(); i++){
       canvasFrame.showImage(frameGrabber.grab());
    }
    frameGrabber.flush();

    canvasFrame.dispose();
}

If I use one correct link rtsp my program return and I can deal with he.

But if the link are incorrect or the ipcam are desconnected the program not return in the command frameGrabber.start();

The program crash, not return error and not do more nothing.

I've already tried use try catch but didn't have sucess, the program not return.

Edit:

I did tests with other protocols like http, and it does not occur this problem, the program return one message that can not open the link, to http are ok, but when using rtsp not return.

@saudet
Copy link
Member

saudet commented Mar 24, 2017 via email

@willagner
Copy link
Author

I find the solution.

It is necessary you define one timeout.

streamGrabber.setOption("timeout" , "3");

The default value for this parameter is '-1' (infinite).

"Timeout
Set maximum timeout (in seconds) to wait for incoming connections.

A value of -1 means infinite (default). This option implies the rtsp_flags set to ‘listen’."

@saudet
Copy link
Member

saudet commented Mar 24, 2017

Great find! Maybe this also fixes #97 #124 #165 #170 #430 and #462? @grimaz @hihi0677 @gtow @rpgomes @guylevin @nacyliu

@willagner
Copy link
Author

willagner commented Mar 24, 2017

👍

Thank you !

@willagner willagner reopened this Mar 24, 2017
@saudet saudet closed this as completed Mar 28, 2017
@d-a-gerashenko
Copy link
Contributor

d-a-gerashenko commented Jun 5, 2017

Why it's not working for me? I can't even start grabber when uses grabber.setOption("timeout" , "3");.
This code:

try {
	FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov");
	grabber.setOption("timeout" , "3");
	grabber.start();
	while (grabber.grab() != null) {
		System.out.println("frame grabbed");
	}
} catch (FrameGrabber.Exception ex) {
	System.err.println(ex);
}
System.out.println("end");

Returns error:

org.bytedeco.javacv.FrameGrabber$Exception: avformat_open_input() error -10049: Could not open input "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov". (Has setFormat() been called?)
end
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
[rtsp @ 168529a0] Unable to open RTSP for listening
[rtsp @ 16855980] Unable to open RTSP for listening

Without this options it works but there is no timeout.

JDK 1.8.0 x32
Windows 7 x64
javacv-platform 1.3.2

@saudet
Copy link
Member

saudet commented Jun 5, 2017

That flag is only valid for listening connections:

This option implies the rtsp_flags set to ‘listen’.

I don't think this is the flag you want. There is another flag is isn't for listening connections though.

@saudet
Copy link
Member

saudet commented Jun 7, 2017

FYI, it looks like the "stimeout" option works for RTSP streams:
#711 (comment)

@saudet
Copy link
Member

saudet commented Jun 15, 2017

It turns out that we need to set the "stimeout" option for the RTSP protocol. Thanks to @d-a-gerashenko we now have working sample code for this:
https://github.com/bytedeco/javacv/blob/master/samples/FFmpegStreamingTimeout.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants