examples: add video inversion sample

parent f548f6ee
......@@ -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
......
#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;
}
#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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment