From a122135194c693edaeb14a1ecddf946d76523d2f Mon Sep 17 00:00:00 2001 From: Vivia Nikolaidou Date: Fri, 10 Mar 2017 17:40:13 +0200 Subject: [PATCH] videotimecode: Fix invalid timecode right before a new second When initializing a timecode from a GDateTime, and the remaining time until the new second is less than half a frame (according to the given frame rate), it would lead to the creation of an invalid timecode, e.g. 00:00:00:25 (at 25 fps) instead of 00:00:01:00. Fixed. https://bugzilla.gnome.org/show_bug.cgi?id=779866 --- gst-libs/gst/video/gstvideotimecode.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gst-libs/gst/video/gstvideotimecode.c b/gst-libs/gst/video/gstvideotimecode.c index 5dd47b7..5c711ce 100644 --- a/gst-libs/gst/video/gstvideotimecode.c +++ b/gst-libs/gst/video/gstvideotimecode.c @@ -219,6 +219,7 @@ gst_video_time_code_init_from_date_time (GstVideoTimeCode * tc, { GDateTime *jam; guint64 frames; + gboolean add_a_frame = FALSE; jam = g_date_time_new_local (g_date_time_get_year (dt), g_date_time_get_month (dt), g_date_time_get_day_of_month (dt), 0, 0, 0.0); @@ -228,6 +229,11 @@ gst_video_time_code_init_from_date_time (GstVideoTimeCode * tc, frames = gst_util_uint64_scale_round (g_date_time_get_microsecond (dt) * G_GINT64_CONSTANT (1000), fps_n, fps_d * GST_SECOND); + if (G_UNLIKELY (frames == fps_n)) { + /* Avoid invalid timecodes */ + frames--; + add_a_frame = TRUE; + } gst_video_time_code_init (tc, fps_n, fps_d, jam, flags, g_date_time_get_hour (dt), g_date_time_get_minute (dt), @@ -240,6 +246,8 @@ gst_video_time_code_init_from_date_time (GstVideoTimeCode * tc, tc->frames = df; } } + if (add_a_frame) + gst_video_time_code_increment_frame (tc); g_date_time_unref (jam); -- 2.7.4