sawpawan / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

FrameGrabber.getFrameRate() does not do anything useful #292

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
- Calling getFrameRate() on a FFmpegFrameGrabber object, returns just the 
number that was previously set sith setFrameRate(), so, the requested 
framerate. If the video input does not support that framerate, getFrameRate() 
still returns the default value.
- Calling getFrameRate() on an OpenCVFrameGrabber object returns -1.

For example, we request 30 fps with setFrameRate, but a given webcam only 
supports 15 fps. getFrameRate returns 30 with FFmpegFG, and -1 with OpenCVFG.

What is the expected output? What do you see instead?
I would expect this method to return the actual framerate set in the source (15 
in the example).

What version of the product are you using? On what operating system?
JavaCV 0.4, Ffmpeg 1.1.3

Please provide any additional information below.
SO: Ubuntu 64

Original issue reported on code.google.com by adle...@gmail.com on 9 Mar 2013 at 8:05

GoogleCodeExporter commented 8 years ago
This should actually not be marked as a defect (as it just follow the get/set 
pattern), but as an enhancement (I don't know how to reclassify the bug once 
created).

Original comment by adle...@gmail.com on 9 Mar 2013 at 11:29

GoogleCodeExporter commented 8 years ago
Let's look at FFmpegFrameGrabber.getFrameRate():
    @Override public double getFrameRate() {
        if (video_st == null) {
            return super.getFrameRate();
        } else {
            AVRational r = video_st.r_frame_rate();
            return (double)r.num() / r.den();
        }
    }

and OpenCVFrameGrabber.getFrameRate():
    @Override public double getFrameRate() {
        return capture == null ? super.getFrameRate() : (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
    }

Should they be doing anything differently?

Original comment by samuel.a...@gmail.com on 10 Mar 2013 at 1:23

GoogleCodeExporter commented 8 years ago
There is something strange somewhere. If I specify some huge number for the 
framerate, like 1250, I get the message:

    The driver changed the time per frame from 1/1250 to 1/226

And getFrameRate() returns 226. However, this webcam in this mode only supports 
125 fps (which are the ones I actually am getting).

If I specify a lower value, like 200, getFrameRate() just returns 200.

May there be a different way to retrieve that framerate?

For example (I don't know if it really applies): 
http://libav-users.943685.n4.nabble.com/Retrieving-Frames-Per-Second-FPS-td94653
3.html

Original comment by adle...@gmail.com on 10 Mar 2013 at 1:55

GoogleCodeExporter commented 8 years ago
Well the best would be to check what the ffmpeg program does, and if that does 
what you need, then to implement something similar in 
FFmpegFrameGrabber.getFrameRate()...

Original comment by samuel.a...@gmail.com on 10 Mar 2013 at 11:22

GoogleCodeExporter commented 8 years ago
Issue 391 has been merged into this issue.

Original comment by samuel.a...@gmail.com on 4 Jan 2014 at 2:15

GoogleCodeExporter commented 8 years ago
JavaCV 0.10 now returns the value of  `AVStream.avg_frame_rate` instead of 
`r_frame_rate`:
https://github.com/bytedeco/javacv/issues/63
I hope this fixes this issue as well. Let me know if you still have problems, 
and thanks for reporting!

Original comment by samuel.a...@gmail.com on 27 Dec 2014 at 3:19

GoogleCodeExporter commented 8 years ago
So I had an issue with my piece of garbage foscam returning NaN with the 
getFrameRate().  So I adjusted it to the following and now i'm getting an fps 
for it and my other cameras.  Not sure if it's the right way but it's working 
for me right now.

    @Override
    public double getFrameRate() {
        if (video_st == null) {
            return super.getFrameRate();
        } else {
            AVRational r = video_st.avg_frame_rate();
            if (Double.isNaN((double) r.num() / r.den()))
                r = video_st.r_frame_rate();
            return (double) r.num() / r.den();
        }
    }

Original comment by robert.t...@gmail.com on 5 Aug 2015 at 2:09

GoogleCodeExporter commented 8 years ago
Thanks! I've added the equivalent in this commit:
https://github.com/bytedeco/javacv/commit/98889d4fa3ad25d9b8a4571442b0c2e17b13c4
e4
Let me know that it works, thanks!

Original comment by samuel.a...@gmail.com on 5 Aug 2015 at 11:20