# How do you extract keyframes from a video for indexing purposes?

Source: https://zilliz.com/ai-faq/how-do-you-extract-keyframes-from-a-video-for-indexing-purposes
Author: zilliz

To extract keyframes from a video for indexing, you can utilize various methods and tools designed specifically for video processing. Keyframes, or I-frames, are important because they represent complete images in a video stream, allowing for easier analyses such as indexing. One common approach is to use a video processing library like OpenCV or FFmpeg, both of which provide efficient ways to extract keyframes.

Using **FFmpeg**, for example, you can identify keyframes by relying on its built-in capabilities through a simple command-line operation. The command `ffmpeg -i input_video.mp4 -vf "select='eq(pict_type,I)'" -vsync vfr keyframe_%04d.jpg` extracts all keyframes from the input video and saves them as JPEG images. The `select` filter with the `eq(pict_type,I)` condition targets only those frames classified as I-frames. As a result, each keyframe will be numbered sequentially, making it easy to organize them for indexing purposes.

Alternatively, **OpenCV** enables finer control over the video processing pipeline. You can read the video frame-by-frame using OpenCV's `cv2.VideoCapture()` function, then check the frame type for each frame captured. By accessing the video's metadata, you can identify whether a frame is a keyframe. Although this method requires more code and understanding of OpenCV’s functionality, it allows developers to implement custom logic for indices, such as filtering based on specific criteria or combining keyframe extraction with additional tasks like frame analysis or scene detection. Overall, both FFmpeg and OpenCV are effective tools for keyframe extraction, providing a solid foundation for building an indexing system for video content.
