2010-01-08 17:16:16 +00:00
|
|
|
/* GStreamer Editing Services
|
|
|
|
* Copyright (C) 2009 Edward Hervey <bilboed@bilboed.com>
|
|
|
|
*
|
|
|
|
* 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
|
2012-11-04 00:25:20 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2010-01-08 17:16:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ges/ges.h>
|
2010-12-15 11:36:25 +00:00
|
|
|
#include <gst/pbutils/encoding-profile.h>
|
2010-01-08 17:16:16 +00:00
|
|
|
|
2011-07-01 17:30:01 +00:00
|
|
|
GstEncodingProfile *make_encoding_profile (gchar * audio, gchar * container);
|
2010-06-09 15:08:31 +00:00
|
|
|
|
2010-01-08 17:16:16 +00:00
|
|
|
/* This example will take a series of files and create a audio-only timeline
|
|
|
|
* containing the first second of each file and render it to the output uri
|
|
|
|
* using ogg/vorbis */
|
|
|
|
|
2011-07-01 17:30:01 +00:00
|
|
|
/* make_encoding_profile
|
|
|
|
* simple method creating an encoding profile. This is here in
|
2010-01-08 17:16:16 +00:00
|
|
|
* order not to clutter the main function. */
|
|
|
|
GstEncodingProfile *
|
2011-07-01 17:30:01 +00:00
|
|
|
make_encoding_profile (gchar * audio, gchar * container)
|
2010-01-08 17:16:16 +00:00
|
|
|
{
|
2010-12-15 11:36:25 +00:00
|
|
|
GstEncodingContainerProfile *profile;
|
2011-07-01 17:30:01 +00:00
|
|
|
GstEncodingProfile *stream;
|
2011-06-27 19:22:48 +00:00
|
|
|
GstCaps *caps;
|
2010-01-08 17:16:16 +00:00
|
|
|
|
2011-07-01 17:30:01 +00:00
|
|
|
caps = gst_caps_from_string (container);
|
|
|
|
profile =
|
|
|
|
gst_encoding_container_profile_new ((gchar *) "ges-test4", NULL, caps,
|
|
|
|
NULL);
|
2011-06-27 19:22:48 +00:00
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
2011-07-01 17:30:01 +00:00
|
|
|
caps = gst_caps_from_string (audio);
|
|
|
|
stream = (GstEncodingProfile *)
|
|
|
|
gst_encoding_audio_profile_new (caps, NULL, NULL, 0);
|
|
|
|
gst_encoding_container_profile_add_profile (profile, stream);
|
2011-06-27 19:22:48 +00:00
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
2010-12-15 11:36:25 +00:00
|
|
|
return (GstEncodingProfile *) profile;
|
2010-01-08 17:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, gchar ** argv)
|
|
|
|
{
|
2013-07-01 14:27:54 +00:00
|
|
|
GESPipeline *pipeline;
|
2010-01-08 17:16:16 +00:00
|
|
|
GESTimeline *timeline;
|
|
|
|
GESTrack *tracka;
|
2013-04-23 23:04:04 +00:00
|
|
|
GESLayer *layer;
|
2010-01-08 17:16:16 +00:00
|
|
|
GMainLoop *mainloop;
|
|
|
|
GstEncodingProfile *profile;
|
2011-07-01 17:30:01 +00:00
|
|
|
gchar *container = (gchar *) "application/ogg";
|
|
|
|
gchar *audio = (gchar *) "audio/x-vorbis";
|
2010-01-08 17:16:16 +00:00
|
|
|
gchar *output_uri;
|
|
|
|
guint i;
|
2011-07-01 17:30:01 +00:00
|
|
|
GError *err = NULL;
|
|
|
|
GOptionEntry options[] = {
|
|
|
|
{"format", 'f', 0, G_OPTION_ARG_STRING, &container,
|
|
|
|
"Container format", "<GstCaps>"},
|
|
|
|
{"aformat", 'a', 0, G_OPTION_ARG_STRING, &audio,
|
|
|
|
"Audio format", "<GstCaps>"},
|
|
|
|
{NULL}
|
|
|
|
};
|
|
|
|
GOptionContext *ctx;
|
|
|
|
|
|
|
|
ctx = g_option_context_new ("- renders a sequence of audio files.");
|
|
|
|
g_option_context_add_main_entries (ctx, options, NULL);
|
|
|
|
g_option_context_add_group (ctx, gst_init_get_option_group ());
|
|
|
|
|
|
|
|
if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
|
|
|
|
g_printerr ("Error initializing: %s\n", err->message);
|
|
|
|
g_option_context_free (ctx);
|
|
|
|
return -1;
|
|
|
|
}
|
2010-01-08 17:16:16 +00:00
|
|
|
|
|
|
|
if (argc < 3) {
|
|
|
|
g_print ("Usage: %s <output uri> <list of audio files>\n", argv[0]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize GStreamer (this will parse environment variables and commandline
|
|
|
|
* arguments. */
|
|
|
|
gst_init (&argc, &argv);
|
|
|
|
|
|
|
|
/* Initialize the GStreamer Editing Services */
|
|
|
|
ges_init ();
|
|
|
|
|
|
|
|
/* Setup of an audio timeline */
|
|
|
|
|
|
|
|
/* This is our main GESTimeline */
|
|
|
|
timeline = ges_timeline_new ();
|
|
|
|
|
2013-03-28 17:51:45 +00:00
|
|
|
tracka = GES_TRACK (ges_audio_track_new ());
|
2010-01-08 17:16:16 +00:00
|
|
|
|
2013-02-08 20:11:22 +00:00
|
|
|
/* We are only going to be doing one layer of clips */
|
2013-11-22 20:49:49 +00:00
|
|
|
layer = ges_layer_new ();
|
2010-01-08 17:16:16 +00:00
|
|
|
|
|
|
|
/* Add the tracks and the layer to the timeline */
|
|
|
|
if (!ges_timeline_add_layer (timeline, layer))
|
|
|
|
return -1;
|
|
|
|
if (!ges_timeline_add_track (timeline, tracka))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Here we've finished initializing our timeline, we're
|
2011-06-27 19:22:48 +00:00
|
|
|
* ready to start using it... by solely working with the layer ! */
|
2010-01-08 17:16:16 +00:00
|
|
|
|
|
|
|
for (i = 2; i < argc; i++) {
|
2012-05-01 18:05:51 +00:00
|
|
|
gchar *uri = gst_filename_to_uri (argv[i], NULL);
|
2013-01-20 15:44:57 +00:00
|
|
|
GESUriClip *src = ges_uri_clip_new (uri);
|
2010-01-08 17:16:16 +00:00
|
|
|
|
|
|
|
g_assert (src);
|
|
|
|
g_free (uri);
|
|
|
|
|
2013-11-22 20:49:49 +00:00
|
|
|
g_object_set (src, "start", ges_layer_get_duration (layer),
|
|
|
|
"duration", GST_SECOND, NULL);
|
2013-04-23 23:04:04 +00:00
|
|
|
/* Since we're using a GESSimpleLayer, objects will be automatically
|
2010-01-08 17:16:16 +00:00
|
|
|
* appended to the end of the layer */
|
2013-04-23 23:04:04 +00:00
|
|
|
ges_layer_add_clip (layer, (GESClip *) src);
|
2010-01-08 17:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* In order to view our timeline, let's grab a convenience pipeline to put
|
|
|
|
* our timeline in. */
|
2013-07-01 14:27:54 +00:00
|
|
|
pipeline = ges_pipeline_new ();
|
2010-01-08 17:16:16 +00:00
|
|
|
|
|
|
|
/* Add the timeline to that pipeline */
|
2014-02-04 09:45:58 +00:00
|
|
|
if (!ges_pipeline_set_timeline (pipeline, timeline))
|
2010-01-08 17:16:16 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
|
|
/* RENDER SETTINGS ! */
|
|
|
|
/* We set our output URI and rendering setting on the pipeline */
|
2011-06-27 19:22:48 +00:00
|
|
|
if (gst_uri_is_valid (argv[1])) {
|
|
|
|
output_uri = g_strdup (argv[1]);
|
2015-03-03 14:26:40 +00:00
|
|
|
} else if (g_file_test (argv[1], G_FILE_TEST_EXISTS)) {
|
2012-05-01 18:05:51 +00:00
|
|
|
output_uri = gst_filename_to_uri (argv[1], NULL);
|
2015-03-03 14:26:40 +00:00
|
|
|
} else {
|
|
|
|
g_printerr ("Unrecognised command line argument '%s'.\n"
|
|
|
|
"Please pass an URI or file as argument!\n", argv[1]);
|
|
|
|
return -1;
|
2011-06-27 19:22:48 +00:00
|
|
|
}
|
2011-07-01 17:30:01 +00:00
|
|
|
profile = make_encoding_profile (audio, container);
|
2013-07-01 14:27:54 +00:00
|
|
|
if (!ges_pipeline_set_render_settings (pipeline, output_uri, profile))
|
2010-01-08 17:16:16 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* We want the pipeline to render (without any preview) */
|
2014-02-17 11:34:04 +00:00
|
|
|
if (!ges_pipeline_set_mode (pipeline, GES_PIPELINE_MODE_SMART_RENDER))
|
2010-01-08 17:16:16 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
|
|
/* The following is standard usage of a GStreamer pipeline (note how you haven't
|
|
|
|
* had to care about GStreamer so far ?).
|
|
|
|
*
|
|
|
|
* We set the pipeline to playing ... */
|
|
|
|
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
|
|
|
|
|
2011-06-27 19:22:48 +00:00
|
|
|
/* ... and we start a GMainLoop. GES **REQUIRES** a GMainLoop to be running in
|
2010-01-08 17:16:16 +00:00
|
|
|
* order to function properly ! */
|
|
|
|
mainloop = g_main_loop_new (NULL, FALSE);
|
|
|
|
|
|
|
|
/* Simple code to have the mainloop shutdown after 4s */
|
|
|
|
/* FIXME : We should wait for EOS ! */
|
2011-06-27 19:22:48 +00:00
|
|
|
g_timeout_add_seconds (argc - 1, (GSourceFunc) g_main_loop_quit, mainloop);
|
2010-01-08 17:16:16 +00:00
|
|
|
g_main_loop_run (mainloop);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|