From a055c3272e5f38d5ca6e38565d46ce39b35104cb Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Wed, 4 Mar 2020 11:07:32 -0300 Subject: [PATCH] validate:ssim: Allow specifying file framerate to use frame numbers during comparison --- docs/plugins/ssim.md | 3 +++ validate/gst-libs/gst/video/gstvalidatessim.c | 16 +++++++++++++++- validate/gst-libs/gst/video/gstvalidatessim.h | 4 +++- validate/plugins/ssim/gstvalidatessim.c | 11 +++++++---- validate/tools/gst-validate-images-check.c | 3 ++- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/docs/plugins/ssim.md b/docs/plugins/ssim.md index 3966f41cb0..afac334dcb 100644 --- a/docs/plugins/ssim.md +++ b/docs/plugins/ssim.md @@ -54,6 +54,9 @@ The following parameters can be passed in the configuration file: used to configure the following configuration expressions. In practice this means that it will change the default values for the other configuration expressions. + - framerate: (GstFraction): The framerate to use to compute frame number from + timestamp, allowing to compare frames by 'frame number' instead of trying to + match timestamp between reference images and output images. # Example # diff --git a/validate/gst-libs/gst/video/gstvalidatessim.c b/validate/gst-libs/gst/video/gstvalidatessim.c index 2586b48bd5..70b5274317 100644 --- a/validate/gst-libs/gst/video/gstvalidatessim.c +++ b/validate/gst-libs/gst/video/gstvalidatessim.c @@ -71,6 +71,7 @@ struct _GstValidateSsimPrivate gfloat min_lowest_similarity; GHashTable *ref_frames_cache; + gint fps_n, fps_d; }; G_DEFINE_TYPE_WITH_CODE (GstValidateSsim, gst_validate_ssim, @@ -532,6 +533,16 @@ _find_frame (GstValidateSsim * self, GArray * frames, GstClockTime ts, guint i; Frame *lframe = &g_array_index (frames, Frame, 0); + if (self->priv->fps_n) { + gint64 frame_number = gst_util_uint64_scale (ts, self->priv->fps_n, + self->priv->fps_d * GST_SECOND); + + if (frames->len < frame_number) + return NULL; + + return &g_array_index (frames, Frame, frame_number); + } + if (frames->len == 1) { Frame *iframe = &g_array_index (frames, Frame, 0); @@ -1002,13 +1013,16 @@ gst_validate_ssim_init (GstValidateSsim * self) GstValidateSsim * gst_validate_ssim_new (GstValidateRunner * runner, - gfloat min_avg_similarity, gfloat min_lowest_similarity) + gfloat min_avg_similarity, gfloat min_lowest_similarity, + gint fps_n, gint fps_d) { GstValidateSsim *self = g_object_new (GST_VALIDATE_SSIM_TYPE, "validate-runner", runner, NULL); self->priv->min_avg_similarity = min_avg_similarity; self->priv->min_lowest_similarity = min_lowest_similarity; + self->priv->fps_n = fps_n; + self->priv->fps_d = fps_d; gst_validate_reporter_set_name (GST_VALIDATE_REPORTER (self), g_strdup ("gst-validate-images-checker")); diff --git a/validate/gst-libs/gst/video/gstvalidatessim.h b/validate/gst-libs/gst/video/gstvalidatessim.h index c47bac6b55..52c7e55e28 100644 --- a/validate/gst-libs/gst/video/gstvalidatessim.h +++ b/validate/gst-libs/gst/video/gstvalidatessim.h @@ -60,7 +60,9 @@ GType gst_validate_ssim_get_type (void); GstValidateSsim * gst_validate_ssim_new (GstValidateRunner *runner, gfloat min_avg_similarity, - gfloat min_lowest_similarity); + gfloat min_lowest_similarity, + gint fps_n, + gint fps_d); gboolean gst_validate_ssim_compare_image_files (GstValidateSsim *self, const gchar *ref_file, const gchar * file, gfloat * mean, gfloat * lowest, diff --git a/validate/plugins/ssim/gstvalidatessim.c b/validate/plugins/ssim/gstvalidatessim.c index 72f871d2f4..8b7e6697d6 100644 --- a/validate/plugins/ssim/gstvalidatessim.c +++ b/validate/plugins/ssim/gstvalidatessim.c @@ -129,6 +129,7 @@ runner_stopping (GstValidateRunner * runner, ValidateSsimOverride * self) const gchar *compared_files_dir = gst_structure_get_string (self->priv->config, "reference-images-dir"); + gint fps_n = 0, fps_d = 1; if (!self->priv->is_attached) { gchar *config_str = gst_structure_to_string (self->priv->config); @@ -154,8 +155,10 @@ runner_stopping (GstValidateRunner * runner, ValidateSsimOverride * self) gst_structure_get_double (self->priv->config, "min-lowest-priority", &min_lowest_similarity); + gst_structure_get_fraction (self->priv->config, "framerate", &fps_n, &fps_d); ssim = - gst_validate_ssim_new (runner, min_avg_similarity, min_lowest_similarity); + gst_validate_ssim_new (runner, min_avg_similarity, min_lowest_similarity, + fps_n, fps_d); nfiles = self->priv->frames->len; for (i = 0; i < nfiles; i++) { @@ -180,10 +183,10 @@ runner_stopping (GstValidateRunner * runner, ValidateSsimOverride * self) min_avg = MIN (min_avg, mssim); min_min = MIN (lowest, min_min); total_avg += mssim; - gst_validate_print_position(frame->position, GST_CLOCK_TIME_NONE, 1.0, - g_strdup_printf(" %d / %d avg: %f min: %f (Passed: %d failed: %d)", + gst_validate_print_position (frame->position, GST_CLOCK_TIME_NONE, 1.0, + g_strdup_printf (" %d / %d avg: %f min: %f (Passed: %d failed: %d)", i + 1, nfiles, mssim, lowest, npassed, nfailures)); - g_free(bname); + g_free (bname); } gst_validate_printf (NULL, diff --git a/validate/tools/gst-validate-images-check.c b/validate/tools/gst-validate-images-check.c index 6a7d29f264..518de1e7ff 100644 --- a/validate/tools/gst-validate-images-check.c +++ b/validate/tools/gst-validate-images-check.c @@ -93,7 +93,8 @@ main (int argc, char **argv) runner = gst_validate_runner_new (); ssim = - gst_validate_ssim_new (runner, min_avg_similarity, min_lowest_similarity); + gst_validate_ssim_new (runner, min_avg_similarity, min_lowest_similarity, + 0, 1); gst_validate_ssim_compare_image_files (ssim, argv[1], argv[2], &mssim, &lowest, &highest, outfolder);