ges/videourisource: handle non-1/1 PAR source videos
[platform/upstream/gstreamer.git] / subprojects / gst-editing-services / ges / ges-video-uri-source.c
index 3eef67b..fe6d514 100644 (file)
@@ -108,6 +108,7 @@ ges_video_uri_source_get_natural_size (GESVideoSource * source, gint * width,
   const GstTagList *tags = NULL;
   gchar *rotation_info = NULL;
   gint videoflip_method, rotate_angle;
+  guint par_n, par_d;
   GstDiscovererVideoInfo *info =
       _get_video_stream_info (GES_VIDEO_URI_SOURCE (source));
 
@@ -116,6 +117,21 @@ ges_video_uri_source_get_natural_size (GESVideoSource * source, gint * width,
 
   *width = gst_discoverer_video_info_get_width (info);
   *height = gst_discoverer_video_info_get_height (info);
+
+  /* account for source video PAR being not 1/1 */
+  par_n = gst_discoverer_video_info_get_par_num (info);
+  par_d = gst_discoverer_video_info_get_par_denom (info);
+
+  if (par_n > 0 && par_d > 0) {
+    if (*height % par_n == 0) {
+      *height = gst_util_uint64_scale_int (*height, par_d, par_n);
+    } else if (*width % par_d == 0) {
+      *height = gst_util_uint64_scale_int (*width, par_n, par_d);
+    } else {
+      *width = gst_util_uint64_scale_int (*height, par_d, par_n);
+    }
+  }
+
   if (!ges_timeline_element_lookup_child (GES_TIMELINE_ELEMENT (source),
           "GstVideoFlip::video-direction", NULL, NULL))
     goto done;
@@ -151,11 +167,14 @@ done:
   return TRUE;
 
 rotate:
-  GST_INFO_OBJECT (source, "Stream is rotated, taking that into account");
-  *width =
-      gst_discoverer_video_info_get_height (GST_DISCOVERER_VIDEO_INFO (info));
-  *height =
-      gst_discoverer_video_info_get_width (GST_DISCOVERER_VIDEO_INFO (info));
+  {
+    gint tmp;
+
+    GST_INFO_OBJECT (source, "Stream is rotated, taking that into account");
+    tmp = *width;
+    *width = *height;
+    *height = tmp;
+  }
 
   goto done;
 }