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

FFMPEGFrameGrabber.start() doesn't find stream most of the time and blocks the thread it's running in from running its course #2226

Open
Alin63992 opened this issue May 2, 2024 · 3 comments

Comments

@Alin63992
Copy link

Alin63992 commented May 2, 2024

Hello! Hope you're doing well. I'm having some issues with FFMPEGFrameGrabber.
Most of the time, when calling the start() method, the grabber does not grab any frames from the RTMP server I have set up using NGINX on Windows, and the thread the grabbing is running in stays blocked on the line where start() is called, so it doesn't run its course, nor checks if it's interrupted or not when the JavaFX window is closed, so the app stays running indefinitely. I have FFMPEGFrameRecorder set up as in the WebcamAndMicrophoneCapture.java sample (but using VideoCapture instead of OpenCVFrameGrabber because implementing the latter consumed a lot of ram, and skipping the audio lines since I don't need the microphone audio being captured and sent), and I have the grabber set up like so:

final int CONNECTION_TIMEOUT = 10;
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("rtmp://" + Main.rtmpServerAddress + ":" + Main.rtmpServerPort + "/live/" + Main.employeeSpotlightUsername);
try {
    grabber.setFormat("flv");
    grabber.setVideoCodec(avcodec.AV_CODEC_ID_H264);
    //grabber.setOption("timeout", String.valueOf(CONNECTION_TIMEOUT * 1000000));
    grabber.start();
    JavaFXFrameConverter converter = new JavaFXFrameConverter();
    Frame frame;
    while (!Thread.currentThread().isInterrupted()) {
        if ((frame = grabber.grab()) != null) {
            camImage.setImage(converter.convert(frame));
        }
    }
    grabber.stop();
} catch (FrameGrabber.Exception e) {
    e.printStackTrace();
    try {
          grabber.stop();
    } catch (FFmpegFrameGrabber.Exception ex) {
          ex.printStackTrace();
    }
}

Also, setting the 10s timeout makes the grabber quit trying to find a stream somewhere between 1-5 seconds.
How can I make the grabber give up after 10s and not block the entire thread, so that the application quits successfully when closing the main window?
Thank you!

@saudet
Copy link
Member

saudet commented May 2, 2024

We can set a timeout on the grabbing side as well, so please try to do that

@Alin63992
Copy link
Author

Hey! I have already tried that in the 6th line, that's commented out, which is how I found out that the 10s timeout isn't reached, and that FFMPEGFrameGrabber quits loading after 1-5s since start() was called. Maybe there's a calculation error I've made there?
But even if that was a problem, there's still one that remains: the one where the stream isn't found or loaded every time I try, even if FFMPEGFrameRecorder doesn't throw an error about sending the stream to the server with the same address I'm trying to grab from.

@whr2349
Copy link

whr2349 commented May 16, 2024

你用的是1.5.10吗?

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

No branches or pull requests

3 participants