1 /* GStreamer Editing Services
2 * Copyright (C) 2009 Edward Hervey <bilboed@bilboed.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #include <gst/pbutils/encoding-profile.h>
23 GstEncodingProfile *make_encoding_profile (gchar * audio, gchar * container);
25 /* This example will take a series of files and create a audio-only timeline
26 * containing the first second of each file and render it to the output uri
29 /* make_encoding_profile
30 * simple method creating an encoding profile. This is here in
31 * order not to clutter the main function. */
33 make_encoding_profile (gchar * audio, gchar * container)
35 GstEncodingContainerProfile *profile;
36 GstEncodingProfile *stream;
39 caps = gst_caps_from_string (container);
41 gst_encoding_container_profile_new ((gchar *) "ges-test4", NULL, caps,
43 gst_caps_unref (caps);
45 caps = gst_caps_from_string (audio);
46 stream = (GstEncodingProfile *)
47 gst_encoding_audio_profile_new (caps, NULL, NULL, 0);
48 gst_encoding_container_profile_add_profile (profile, stream);
49 gst_caps_unref (caps);
51 return (GstEncodingProfile *) profile;
55 main (int argc, gchar ** argv)
57 GESPipeline *pipeline;
58 GESTimeline *timeline;
62 GstEncodingProfile *profile;
63 gchar *container = (gchar *) "application/ogg";
64 gchar *audio = (gchar *) "audio/x-vorbis";
68 GOptionEntry options[] = {
69 {"format", 'f', 0, G_OPTION_ARG_STRING, &container,
70 "Container format", "<GstCaps>"},
71 {"aformat", 'a', 0, G_OPTION_ARG_STRING, &audio,
72 "Audio format", "<GstCaps>"},
77 ctx = g_option_context_new ("- renders a sequence of audio files.");
78 g_option_context_add_main_entries (ctx, options, NULL);
79 g_option_context_add_group (ctx, gst_init_get_option_group ());
81 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
82 gst_printerr ("Error initializing: %s\n", err->message);
83 g_option_context_free (ctx);
87 g_option_context_free (ctx);
90 gst_print ("Usage: %s <output uri> <list of audio files>\n", argv[0]);
94 /* Initialize GStreamer (this will parse environment variables and commandline
96 gst_init (&argc, &argv);
98 /* Initialize the GStreamer Editing Services */
101 /* Setup of an audio timeline */
103 /* This is our main GESTimeline */
104 timeline = ges_timeline_new ();
106 tracka = GES_TRACK (ges_audio_track_new ());
108 /* We are only going to be doing one layer of clips */
109 layer = ges_layer_new ();
111 /* Add the tracks and the layer to the timeline */
112 if (!ges_timeline_add_layer (timeline, layer))
114 if (!ges_timeline_add_track (timeline, tracka))
117 /* Here we've finished initializing our timeline, we're
118 * ready to start using it... by solely working with the layer ! */
120 for (i = 2; i < argc; i++) {
121 gchar *uri = gst_filename_to_uri (argv[i], NULL);
122 GESUriClip *src = ges_uri_clip_new (uri);
127 g_object_set (src, "start", ges_layer_get_duration (layer),
128 "duration", GST_SECOND, NULL);
129 /* Since we're using a GESSimpleLayer, objects will be automatically
130 * appended to the end of the layer */
131 ges_layer_add_clip (layer, (GESClip *) src);
134 /* In order to view our timeline, let's grab a convenience pipeline to put
135 * our timeline in. */
136 pipeline = ges_pipeline_new ();
138 /* Add the timeline to that pipeline */
139 if (!ges_pipeline_set_timeline (pipeline, timeline))
143 /* RENDER SETTINGS ! */
144 /* We set our output URI and rendering setting on the pipeline */
145 if (gst_uri_is_valid (argv[1])) {
146 output_uri = g_strdup (argv[1]);
147 } else if (g_file_test (argv[1], G_FILE_TEST_EXISTS)) {
148 output_uri = gst_filename_to_uri (argv[1], NULL);
150 gst_printerr ("Unrecognised command line argument '%s'.\n"
151 "Please pass an URI or file as argument!\n", argv[1]);
154 profile = make_encoding_profile (audio, container);
155 if (!ges_pipeline_set_render_settings (pipeline, output_uri, profile))
158 /* We want the pipeline to render (without any preview) */
159 if (!ges_pipeline_set_mode (pipeline, GES_PIPELINE_MODE_SMART_RENDER))
163 /* The following is standard usage of a GStreamer pipeline (note how you haven't
164 * had to care about GStreamer so far ?).
166 * We set the pipeline to playing ... */
167 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
169 /* ... and we start a GMainLoop. GES **REQUIRES** a GMainLoop to be running in
170 * order to function properly ! */
171 mainloop = g_main_loop_new (NULL, FALSE);
173 /* Simple code to have the mainloop shutdown after 4s */
174 /* FIXME : We should wait for EOS ! */
175 g_timeout_add_seconds (argc - 1, (GSourceFunc) g_main_loop_quit, mainloop);
176 g_main_loop_run (mainloop);