From 9dd1d7f1ba889a007bfb120505a67d7dec5ebf33 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Thu, 20 May 2010 10:46:38 +0200 Subject: [PATCH] examples: New concatenate examples. Allows concatenating several files of the same type together --- tests/examples/.gitignore | 3 +- tests/examples/Makefile.am | 5 +- tests/examples/concatenate.c | 182 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 186 insertions(+), 4 deletions(-) create mode 100644 tests/examples/concatenate.c diff --git a/tests/examples/.gitignore b/tests/examples/.gitignore index b39bcb5..abe6173 100644 --- a/tests/examples/.gitignore +++ b/tests/examples/.gitignore @@ -1,5 +1,4 @@ -playlist -simple1 +concatenate test1 test2 test3 diff --git a/tests/examples/Makefile.am b/tests/examples/Makefile.am index d5bac25..e301452 100644 --- a/tests/examples/Makefile.am +++ b/tests/examples/Makefile.am @@ -1,4 +1,5 @@ noinst_PROGRAMS = \ + concatenate \ playlist \ simple1 \ test1 \ @@ -6,5 +7,5 @@ noinst_PROGRAMS = \ test3 \ test4 -AM_CFLAGS = -I$(top_srcdir) $(GST_PROFILE_CFLAGS) $(GST_CFLAGS) -LDADD = $(top_builddir)/ges/libges-@GST_MAJORMINOR@.la -lges-@GST_MAJORMINOR@ $(GST_PROFILE_LIBS) $(GST_LIBS) +AM_CFLAGS = -I$(top_srcdir) $(GST_PROFILE_CFLAGS) $(GST_DISCOVERER_CFLAGS) $(GST_CFLAGS) +LDADD = $(top_builddir)/ges/libges-@GST_MAJORMINOR@.la -lges-@GST_MAJORMINOR@ -lgstdiscoverer-@GST_MAJORMINOR@ $(GST_DISCOVERER_LIBS) $(GST_LIBS) diff --git a/tests/examples/concatenate.c b/tests/examples/concatenate.c new file mode 100644 index 0000000..de234b4 --- /dev/null +++ b/tests/examples/concatenate.c @@ -0,0 +1,182 @@ +/* GStreamer Editing Services + * Copyright (C) 2010 Edward Hervey + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include +#include + +GstDiscovererInformation * +get_info_for_file (GstDiscoverer * disco, gchar * filename) +{ + GError *err; + gchar *path, *uri; + + /* Convert to a URI */ + if (!g_path_is_absolute (filename)) { + gchar *cur_dir; + + cur_dir = g_get_current_dir (); + path = g_build_filename (cur_dir, filename, NULL); + g_free (cur_dir); + } else { + path = g_strdup (filename); + } + + uri = g_filename_to_uri (path, NULL, &err); + g_free (path); + path = NULL; + + /* Get information */ + return gst_discoverer_discover_uri (disco, uri, &err); +} + +static GstEncodingProfile * +make_profile_from_info (GstDiscovererInformation * info) +{ + GstEncodingProfile *profile = NULL; + + /* Get the container format */ + if (info->stream_info->streamtype == GST_STREAM_CONTAINER) { + GstStreamContainerInformation *container = + GST_STREAM_CONTAINER_INFORMATION (info->stream_info); + GList *tmp; + + profile = gst_encoding_profile_new ("concatenate", + gst_caps_copy (info->stream_info->caps), NULL, FALSE); + /* For each on the formats add stream profiles */ + for (tmp = container->streams; tmp; tmp = tmp->next) { + GstStreamInformation *stream = GST_STREAM_INFORMATION (tmp->data); + GstStreamEncodingProfile *sprof; + + sprof = + gst_stream_encoding_profile_new (stream->streamtype == + GST_STREAM_VIDEO ? GST_ENCODING_PROFILE_VIDEO : + GST_ENCODING_PROFILE_AUDIO, gst_caps_copy (stream->caps), NULL, + NULL, 1); + gst_encoding_profile_add_stream (profile, sprof); + } + } else { + GST_ERROR ("No container format !!!"); + } + + return profile; +} + +static void +bus_message_cb (GstBus * bus, GstMessage * message, GMainLoop * mainloop) +{ + switch (GST_MESSAGE_TYPE (message)) { + case GST_MESSAGE_ERROR: + g_print ("ERROR\n"); + g_main_loop_quit (mainloop); + break; + case GST_MESSAGE_EOS: + g_print ("Done\n"); + g_main_loop_quit (mainloop); + break; + default: + break; + } +} + +int +main (int argc, gchar ** argv) +{ + GESTimelinePipeline *pipeline; + GESTimeline *timeline; + GESTimelineLayer *layer; + GList *sources = NULL; + GMainLoop *mainloop; + GstEncodingProfile *profile; + gchar *output_uri; + guint i; + gboolean gotprofile = FALSE; + GstDiscoverer *disco; + GstBus *bus; + + if (argc < 3) { + g_print ("Usage: %s \n", argv[0]); + return -1; + } + + gst_init (&argc, &argv); + ges_init (); + + timeline = ges_timeline_new_audio_video (); + + layer = (GESTimelineLayer *) ges_simple_timeline_layer_new (); + if (!ges_timeline_add_layer (timeline, layer)) + return -1; + + disco = gst_discoverer_new (10 * GST_SECOND); + + for (i = 2; i < argc; i++) { + GstDiscovererInformation *info; + GESTimelineFileSource *src; + + info = get_info_for_file (disco, argv[i]); + + if (!gotprofile) { + profile = make_profile_from_info (info); + gotprofile = TRUE; + } + + src = ges_timeline_filesource_new (info->uri); + g_object_set (src, "duration", info->duration, NULL); + /* Since we're using a GESSimpleTimelineLayer, objects will be automatically + * appended to the end of the layer */ + ges_timeline_layer_add_object (layer, (GESTimelineObject *) src); + + gst_discoverer_information_free (info); + sources = g_list_append (sources, src); + } + + /* In order to view our timeline, let's grab a convenience pipeline to put + * our timeline in. */ + pipeline = ges_timeline_pipeline_new (); + + /* Add the timeline to that pipeline */ + if (!ges_timeline_pipeline_add_timeline (pipeline, timeline)) + return -1; + + + /* RENDER SETTINGS ! */ + /* We set our output URI and rendering setting on the pipeline */ + output_uri = argv[1]; + if (!ges_timeline_pipeline_set_render_settings (pipeline, output_uri, + profile)) + return -1; + + /* We want the pipeline to render (without any preview) */ + if (!ges_timeline_pipeline_set_mode (pipeline, TIMELINE_MODE_SMART_RENDER)) + return -1; + + + mainloop = g_main_loop_new (NULL, FALSE); + + bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); + gst_bus_add_signal_watch (bus); + g_signal_connect (bus, "message", G_CALLBACK (bus_message_cb), mainloop); + + gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); + + g_main_loop_run (mainloop); + + return 0; +} -- 2.7.4