anhtuan98 / javacv

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

Different ways to count keyframes give different answers for h264. #409

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

For attached file run code:
FFmpegFrameGrabber gr = new FFmpegFrameGrabber(fileName);
try {
    gr.start();
    System.out.println("getLengthInFrames() = "+gr.getLengthInFrames());
    int i, cou = 0;
    for(i=0;;i++){
        final Frame fr = gr.grabFrame();
        if(fr == null) break;
        if(!fr.keyFrame) continue;
        cou++;
    }
    System.out.println("use fr.keyFrame, "+i+" frames "+cou+" keyframes");
    gr.release(); gr.start();
    cou = 0;
    for(i=0;;i++){
        final Frame fr = gr.grabKeyFrame();
        if(fr == null) break;
        cou++;
    }
    gr.release();
    System.out.println("use grabKeyFrame(), "+cou+" keyframes");
} catch (com.googlecode.javacv.FrameGrabber.Exception e) { 
e.printStackTrace();    }

What is the expected output? What do you see instead?

Expected:
getLengthInFrames() = <number X>
use fr.keyFrame, <number X> frames 7 keyframes
use grabKeyFrame(), 7 keyframes

I see instead:
getLengthInFrames() = 480
use fr.keyFrame, 1340 frames 868 keyframes
use grabKeyFrame(), 7 keyframes

What version of the product are you using? On what operating system?
JavaCV 0.7, Win7

Please provide any additional information below.

We started this discussion in comments for Issue 312. Attached file prepared in 
Format Factory 3.1.1 .

Original issue reported on code.google.com by mip...@gmail.com on 14 Jan 2014 at 9:08

Attachments:

GoogleCodeExporter commented 9 years ago
I had insight and re-encoded the same file but without audio and got good 
result:
getLengthInFrames() = 472
use fr.keyFrame, 473 frames 7 keyframes
use grabKeyFrame(), 7 keyframes

So, I hope this will help.

Original comment by mip...@gmail.com on 14 Jan 2014 at 9:32

Attachments:

GoogleCodeExporter commented 9 years ago
Obviously if you're only interested in video key frames, you should ignore the 
audio key frames. So, I guess this is not an issue after all?

Original comment by samuel.a...@gmail.com on 15 Jan 2014 at 12:23

GoogleCodeExporter commented 9 years ago
Yes it is not an issue after all... sorry for increasing you issue count.
It will be very useful to have even short javadoc for such similar looking 
function. Like:
/**  Grab next videoframe */
public IplImage grab() 
/**  Grab next video keyframe */
public Frame grabKeyFrame()
/** Grab next video or audio frame */
public Frame grabFrame()

Reading javadocs before using new function is useful habit. May be next time 
this will save someone's hours.
Thank you for your time and help!

Original comment by mip...@gmail.com on 15 Jan 2014 at 2:02

GoogleCodeExporter commented 9 years ago
Some Javadoc would be useful, I agree. Unfortunately, I'm spending all the free 
time I have on JavaCPP Presets these days:
    http://code.google.com/p/javacpp/wiki/Presets
So, if you have doc you'd like to see in JavaCV, please post your patches as an 
issue, actually issue #360 would be appropriate I suppose. Thanks in advance!

BTW, the issue list here is a way for me to keep track about what needs to be 
done, and give a chance for people to vote on the issues that they wish would 
be fixed first. It is not a mailing list. Unless someone is really curious 
about a given issue, I'm the only person reading any of the messages you write 
here. This is why there is a mailing list to post your questions to, because, 
in theory anyway, there's more than just me on the mailing list. So if you wish 
your questions answered with the highest probably, that's the place to ask 
them. It's purely for your convenience, not mine.

Original comment by samuel.a...@gmail.com on 19 Jan 2014 at 7:55