Search code examples
javavideo-processingxuggle

Java - Keyframe extraction from a video


I want to extract keyframes from a video. Now I'm using a loop that compare the samples of one frame with the samples of the preceding frame, but this method isn't very good.

Let me explain: I have a surveillance video and I have to select the frames where there is a change (a person appears, another person appears, a person goes away, etc.) Now I'm using this class to compare frames: Java Image Comparison / Motion Detection Class

Do you know other ways?

Thanks!!


Solution

  • I'm not sure what you call a "keyframe". Your method would allow you only to find scene transitions, but that is not what is usually meant by a "keyframe" in video decoding: it's rather usually an I-frame (a frame which can be decoded on its own, without reference to other frames). (Frequently scene transitions are keyframes, but no necessarily the other way). This concept it tied to the video codec, of course, but most modern codecs (from MPEG-1) implement this concept. But notice that this is not related to the raw pictures in themselves, but with the codec.

    If you want to detect these keyframes (I-frames), then you must look inside your video decoding API, to see if it allows you to get this information. It seems that xuggle provides you the IVideoPicture.getPictureType() method, but I have not used it.