From 87403135041470b4fa101dd2930777b6d3ea2cb6 Mon Sep 17 00:00:00 2001 From: Mario Sanchez Prada Date: Fri, 22 Apr 2016 15:02:16 +0100 Subject: [PATCH] vpxenc: Properly handle frames with too low duration When a frame's duration is too low, calling gst_util_uint64_scale() to scale its value can result into it being truncated to zero, which will cause the vpx encoder to return an VPX_CODEC_INVALID_PARAM error when trying to encode. To prevent this from happening, we simply ignore the duration when encoding if it becomes zero after scaling, logging a warning message. https://bugzilla.gnome.org/show_bug.cgi?id=765391 --- ext/vpx/gstvpxenc.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ext/vpx/gstvpxenc.c b/ext/vpx/gstvpxenc.c index 11d4cc11a..003d4640f 100644 --- a/ext/vpx/gstvpxenc.c +++ b/ext/vpx/gstvpxenc.c @@ -1888,7 +1888,17 @@ gst_vpx_enc_handle_frame (GstVideoEncoder * video_encoder, duration = gst_util_uint64_scale (frame->duration, encoder->cfg.g_timebase.den, encoder->cfg.g_timebase.num * (GstClockTime) GST_SECOND); - encoder->last_pts += frame->duration; + + if (duration > 0) { + encoder->last_pts += frame->duration; + } else { + /* We force the path ignoring the duration if we end up with a zero + * value for duration after scaling (e.g. duration value too small) */ + GST_WARNING_OBJECT (encoder, + "Ignoring too small frame duration %" GST_TIME_FORMAT, + GST_TIME_ARGS (frame->duration)); + duration = 1; + } } else { duration = 1; } -- 2.22.2