[gegl/video-rejuvenation: 60/60] examples: add video inversion sample



commit edad02635cef626cb2cb48f6f7c0f9b5d75d836b
Author: Øyvind Kolås <pippin gimp org>
Date:   Mon Nov 16 23:11:09 2015 +0100

    examples: add video inversion sample

 examples/Makefile.am     |    4 ++
 examples/frame-counter.c |   63 ++++++++++++++++++++++++++++++++
 examples/video-invert.c  |   89 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 156 insertions(+), 0 deletions(-)
---
diff --git a/examples/Makefile.am b/examples/Makefile.am
index edc1186..cd0cef7 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -36,14 +36,18 @@ bin_PROGRAMS = \
        2geglbuffer \
        gegl-convert \
        gegl-slicer \
+       video-invert \
         gegl-video \
        geglbuffer-add-image \
        geglbuffer-clock \
+       frame-counter \
        hello-world
 
+frame_counter_SOURCES = frame-counter.c
 2geglbuffer_SOURCES = 2geglbuffer.c
 gegl_convert_SOURCES = gegl-convert.c
 gegl_slicer_SOURCES = gegl-slicer.c
+video_invert_SOURCES = video-invert.c
 geglbuffer_add_image_SOURCES = geglbuffer-add-image.c
 geglbuffer_clock_SOURCES = geglbuffer-clock.c
 hello_world_SOURCES = hello-world.c
diff --git a/examples/frame-counter.c b/examples/frame-counter.c
new file mode 100644
index 0000000..98da893
--- /dev/null
+++ b/examples/frame-counter.c
@@ -0,0 +1,63 @@
+#include <gegl.h>
+#include <stdio.h>
+
+const char *output_path = "frame-counter.ogv";
+
+gint
+main (gint    argc,
+      gchar **argv)
+{
+  if (argv[1])
+    output_path = argv[1];
+
+  gegl_init (&argc, &argv);  /* initialize the GEGL library */
+  {
+    GeglNode *gegl  = gegl_node_new ();
+    GeglNode *store = gegl_node_new_child (gegl,
+                              "operation", "gegl:ff-save",
+                              "path", output_path,
+                              "video-bitrate", 1024 * 1024,
+                              "frame-rate", 24.0,
+                              NULL);
+    GeglNode *crop    = gegl_node_new_child (gegl,
+                              "operation", "gegl:crop",
+                              "width", 512.0,
+                              "height", 384.0,
+                               NULL);
+    GeglNode *over    = gegl_node_new_child (gegl,
+                              "operation", "gegl:over",
+                              NULL);
+    GeglNode *text    = gegl_node_new_child (gegl,
+                              "operation", "gegl:text",
+                              "size", 120.0,
+                              "color", gegl_color_new ("rgb(1.0,0.0,1.0)"),
+                              NULL);
+    GeglNode *bg      = gegl_node_new_child (gegl,
+                             "operation", "gegl:color",
+                              "value", gegl_color_new ("rgb(0.1,0.2,0.3)"),
+                             NULL);
+
+    gegl_node_link_many (bg, over, crop, store, NULL);
+    gegl_node_connect_to (text, "output",  over, "aux");
+
+    {
+      gint frame;
+      gint frames = 64;
+
+      for (frame=0; frame < frames; frame++)
+        {
+          gchar string[512];
+          gdouble t = frame * 1.0/frames;
+#define INTERPOLATE(min,max) ((max)*(t)+(min)*(1.0-t))
+
+          sprintf (string, "#%i\n%1.2f%%", frame, t*100);
+          gegl_node_set (text, "string", string, NULL);
+          fprintf (stderr, "\r%i% 1.2f%% ", frame, t*100);
+          gegl_node_process (store);
+        }
+    }
+    g_object_unref (gegl);
+  }
+  gegl_exit ();
+  return 0;
+}
diff --git a/examples/video-invert.c b/examples/video-invert.c
new file mode 100644
index 0000000..afa9f27
--- /dev/null
+++ b/examples/video-invert.c
@@ -0,0 +1,89 @@
+#include <gegl.h>
+#include <stdio.h>
+
+GeglNode *gegl_dec;
+
+GeglNode   *decode, *store_buf;
+GeglBuffer *buffer = NULL;
+
+GeglNode *gegl_enc;
+GeglNode *load_buf, *invert, *encode, *invert2, *invert3;
+
+const char *input_path = "input.ogv";
+const char *output_path = "output.ogv";
+
+gdouble fps;
+
+gint
+main (gint argc,
+      gchar **argv)
+{
+  
+  if (argv[1])
+  {
+    input_path = argv[1];
+    if (argv[2])
+      output_path = argv[2];
+  }
+
+
+  gegl_init (&argc, &argv);
+
+  gegl_dec  = gegl_node_new ();
+  decode = gegl_node_new_child (gegl_dec, "operation", "gegl:ff-load", "path", input_path, NULL);
+  store_buf = gegl_node_new_child (gegl_dec, "operation", "gegl:buffer-sink", "buffer", &buffer, NULL);
+  gegl_node_link_many (decode, store_buf, NULL);
+  
+  gegl_enc = gegl_node_new ();
+  load_buf = gegl_node_new_child (gegl_enc, "operation", "gegl:buffer-source", NULL);
+  //invert = gegl_node_new_child (gegl_enc,   "operation", "gegl:snn-mean", NULL);
+  invert = gegl_node_new_child (gegl_enc,   "operation", "gegl:invert", NULL);
+  invert2 = gegl_node_new_child (gegl_enc,  "operation", "gegl:snn-mean", NULL);
+  invert3 = gegl_node_new_child (gegl_enc,  "operation", "gegl:snn-mean", NULL);
+  encode = gegl_node_new_child (gegl_dec,   "operation", "gegl:ff-save", "path", output_path, NULL);
+
+  gegl_node_link_many (load_buf, invert, /*invert2, invert3,*/ encode, NULL);
+
+  {
+    gint frame_no;
+    gint frame_count = 100;
+    gint audio_sample_rate = 44100;
+    gint audio_channels = 0;
+
+    for (frame_no = 0; frame_no < frame_count; frame_no++)
+    {
+      GeglAudio *audio;
+      fprintf (stderr, "\r%i/%i", frame_no, frame_count);
+      gegl_node_set (decode, "frame", frame_no, NULL);
+      if (buffer){
+        g_object_unref (buffer);
+        buffer = NULL;
+      }
+      gegl_node_process (store_buf);
+      if (buffer)
+      {
+        if (frame_no == 0)
+        {
+          gegl_node_get (decode, "frame-rate", &fps, 
+            //                   "frames", &frame_count, 
+                                 "audio-sample-rate", &audio_sample_rate, 
+                                 "audio-channels", &audio_channels,
+                                 NULL);
+          fprintf (stderr, "frame-rate: %f\n", fps);
+          gegl_node_set (encode, "frame-rate", fps, NULL);
+        }
+        gegl_node_get (decode, "audio", &audio, NULL);
+        gegl_node_set (encode, "audio", audio, NULL);
+        gegl_node_set (load_buf, "buffer", buffer, NULL);
+        gegl_node_process (encode);
+      }
+    }
+  }
+  fprintf (stderr, "\n");
+  g_object_unref (gegl_enc);
+  g_object_unref (gegl_dec);
+  g_object_unref (buffer);
+
+  gegl_exit ();
+  return 0;
+}


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