[pitivi] render: Set format in video caps as part of ensure restriction caps



commit a8ea529bb4b7735b272618f6d3b0445b93678f35
Author: Thibault Saunier <tsaunier gnome org>
Date:   Tue Aug 15 11:18:01 2017 -0300

    render: Set format in video caps as part of ensure restriction caps
    
    And make it uses any of the avalaible raw video formats. This also
    allows us to remove the where we were specially setting it.
    
    Fixes T7808
    
    Reviewed-by: Mathieu Duponchelle <mathieu duponchelle epitech eu>
    Differential Revision: https://phabricator.freedesktop.org/D1840

 pitivi/check.py      |    1 +
 pitivi/project.py    |   29 ++++++++++++++++++++++++++---
 pitivi/render.py     |   21 ---------------------
 pitivi/utils/misc.py |    8 ++++----
 4 files changed, 31 insertions(+), 28 deletions(-)
---
diff --git a/pitivi/check.py b/pitivi/check.py
index e5c9b72..67ba57e 100644
--- a/pitivi/check.py
+++ b/pitivi/check.py
@@ -393,6 +393,7 @@ HARD_DEPENDENCIES = [GICheck("3.20.0"),
                      GstDependency("Gst", GST_API_VERSION, "1.10.2"),
                      GstDependency("GES", GST_API_VERSION, "1.10.2"),
                      GIDependency("GstTranscoder", GST_API_VERSION),
+                     GIDependency("GstVideo", GST_API_VERSION),
                      GtkDependency("Gtk", GTK_API_VERSION, "3.20.0"),
                      ClassicDependency("numpy"),
                      GIDependency("Gio", "2.0"),
diff --git a/pitivi/project.py b/pitivi/project.py
index 8f81aea..683e716 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -30,6 +30,7 @@ from gi.repository import GLib
 from gi.repository import GObject
 from gi.repository import Gst
 from gi.repository import GstPbutils
+from gi.repository import GstVideo
 from gi.repository import Gtk
 
 from pitivi.configure import get_ui_dir
@@ -45,7 +46,6 @@ from pitivi.utils.misc import path_from_uri
 from pitivi.utils.misc import quote_uri
 from pitivi.utils.misc import unicode_error_dialog
 from pitivi.utils.pipeline import Pipeline
-from pitivi.utils.pipeline import PipelineError
 from pitivi.utils.ripple_update_group import RippleUpdateGroup
 from pitivi.utils.ui import audio_channels
 from pitivi.utils.ui import audio_rates
@@ -74,6 +74,20 @@ ENCODERS_RESTRICTIONS_SETTER = {
         profile, "format", "Y444")
 }
 
+ALL_RAW_VIDEO_FORMATS = []
+# Starting at 2 as 0 is UNKNOWN and 1 is ENCODED.
+# We want to make sure we do not try to force ENCODED
+# format (as it won't be possible as we have a compositor
+# in the pipeline) but we enforce a same VideoFormat is
+# used during the whole encoding process.
+for i in range(2, GLib.MAXINT):
+    try:
+        vformat = GstVideo.VideoFormat(i)
+        ALL_RAW_VIDEO_FORMATS.append(
+            GstVideo.VideoFormat.to_string(vformat))
+    except ValueError:
+        break
+
 
 class ProjectManager(GObject.Object, Loggable):
     """The project manager.
@@ -777,6 +791,9 @@ class Project(Loggable, GES.Project):
 
     # Encoding related properties
     def set_rendering(self, rendering):
+        self._ensureAudioRestrictions()
+        self._ensureVideoRestrictions()
+
         video_restrictions = self.video_profile.get_restriction().copy_nth(0)
         video_restrictions_struct = video_restrictions[0]
 
@@ -1529,19 +1546,25 @@ class Project(Loggable, GES.Project):
             "width": 720,
             "height": 576,
             "framerate": Gst.Fraction(25, 1),
-            "pixel-aspect-ratio": Gst.Fraction(1, 1)
+            "pixel-aspect-ratio": Gst.Fraction(1, 1),
+            "format": Gst.ValueArray(ALL_RAW_VIDEO_FORMATS),
+
         }
 
         prev_vals = None
         if self.video_profile:
             prev_vals = self.video_profile.get_restriction().copy()
 
-        ref_restrictions = None
         if not profile:
             profile = self.video_profile
+            ref_restrictions = Gst.Caps("video/x-raw")
         else:
             ref_restrictions = profile.get_restriction()
 
+        for struct in ref_restrictions:
+            if not struct["format"]:
+                struct["format"] = Gst.ValueArray(ALL_RAW_VIDEO_FORMATS)
+
         self._ensureRestrictions(profile, defaults, ref_restrictions,
                                  prev_vals)
 
diff --git a/pitivi/render.py b/pitivi/render.py
index 019939e..1f791b8 100644
--- a/pitivi/render.py
+++ b/pitivi/render.py
@@ -979,27 +979,6 @@ class RenderDialog(Loggable):
         # Hide the rendering settings dialog while rendering
         self.window.hide()
 
-        encoder_string = self.project.vencoder
-        try:
-            fmt = self._factory_formats[encoder_string]
-            self.project.video_profile.get_restriction()[0]["format"] = fmt
-        except KeyError:
-            # Now find a format to set on the restriction caps.
-            # The reason is we can't send different formats on the encoders.
-            factory = Encoders().factories_by_name.get(self.project.vencoder)
-            for struct in factory.get_static_pad_templates():
-                if struct.direction == Gst.PadDirection.SINK:
-                    caps = Gst.Caps.from_string(struct.get_caps().to_string())
-                    # FIXME HACK! - remove once https://bugzilla.gnome.org/show_bug.cgi?id=784960
-                    # is fixed.
-                    caps.mini_object.refcount += 1
-
-                    fixed = caps.fixate()
-                    fmt = fixed.get_structure(0).get_value("format")
-                    self.project.setVideoRestriction("format", fmt)
-                    self._factory_formats[encoder_string] = fmt
-                    break
-
         self.app.gui.timeline_ui.timeline.set_best_zoom_ratio(allow_zoom_in=True)
         self.project.set_rendering(True)
         self._pipeline.set_render_settings(
diff --git a/pitivi/utils/misc.py b/pitivi/utils/misc.py
index 3b229e3..ba16e84 100644
--- a/pitivi/utils/misc.py
+++ b/pitivi/utils/misc.py
@@ -342,8 +342,8 @@ def fixate_caps_with_default_values(template, restrictions, default_values,
         for struct in restrictions:
             fields.update(struct.keys())
 
-        log.debug("utils", "Intersect template %s with the restriction %s",
-                  template, restrictions)
+        log.log("utils", "Intersect template %s with the restriction %s",
+                template, restrictions)
         tmp = template.intersect(restrictions)
 
         if not tmp:
@@ -378,8 +378,8 @@ def fixate_caps_with_default_values(template, restrictions, default_values,
                     if v is not None:
                         struct[field] = v
                 else:
-                    log.info("utils", "Field %s from %s is plainly fixated",
-                             field, struct)
+                    log.debug("utils", "Field %s from %s is plainly fixated",
+                              field, struct)
 
         struct = struct.copy()
         for key in struct.keys():


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]