waveform80 / picamera

A pure Python interface to the Raspberry Pi camera module
https://picamera.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.57k stars 355 forks source link

I-Frame Extraction #701

Closed rossGardiner closed 3 years ago

rossGardiner commented 3 years ago

Is it possible to extract keyframes (iframes) at the encoding stage of the video stream? I have an application which requires iframes from specific points in a H264 stream, selecting iframes from the stream in post (using ffmpeg) takes too long. Could picamera output iframes as they are encoded?

Any advice appreciated!

6by9 commented 3 years ago

The GPU gives you flags alongside each encoded buffer. With the Encoder class you get _callback which gives you a MMALBuffer object. The flags member will have MMAL_BUFFER_HEADER_FLAG_KEYFRAME set for an I-frame.

rossGardiner commented 3 years ago

Thank you, this was exactly what I needed.