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 set Frame skipping #1877

Closed
lironghai opened this issue Aug 25, 2022 · 8 comments
Closed

FFmpegFrameGrabber set Frame skipping #1877

lironghai opened this issue Aug 25, 2022 · 8 comments

Comments

@lironghai
Copy link

When using ffmpegframegrabber decoding, I want to get only one frame of data per second.
I want to ask if ffmpegframegrabber provides such parameter settings. I use setframerate, but it does not work

    FFmpegFrameGrabber.tryLoad();
    FFmpegFrameRecorder.tryLoad();
    FFmpegLogCallback.set();
    System.setProperty("java.awt.headless", "false");
    String url = "rtsp://admin:ad123456@192.168.40.222/";
    FFmpegFrameGrabber grabber = FFmpegFrameGrabber.createDefault(url);
    grabber.setOption("rtsp_transport", "tcp");
    grabber.setOption("timeout", "2000000");
    grabber.setOption("rw_timeout", "2000000");
    grabber.setFrameRate(1);
    grabber.setImageWidth(1920);
    grabber.setImageHeight(1080);
    String encodeName = "h264_nvenc";
    String encodeName2 = "h264_cuvid";

// grabber.setVideoCodecName("vaapi");
System.out.println("grabber start");
grabber.start();
CanvasFrame canvasFrame = new CanvasFrame("opencvtest");
canvasFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
canvasFrame.setAlwaysOnTop(true);
OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat();
// OpenCVFrameConverter.ToIplImage converter = new OpenCVFrameConverter.ToIplImage();
int num = 0 ;
while (true){
System.out.println(System.currentTimeMillis()/1000);
Frame frame = grabber.grabImage();
canvasFrame.showImage(frame);
// Thread.sleep(5000);
}

@saudet
Copy link
Member

saudet commented Aug 25, 2022

We can call grabAtFrameRate() instead of grab(), if that's what your looking for?

@lironghai
Copy link
Author

We can call grabAtFrameRate() instead of grab(), if that's what your looking for?

grabAtFrameRate() Can't do it,It seems that I can only discard some frames manually.
What I hope to achieve is that only one frame of data is returned every 25 frames, skip 24 of them.
grabAtFrameRate() In, I found that he can sleep, but sleep does not get the frame data of the current time, and only gets the continuous frames before sleep.

@saudet
Copy link
Member

saudet commented Aug 29, 2022

That sounds maybe like grabKeyFrame()?

@lironghai
Copy link
Author

That sounds maybe like grabKeyFrame()?

Thank you very much. This function is similar to the expected work, but it cannot control the number of returned frames per second. At present, it seems that only some frames can be discarded manually

1 similar comment
@lironghai
Copy link
Author

That sounds maybe like grabKeyFrame()?

Thank you very much. This function is similar to the expected work, but it cannot control the number of returned frames per second. At present, it seems that only some frames can be discarded manually

@lironghai
Copy link
Author

That sounds maybe like grabKeyFrame()?

I want to confirm that if you want to accelerate decoding with GPU NVIDIA graphics card, do you have to install ffmpeg and the corresponding decoder dependencies on the host computer?

I am here #1767 Only POM related dependencies are seen in, and the modules to be installed by the host machine are not mentioned

Can you provide a case of using GPU acceleration in the wiki

@saudet
Copy link
Member

saudet commented Aug 31, 2022

Thank you very much. This function is similar to the expected work, but it cannot control the number of returned frames per second. At present, it seems that only some frames can be discarded manually

If your stream is based on key frames, it's not possible to decode any other frames independently. However, if your stream has other kinds of frames, it might be possible to decode only some of them. @mihirbala should be able to help you with that, see issue #1832.

I want to confirm that if you want to accelerate decoding with GPU NVIDIA graphics card, do you have to install ffmpeg and the corresponding decoder dependencies on the host computer?

You only need to install the correct video driver for your GPU, and it should work out of the box by setting the right codec with setVideoCodecName() before calling start(). We do not need CUDA.

Can you provide a case of using GPU acceleration in the wiki

There's a wiki page with the names of the codecs here: https://trac.ffmpeg.org/wiki/HWAccelIntro

If you would like to have something with more details, contributions are welcome!

@saudet
Copy link
Member

saudet commented May 29, 2023

Duplicate of #1121

@saudet saudet marked this as a duplicate of #1121 May 29, 2023
@saudet saudet closed this as completed May 29, 2023
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

2 participants