ges: Add keyframe support to the command line formatter
authorThibault Saunier <tsaunier@igalia.com>
Fri, 15 Jan 2021 12:27:31 +0000 (09:27 -0300)
committerThibault Saunier <tsaunier@igalia.com>
Wed, 10 Feb 2021 19:14:47 +0000 (16:14 -0300)
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-editing-services/-/merge_requests/227>

ges/ges-command-line-formatter.c
ges/ges-structure-parser.c
ges/parse.l

index a0c7592..475cf5f 100644 (file)
@@ -53,6 +53,9 @@ _ges_command_line_formatter_add_title_clip (GESTimeline * timeline,
 static gboolean
 _ges_command_line_formatter_add_track (GESTimeline * timeline,
     GstStructure * structure, GError ** error);
+static gboolean
+_ges_command_line_formatter_add_keyframes (GESTimeline * timeline,
+    GstStructure * structure, GError ** error);
 
 typedef struct
 {
@@ -267,6 +270,31 @@ static GESCommandLineOption options[] = {
     },
   },
   {
+    .long_name="keyframes",
+    .short_name='k',
+    .callback=(ActionFromStructureFunc) _ges_command_line_formatter_add_keyframes,
+    .synopsis="<property name>",
+    .description="Adds keyframes for the specified property in the form:\n\n",
+    .examples="    ges-launch-1.0 +test-clip blue d=1.0 +keyframes posx 0=0 1.0=1280 t=direct-absolute +k posy 0=0 1.0=720 t=direct-absolute\n\n"
+              "This add a testclip that will disappear in the bottom right corner",
+    .properties={
+      {"property-name", 0, 0, NULL, NULL},
+      {
+        "binding-type", "t", 0, NULL,
+        "The type of binding to use, eg. 'direct-absolute', 'direct'"
+      },
+      {
+        "interpolation-mode", "m", 0, NULL,
+        "The GstInterpolationMode to user."
+      },
+      {
+        "...", 0, 0, NULL,
+        "The list of keyframe_timestamp=value to be set."
+      },
+      {NULL, 0, 0, NULL, FALSE},
+    },
+  },
+  {
     .long_name="set-",
     .short_name=0,
     .callback=NULL,
@@ -297,6 +325,7 @@ typedef enum
   TEST_CLIP,
   TITLE,
   TRACK,
+  KEYFRAMES,
   SET,
 } GESCommandLineOptionType;
 
@@ -382,13 +411,19 @@ _cleanup_fields (const Property * field_names, GstStructure * structure,
     gboolean exists = FALSE;
 
     /* Move shortly named fields to longname variante */
-    if (gst_structure_has_field (structure, field_names[i].short_name)) {
+    if (field_names[i].short_name &&
+        gst_structure_has_field (structure, field_names[i].short_name)) {
       exists = TRUE;
 
       if (gst_structure_has_field (structure, field_names[i].long_name)) {
-        *error = g_error_new (GES_ERROR, 0, "Using short and long name"
-            " at the same time for property: %s, which one should I use?!",
-            field_names[i].long_name);
+        gchar *str_info = gst_structure_serialize (structure, 0);
+
+        *error =
+            g_error_new (GES_ERROR, 0,
+            "Using short (%s) and long name (%s)"
+            " at the same time s in %s, which one should I use?!",
+            field_names[i].short_name, field_names[i].long_name, str_info);
+        g_free (str_info);
 
         return FALSE;
       } else {
@@ -480,6 +515,19 @@ _ges_command_line_formatter_add_title_clip (GESTimeline * timeline,
 }
 
 static gboolean
+_ges_command_line_formatter_add_keyframes (GESTimeline * timeline,
+    GstStructure * structure, GError ** error)
+{
+  if (!_cleanup_fields (options[KEYFRAMES].properties, structure, error))
+    return FALSE;
+
+  if (!_ges_set_control_source_from_struct (timeline, structure, error))
+    return FALSE;
+
+  return _ges_add_remove_keyframe_from_struct (timeline, structure, error);
+}
+
+static gboolean
 _ges_command_line_formatter_add_track (GESTimeline * timeline,
     GstStructure * structure, GError ** error)
 {
index 327b2a2..d84d64b 100644 (file)
@@ -151,6 +151,10 @@ ges_structure_parser_parse_symbol (GESStructureParser * self,
     ges_structure_parser_parse_string (self, "title, text=(string)", TRUE);
   else if (!g_ascii_strncasecmp (symbol, "track", 5))
     ges_structure_parser_parse_string (self, "track, type=(string)", TRUE);
+  else if (!g_ascii_strncasecmp (symbol, "keyframes", 8)) {
+    ges_structure_parser_parse_string (self,
+        "keyframes, property-name=(string)", TRUE);
+  }
 }
 
 void
index da8743f..712d05d 100644 (file)
@@ -17,6 +17,7 @@ TRANSITION      [ ]+\+transition[ ]+
 EFFECT          [ ]+\+effect[ ]+
 TITLE           [ ]+\+title[ ]+
 TRACK           [ ]+\+track[ ]+
+KEYFRAME        [ ]+\+keyframes[ ]+
 
 SETTER          [ ]+set-[^ ]+[ ]+
 
@@ -36,7 +37,7 @@ VALUE           {STRING}|([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0
                ges_structure_parser_parse_string (yyextra, yytext, FALSE);
 }
 
-{TRACK}|{CLIP}|{TRANSITION}|{EFFECT}|{TEST_CLIP}|{TITLE}   {
+{KEYFRAME}|{TRACK}|{CLIP}|{TRANSITION}|{EFFECT}|{TEST_CLIP}|{TITLE}   {
                ges_structure_parser_parse_symbol (yyextra, yytext);
 }