openh264enc: Add new enable-frame-skip property and disable it by default

Otherwise e.g. videotestsrc ! openh264enc ! ... will drop every second frame
because otherwise the target bitrate can't be reached without loosing too
much quality.
This commit is contained in:
Sebastian Dröge 2014-11-12 11:52:58 +01:00
parent a1cc1b34e1
commit 354fa3f2c9

View file

@ -116,6 +116,7 @@ static void gst_openh264enc_set_rate_control (GstOpenh264Enc * openh264enc,
#define DEFAULT_RATE_CONTROL RC_QUALITY_MODE #define DEFAULT_RATE_CONTROL RC_QUALITY_MODE
#define DEFAULT_MULTI_THREAD 0 #define DEFAULT_MULTI_THREAD 0
#define DEFAULT_ENABLE_DENOISE FALSE #define DEFAULT_ENABLE_DENOISE FALSE
#define DEFAULT_ENABLE_FRAME_SKIP FALSE
enum enum
{ {
@ -127,6 +128,7 @@ enum
PROP_RATE_CONTROL, PROP_RATE_CONTROL,
PROP_MULTI_THREAD, PROP_MULTI_THREAD,
PROP_ENABLE_DENOISE, PROP_ENABLE_DENOISE,
PROP_ENABLE_FRAME_SKIP,
N_PROPERTIES N_PROPERTIES
}; };
@ -141,6 +143,7 @@ struct _GstOpenh264EncPrivate
guint framerate; guint framerate;
guint multi_thread; guint multi_thread;
gboolean enable_denoise; gboolean enable_denoise;
gboolean enable_frame_skip;
GstVideoCodecState *input_state; GstVideoCodecState *input_state;
guint32 drop_bitrate; guint32 drop_bitrate;
guint64 time_per_frame; guint64 time_per_frame;
@ -228,6 +231,11 @@ gst_openh264enc_class_init (GstOpenh264EncClass * klass)
"Denoise control", "Denoise control",
FALSE, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); FALSE, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_ENABLE_FRAME_SKIP,
g_param_spec_boolean ("enable-frame-skip", "Skip Frames",
"Skip frames to reach target bitrate",
FALSE, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_BITRATE, g_object_class_install_property (gobject_class, PROP_BITRATE,
g_param_spec_uint ("bitrate", "Bitrate", g_param_spec_uint ("bitrate", "Bitrate",
"Bitrate (in bits per second)", "Bitrate (in bits per second)",
@ -264,6 +272,7 @@ gst_openh264enc_init (GstOpenh264Enc * openh264enc)
openh264enc->priv->previous_timestamp = 0; openh264enc->priv->previous_timestamp = 0;
openh264enc->priv->drop_bitrate = DROP_BITRATE; openh264enc->priv->drop_bitrate = DROP_BITRATE;
openh264enc->priv->enable_denoise = DEFAULT_ENABLE_DENOISE; openh264enc->priv->enable_denoise = DEFAULT_ENABLE_DENOISE;
openh264enc->priv->enable_frame_skip = DEFAULT_ENABLE_FRAME_SKIP;
openh264enc->priv->encoder = NULL; openh264enc->priv->encoder = NULL;
gst_openh264enc_set_usage_type (openh264enc, CAMERA_VIDEO_REAL_TIME); gst_openh264enc_set_usage_type (openh264enc, CAMERA_VIDEO_REAL_TIME);
gst_openh264enc_set_rate_control (openh264enc, RC_QUALITY_MODE); gst_openh264enc_set_rate_control (openh264enc, RC_QUALITY_MODE);
@ -330,6 +339,10 @@ gst_openh264enc_set_property (GObject * object, guint property_id,
openh264enc->priv->enable_denoise = g_value_get_boolean (value); openh264enc->priv->enable_denoise = g_value_get_boolean (value);
break; break;
case PROP_ENABLE_FRAME_SKIP:
openh264enc->priv->enable_frame_skip = g_value_get_boolean (value);
break;
case PROP_RATE_CONTROL: case PROP_RATE_CONTROL:
gst_openh264enc_set_rate_control (openh264enc, g_value_get_enum (value)); gst_openh264enc_set_rate_control (openh264enc, g_value_get_enum (value));
break; break;
@ -373,6 +386,10 @@ gst_openh264enc_get_property (GObject * object, guint property_id,
g_value_set_boolean (value, openh264enc->priv->enable_denoise); g_value_set_boolean (value, openh264enc->priv->enable_denoise);
break; break;
case PROP_ENABLE_FRAME_SKIP:
g_value_set_boolean (value, openh264enc->priv->enable_frame_skip);
break;
case PROP_MULTI_THREAD: case PROP_MULTI_THREAD:
g_value_set_uint (value, openh264enc->priv->multi_thread); g_value_set_uint (value, openh264enc->priv->multi_thread);
break; break;
@ -503,7 +520,7 @@ gst_openh264enc_set_format (GstVideoEncoder * encoder,
enc_params.uiIntraPeriod = priv->gop_size; enc_params.uiIntraPeriod = priv->gop_size;
enc_params.bEnableBackgroundDetection = 1; enc_params.bEnableBackgroundDetection = 1;
enc_params.bEnableAdaptiveQuant = 1; enc_params.bEnableAdaptiveQuant = 1;
enc_params.bEnableFrameSkip = 1; enc_params.bEnableFrameSkip = openh264enc->priv->enable_frame_skip;
enc_params.bEnableLongTermReference = 0; enc_params.bEnableLongTermReference = 0;
enc_params.bEnableSpsPpsIdAddition = 1; enc_params.bEnableSpsPpsIdAddition = 1;
enc_params.bPrefixNalAddingCtrl = 0; enc_params.bPrefixNalAddingCtrl = 0;