gst emit video keyframe on demand. (#27)

This commit is contained in:
Miroslav Šedivý 2023-02-07 21:43:14 +01:00 committed by GitHub
parent 2364facd60
commit bfabee12e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

View File

@ -200,3 +200,15 @@ gboolean gstreamer_pipeline_set_caps_resolution(GstPipelineCtx *ctx, const gchar
gst_object_unref(el); gst_object_unref(el);
return TRUE; return TRUE;
} }
gboolean gstreamer_pipeline_emit_video_keyframe(GstPipelineCtx *ctx) {
GstClock *clock = gst_pipeline_get_clock(GST_PIPELINE(ctx->pipeline));
gst_object_ref(clock);
GstClockTime time = gst_clock_get_time(clock);
GstClockTime now = time - gst_element_get_base_time(ctx->pipeline);
gst_object_unref(clock);
GstEvent *keyFrameEvent = gst_video_event_new_downstream_force_key_unit(now, time, now, TRUE, 0);
return gst_element_send_event(GST_ELEMENT(ctx->pipeline), keyFrameEvent);
}

View File

@ -1,7 +1,7 @@
package gst package gst
/* /*
#cgo pkg-config: gstreamer-1.0 gstreamer-app-1.0 #cgo pkg-config: gstreamer-1.0 gstreamer-app-1.0 gstreamer-video-1.0
#include "gst.h" #include "gst.h"
*/ */
@ -46,6 +46,8 @@ type Pipeline interface {
SetPropInt(binName string, prop string, value int) bool SetPropInt(binName string, prop string, value int) bool
SetCapsFramerate(binName string, numerator, denominator int) bool SetCapsFramerate(binName string, numerator, denominator int) bool
SetCapsResolution(binName string, width, height int) bool SetCapsResolution(binName string, width, height int) bool
// emit video keyframe
EmitVideoKeyframe() bool
} }
type pipeline struct { type pipeline struct {
@ -177,6 +179,11 @@ func (p *pipeline) SetCapsResolution(binName string, width, height int) bool {
return ok == C.TRUE return ok == C.TRUE
} }
func (p *pipeline) EmitVideoKeyframe() bool {
ok := C.gstreamer_pipeline_emit_video_keyframe(p.ctx)
return ok == C.TRUE
}
// gst-inspect-1.0 // gst-inspect-1.0
func CheckPlugins(plugins []string) error { func CheckPlugins(plugins []string) error {
var plugin *C.GstPlugin var plugin *C.GstPlugin

View File

@ -3,6 +3,7 @@
#include <stdio.h> #include <stdio.h>
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/app/gstappsrc.h> #include <gst/app/gstappsrc.h>
#include <gst/video/video.h>
typedef struct GstPipelineCtx { typedef struct GstPipelineCtx {
int pipelineId; int pipelineId;
@ -25,3 +26,4 @@ void gstreamer_pipeline_push(GstPipelineCtx *ctx, void *buffer, int bufferLen);
gboolean gstreamer_pipeline_set_prop_int(GstPipelineCtx *ctx, char *binName, char *prop, gint value); gboolean gstreamer_pipeline_set_prop_int(GstPipelineCtx *ctx, char *binName, char *prop, gint value);
gboolean gstreamer_pipeline_set_caps_framerate(GstPipelineCtx *ctx, const gchar* binName, gint numerator, gint denominator); gboolean gstreamer_pipeline_set_caps_framerate(GstPipelineCtx *ctx, const gchar* binName, gint numerator, gint denominator);
gboolean gstreamer_pipeline_set_caps_resolution(GstPipelineCtx *ctx, const gchar* binName, gint width, gint height); gboolean gstreamer_pipeline_set_caps_resolution(GstPipelineCtx *ctx, const gchar* binName, gint width, gint height);
gboolean gstreamer_pipeline_emit_video_keyframe(GstPipelineCtx *ctx);