Skip to content

Instantly share code, notes, and snippets.

@ManasJayanth
Last active November 23, 2018 11:35
Show Gist options
  • Save ManasJayanth/7a6da0384ddadfe787c4f11773fdc6cc to your computer and use it in GitHub Desktop.
Save ManasJayanth/7a6da0384ddadfe787c4f11773fdc6cc to your computer and use it in GitHub Desktop.
Agingtv works but text doesnt
#include <ges/ges.h>
#define MAX_GES_LAYERS 100
GESTimeline* prepare_ges_timeline(const GESLayer **layers, int n_layers);
GESPipeline* prepare_ges_pipeline(GESTimeline* timeline, gboolean preview);
int run_ges_pipeline(GESPipeline *pipeline, gdouble duration, gboolean preview);
GESTimeline* prepare_ges_timeline(const GESLayer **layers, int n_layers) {
GESTimeline *timeline;
GESTrack *v, *a;
v = GES_TRACK(ges_video_track_new ());
a = GES_TRACK(ges_audio_track_new ());
timeline = ges_timeline_new ();
ges_timeline_add_track(timeline, v);
ges_timeline_add_track(timeline, a);
for (int i = 0; i < n_layers; ++i) {
ges_timeline_add_layer(timeline, layers[i]);
}
return timeline;
}
GESPipeline* prepare_ges_pipeline(GESTimeline* timeline, gboolean preview) {
GESPipeline *pipeline = ges_pipeline_new ();
ges_pipeline_set_timeline(pipeline, timeline);
if (preview == TRUE) {
ges_pipeline_set_mode (pipeline, GES_PIPELINE_MODE_PREVIEW);
} else {
ges_pipeline_set_mode (pipeline, GES_PIPELINE_MODE_RENDER);
}
return pipeline;
}
int run_ges_pipeline(GESPipeline *pipeline, gdouble duration, gboolean preview) {
GMainLoop *mainloop;
GstStateChangeReturn state_change_return;
state_change_return = gst_element_set_state (GST_ELEMENT (pipeline),
GST_STATE_PLAYING);
if (state_change_return == GST_STATE_CHANGE_FAILURE) {
g_printerr ("Unable to set the pipeline to the playing state.\n");
gst_object_unref (pipeline);
return -1;
}
if (preview == TRUE) {
mainloop = g_main_loop_new (NULL, FALSE);
g_timeout_add_seconds (duration,
(GSourceFunc) g_main_loop_quit,
mainloop);
g_main_loop_run (mainloop);
} else {
GstBus *bus = gst_element_get_bus (pipeline);
GstMessage *msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
/* Parse message */
if (msg != NULL) {
GError *err;
gchar *debug_info;
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_ERROR:
gst_message_parse_error (msg, &err, &debug_info);
g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message);
g_printerr ("Debugging information: %s\n", debug_info ? debug_info : "none");
g_clear_error (&err);
g_free (debug_info);
break;
case GST_MESSAGE_EOS:
g_print("Done");
break;
default:
/* We should not reach here because we only asked for ERRORs and EOS */
g_printerr ("Unexpected message received.\n");
break;
}
gst_message_unref (msg);
}
}
return 0;
}
void child_added(GESContainer *c, GESTrackElement *timeline_element, gpointer user_data) {
g_print("child added\n");
ges_timeline_commit_sync(user_data);
}
void core(gchar** videos, int length, gchar* output_file) {
GESPipeline *pipeline;
GESTimeline *timeline;
GESClip *clips[1000];
GESLayer *layers[MAX_GES_LAYERS];
gboolean preview = TRUE;
gdouble duration = 0;
gint n_clips = 0;
gst_init(NULL, NULL);
ges_init();
GESLayer *layer;
layer = ges_layer_new ();
g_object_set (layer, "priority", 1, NULL);
for (int i = 0; i < length; i++) {
gchar *uri = gst_filename_to_uri (videos[i], NULL);
g_print ("Adding %s to timeline...\n", uri);
GESClip *clip = GES_CLIP(ges_uri_clip_new (uri));
guint64 clip_duration = (guint64) 3 * GST_SECOND;
g_object_set (clip,
"start", (guint64) 3 * i * GST_SECOND,
"duration", clip_duration,
"priority", (guint32) 5,
"in-point", (guint64) 0,
NULL);
duration += (gdouble) 3;
ges_layer_add_clip(layer, clip);
clips[i] = clip;
n_clips += 1;
}
layers[0] = layer;
timeline = prepare_ges_timeline(layers, 1);
for (int i = 0; i < n_clips; ++i) {
GESClip *clip = clips[i];
GESTimelineElement *timeline_element = GES_TIMELINE_ELEMENT(ges_effect_new("textoverlay text=\"Room A\" valignment=top halignment=left font-desc=\"Sans, 72\""));
/* GESTimelineElement *timeline_element = GES_TIMELINE_ELEMENT(ges_effect_new("agingtv")); */
ges_container_add(clip, timeline_element);
g_object_set(timeline_element,
"start", (guint64) 3 * i * GST_SECOND,
"duration", 3 * GST_SECOND,
/* "priority", (guint32) 0, */
"in-point", (guint64) 0,
NULL);
g_signal_connect(clip, "child-added", child_added, timeline);
}
ges_timeline_commit_sync(timeline);
pipeline = prepare_ges_pipeline(timeline, preview);
return run_ges_pipeline(pipeline, duration, preview);
}
int main(int argc, char**argv) {
gchar* output_file = argv[1];
gchar* va = argv[2];
gchar* vb = argv[3];
gchar* vc = argv[4];
gchar* videos[] = { vb }; //, vb, vc };
core(videos, 1, output_file);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment