BugFix Add keyframes every second of output recording

Also compilation warning fix for GValue init.
This commit is contained in:
Bruno Herbelin
2024-04-29 23:45:48 +02:00
parent fd9c868c40
commit cd8f9792ab
7 changed files with 21 additions and 7 deletions

View File

@@ -272,7 +272,7 @@ FrameGrabber::FrameGrabber(): finished_(false), initialized_(false), active_(fal
endofstream_(false), accept_buffer_(false), buffering_full_(false), pause_(false), endofstream_(false), accept_buffer_(false), buffering_full_(false), pause_(false),
pipeline_(nullptr), src_(nullptr), caps_(nullptr), timer_(nullptr), timer_firstframe_(0), pipeline_(nullptr), src_(nullptr), caps_(nullptr), timer_(nullptr), timer_firstframe_(0),
timer_pauseframe_(0), timestamp_(0), duration_(0), pause_duration_(0), frame_count_(0), timer_pauseframe_(0), timestamp_(0), duration_(0), pause_duration_(0), frame_count_(0),
buffering_size_(MIN_BUFFER_SIZE), buffering_count_(0), timestamp_on_clock_(true) keyframe_count_(0), buffering_size_(MIN_BUFFER_SIZE), buffering_count_(0), timestamp_on_clock_(true)
{ {
// unique id // unique id
id_ = BaseToolkit::uniqueId(); id_ = BaseToolkit::uniqueId();
@@ -513,6 +513,18 @@ void FrameGrabber::addFrame (GstBuffer *buffer, GstCaps *caps)
// push frame // push frame
gst_app_src_push_buffer (src_, buffer); gst_app_src_push_buffer (src_, buffer);
// NB: buffer will be unrefed by the appsrc // NB: buffer will be unrefed by the appsrc
// add a key frame every second (if keyframecount is valid)
if (keyframe_count_ > 1 && frame_count_ % keyframe_count_ < 1) {
GstEvent *event
= gst_video_event_new_downstream_force_key_unit(timestamp_,
GST_CLOCK_TIME_NONE,
GST_CLOCK_TIME_NONE,
FALSE,
frame_count_ / keyframe_count_);
gst_element_send_event(GST_ELEMENT(src_), event);
}
} }
} }
} }

View File

@@ -84,6 +84,7 @@ protected:
GstClockTime pause_duration_; GstClockTime pause_duration_;
GstClockTime frame_duration_; GstClockTime frame_duration_;
guint64 frame_count_; guint64 frame_count_;
guint64 keyframe_count_;
guint64 buffering_size_; guint64 buffering_size_;
guint64 buffering_count_; guint64 buffering_count_;
bool timestamp_on_clock_; bool timestamp_on_clock_;

View File

@@ -124,7 +124,7 @@ std::string Loopback::init(GstCaps *caps)
// specify streaming framerate in the given caps // specify streaming framerate in the given caps
GstCaps *tmp = gst_caps_copy( caps ); GstCaps *tmp = gst_caps_copy( caps );
GValue v = { 0, }; GValue v = G_VALUE_INIT;
g_value_init (&v, GST_TYPE_FRACTION); g_value_init (&v, GST_TYPE_FRACTION);
gst_value_set_fraction (&v, LOOPBACK_FPS, 1); // fixed FPS gst_value_set_fraction (&v, LOOPBACK_FPS, 1); // fixed FPS
gst_caps_set_value(tmp, "framerate", &v); gst_caps_set_value(tmp, "framerate", &v);

View File

@@ -334,7 +334,8 @@ std::string VideoRecorder::init(GstCaps *caps)
// apply settings // apply settings
buffering_size_ = MAX( MIN_BUFFER_SIZE, buffering_preset_value[Settings::application.record.buffering_mode]); buffering_size_ = MAX( MIN_BUFFER_SIZE, buffering_preset_value[Settings::application.record.buffering_mode]);
frame_duration_ = gst_util_uint64_scale_int (1, GST_SECOND, framerate_preset_value[Settings::application.record.framerate_mode]); frame_duration_ = gst_util_uint64_scale_int (1, GST_SECOND, framerate_preset_value[Settings::application.record.framerate_mode]);
timestamp_on_clock_ = Settings::application.record.priority_mode < 1; timestamp_on_clock_ = Settings::application.record.priority_mode < 1;
keyframe_count_ = framerate_preset_value[Settings::application.record.framerate_mode];
// create a gstreamer pipeline // create a gstreamer pipeline
std::string description = "appsrc name=src ! videoconvert ! queue ! "; std::string description = "appsrc name=src ! videoconvert ! queue ! ";
@@ -440,7 +441,7 @@ std::string VideoRecorder::init(GstCaps *caps)
// specify recorder framerate in the given caps // specify recorder framerate in the given caps
GstCaps *tmp = gst_caps_copy( caps ); GstCaps *tmp = gst_caps_copy( caps );
GValue v = { 0, }; GValue v = G_VALUE_INIT;
g_value_init (&v, GST_TYPE_FRACTION); g_value_init (&v, GST_TYPE_FRACTION);
gst_value_set_fraction (&v, framerate_preset_value[Settings::application.record.framerate_mode], 1); gst_value_set_fraction (&v, framerate_preset_value[Settings::application.record.framerate_mode], 1);
gst_caps_set_value(tmp, "framerate", &v); gst_caps_set_value(tmp, "framerate", &v);

View File

@@ -131,7 +131,7 @@ std::string ShmdataBroadcast::init(GstCaps *caps)
// specify streaming framerate in the given caps // specify streaming framerate in the given caps
GstCaps *tmp = gst_caps_copy( caps ); GstCaps *tmp = gst_caps_copy( caps );
GValue v = { 0, }; GValue v = G_VALUE_INIT;
g_value_init (&v, GST_TYPE_FRACTION); g_value_init (&v, GST_TYPE_FRACTION);
gst_value_set_fraction (&v, SHMDATA_FPS, 1); // fixed 30 FPS gst_value_set_fraction (&v, SHMDATA_FPS, 1); // fixed 30 FPS
gst_caps_set_value(tmp, "framerate", &v); gst_caps_set_value(tmp, "framerate", &v);

View File

@@ -449,7 +449,7 @@ std::string VideoStreamer::init(GstCaps *caps)
// specify streaming framerate in the given caps // specify streaming framerate in the given caps
GstCaps *tmp = gst_caps_copy( caps ); GstCaps *tmp = gst_caps_copy( caps );
GValue v = { 0, }; GValue v = G_VALUE_INIT;
g_value_init (&v, GST_TYPE_FRACTION); g_value_init (&v, GST_TYPE_FRACTION);
gst_value_set_fraction (&v, STREAMING_FPS, 1); // fixed 30 FPS gst_value_set_fraction (&v, STREAMING_FPS, 1); // fixed 30 FPS
gst_caps_set_value(tmp, "framerate", &v); gst_caps_set_value(tmp, "framerate", &v);

View File

@@ -156,7 +156,7 @@ std::string VideoBroadcast::init(GstCaps *caps)
// specify streaming framerate in the given caps // specify streaming framerate in the given caps
GstCaps *tmp = gst_caps_copy( caps ); GstCaps *tmp = gst_caps_copy( caps );
GValue v = { 0, }; GValue v = G_VALUE_INIT;
g_value_init (&v, GST_TYPE_FRACTION); g_value_init (&v, GST_TYPE_FRACTION);
gst_value_set_fraction (&v, BROADCAST_FPS, 1); // fixed 30 FPS gst_value_set_fraction (&v, BROADCAST_FPS, 1); // fixed 30 FPS
gst_caps_set_value(tmp, "framerate", &v); gst_caps_set_value(tmp, "framerate", &v);