Find Keyframes in H264 Stream in Python from GST Buffer or Similar

ashwath ashwath at bodega.ai
Wed Aug 15 23:50:16 UTC 2018


Hi,

I have a sortof strange request - I have a pipeline which passes raw h264
frames into appsink directly, where I then work with them in my python
runtime (Input Pipeline).  In this python runtime, I then start writing the
frames to short video snippets (Output Pipeline).

Input pipeline:

v4l2src device=<device> ! videoconvert ! video/x-raw,format=I420 !
vaapipostproc ! vaapih264enc ! video/x-h264,stream-format=avc,alignment=au !
appsink enable-last-sample=true                                       
 emit-signals=true, sync=false, drop=false

Output Pipeline
appsrc caps=<CAPS> ! queue ! h264parse ! mp4mux ! filesink
location=<location>

In order for this to write video that is not corrupted, I need to find and
mark the keyframes in the input pipeline - I'm having trouble doing this
consistently.  I have heuristics that I can think of (collect the size of 60
frames, and if the size of the frame is within 10% of the max, it's a
keyframe) that work OK, but sometimes my pipeline is failing to find the
keyframes and is writing corrupted videos.

Is there a better way to determine keyframes from just the GSTBuffer object
alone?  Ideally I'm constantly streaming all h264 frames into my python
runtime - which makes me feel like any sort of flushing seek is out of the
question for me.

Any help would be much appreciated,

Ash



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/


More information about the gstreamer-devel mailing list