Reading frames with FFmpegFrameGrabber from MP4 file and keyframes are null

1,900 views
Skip to first unread message

Bartek Zdanowski

unread,
Jan 8, 2017, 7:15:05 PM1/8/17
to javacv
HI.

I'm very grateful for developing javacv. You did great job!!!

I have problem with grabbing every mp4 or other types of files. I used code from current README.md.
Instead of grabbing video from a camera, I used FFmpegFrameGrabber with mp4 file:

        FrameGrabber grabber = FFmpegFrameGrabber.createDefault("http://techslides.com/demos/sample-videos/small.mp4");

And now it grabbes frame from that file, but ther's something strange. Every few frames the frame is a keyFrame, and it has null image.
I've modified while loop:
   while (frame.isVisible() && (grabbedImage = converter.convert(grabber.grab())) != null) {
   
to

 while (frame.isVisible()) {
            Frame grabbedFrame = grabber.grab();
            System.out.println(String.format("keyframe %s, image is null: %s", grabbedFrame.keyFrame, grabbedFrame.image == null));

            if (grabbedFrame.image == null) {
                continue;
            }
            grabbedImage = converter.convert(grabbedFrame);


and now the output is:

keyframe false, image is null: false
keyframe false, image is null: false
keyframe false, image is null: false
keyframe true, image is null: true
keyframe true, image is null: true
keyframe true, image is null: true
keyframe true, image is null: true
keyframe true, image is null: true
keyframe true, image is null: true
keyframe false, image is null: false
keyframe false, image is null: false
keyframe false, image is null: false

The output to the Canvas is very fast running film as there are lots of gaps in frames. 
Strange thing. If I dump frames with ffmpeg:


ffmpeg -i small.mp4 thumb%04d.jpg


I get all the frames. No gaps.

Can you help me?
I'd be very grateful.

Bartek

Samuel Audet

unread,
Jan 8, 2017, 7:25:47 PM1/8/17
to jav...@googlegroups.com
This following works fine, so try something like that instead:
https://github.com/bytedeco/javacv/blob/master/platform/src/test/java/org/bytedeco/javacv/FrameGrabberTest.java#L42
Frames with no images are audio frames.

Samuel

Bartek Zdanowski

unread,
Jan 9, 2017, 4:20:29 AM1/9/17
to javacv
Samuel,
thank you for response.
I will check this. But I see that you're referring snapshot version. Now I'm trying to build whole and I will see if it helps.

I will give some feedback regarding building.

Regarding what you wrote, do you have any knowledge about such mp4 stream? My additional question is why there are so few image frames? If I dump all frames via command line, there are exactly 166 frames and that's correct (30fps * 166 gives almost 6secs which is right for example small.mp4)?

If I grab only non-null image frames - those are very few giving only about 10fps. 
And last question - if those (keyFrame == true) frames are sound frames - why is this marked as keyFrame - which is not actually an image frame?

Shouldn't it be fixed? I might do it if you wish but I need some directions from you - the core developer.

Very best regards,
Bartek

Samuel Audet

unread,
Jan 9, 2017, 5:57:42 AM1/9/17
to jav...@googlegroups.com
Everything works perfectly fine here. If you have any issues please post
more details on GitHub and we'll look into it:
https://github.com/bytedeco/javacv/issues

Samuel Audet

unread,
Jan 9, 2017, 9:17:37 AM1/9/17
to jav...@googlegroups.com
As to why FFmpeg marks all audio frames as "key frames", and for other
questions regarding FFmpeg, I don't know. You'll need to ask on FFmpeg's
mailing list to get answers.

Bartek Zdanowski

unread,
Jan 9, 2017, 9:38:59 AM1/9/17
to javacv
OK. Thanks.
Reply all
Reply to author
Forward
0 new messages