2010-05-20 08:46:38 +00:00
|
|
|
/* GStreamer Editing Services
|
|
|
|
* Copyright (C) 2010 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-05-20 08:46:38 +00:00
|
|
|
*/
|
|
|
|
|
2012-09-10 00:26:49 +00:00
|
|
|
#include <gio/gio.h>
|
2010-05-20 08:46:38 +00:00
|
|
|
#include <ges/ges.h>
|
2010-09-23 16:33:27 +00:00
|
|
|
#include <gst/pbutils/gstdiscoverer.h>
|
2010-12-15 11:36:25 +00:00
|
|
|
#include <gst/pbutils/encoding-profile.h>
|
2010-05-20 08:46:38 +00:00
|
|
|
|
2012-09-10 00:26:49 +00:00
|
|
|
static void
|
|
|
|
bus_message_cb (GstBus * bus, GstMessage * message, GMainLoop * mainloop);
|
|
|
|
|
|
|
|
static GstEncodingProfile *make_profile_from_info (GstDiscovererInfo * info);
|
|
|
|
|
|
|
|
GESTimelinePipeline *pipeline = NULL;
|
|
|
|
gchar *output_uri = NULL;
|
|
|
|
guint assetsCount = 0;
|
|
|
|
guint assetsLoaded = 0;
|
2010-06-09 14:27:43 +00:00
|
|
|
|
2012-09-10 00:26:49 +00:00
|
|
|
static void
|
|
|
|
asset_loaded_cb (GObject * source_object, GAsyncResult * res,
|
|
|
|
GMainLoop * mainloop)
|
2010-05-20 08:46:38 +00:00
|
|
|
{
|
2012-09-10 00:26:49 +00:00
|
|
|
GError *error = NULL;
|
2010-05-20 08:46:38 +00:00
|
|
|
|
2013-01-20 15:44:57 +00:00
|
|
|
GESUriClipAsset *mfs =
|
|
|
|
GES_URI_CLIP_ASSET (ges_asset_request_finish (res, &error));
|
2010-05-20 08:46:38 +00:00
|
|
|
|
2012-09-10 00:26:49 +00:00
|
|
|
if (error) {
|
|
|
|
GST_WARNING ("error creating asseti %s", error->message);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assetsLoaded++;
|
|
|
|
/*
|
|
|
|
* Check if we have loaded last asset and trigger concatenating
|
|
|
|
*/
|
|
|
|
if (assetsLoaded == assetsCount) {
|
2013-01-20 15:44:57 +00:00
|
|
|
GstDiscovererInfo *info = ges_uri_clip_asset_get_info (mfs);
|
2012-09-10 00:26:49 +00:00
|
|
|
GstEncodingProfile *profile = make_profile_from_info (info);
|
|
|
|
ges_timeline_pipeline_set_render_settings (pipeline, output_uri, profile);
|
|
|
|
/* We want the pipeline to render (without any preview) */
|
|
|
|
if (!ges_timeline_pipeline_set_mode (pipeline, TIMELINE_MODE_SMART_RENDER)) {
|
|
|
|
g_main_loop_quit (mainloop);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (mfs);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
GMainLoop *mainloop = NULL;
|
|
|
|
GESTimeline *timeline;
|
|
|
|
GESTimelineLayer *layer = NULL;
|
|
|
|
GstBus *bus = NULL;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
|
|
if (argc < 3) {
|
|
|
|
g_print ("Usage: %s <output uri> <list of files>\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;
|
|
|
|
|
|
|
|
output_uri = argv[1];
|
|
|
|
assetsCount = argc - 2;
|
|
|
|
|
|
|
|
for (i = 2; i < argc; i++) {
|
2013-01-20 15:44:57 +00:00
|
|
|
ges_asset_request_async (GES_TYPE_URI_CLIP, argv[i],
|
2012-09-10 00:26:49 +00:00
|
|
|
NULL, (GAsyncReadyCallback) asset_loaded_cb, mainloop);
|
2010-05-20 08:46:38 +00:00
|
|
|
}
|
|
|
|
|
2012-09-10 00:26:49 +00:00
|
|
|
/* 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;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
g_main_loop_run (mainloop);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
2010-05-20 08:46:38 +00:00
|
|
|
|
2012-09-10 00:26:49 +00:00
|
|
|
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;
|
|
|
|
}
|
2010-05-20 08:46:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstEncodingProfile *
|
2010-09-23 16:33:27 +00:00
|
|
|
make_profile_from_info (GstDiscovererInfo * info)
|
2010-05-20 08:46:38 +00:00
|
|
|
{
|
2010-12-15 11:36:25 +00:00
|
|
|
GstEncodingContainerProfile *profile = NULL;
|
2010-09-23 16:33:27 +00:00
|
|
|
GstDiscovererStreamInfo *sinfo = gst_discoverer_info_get_stream_info (info);
|
2010-05-20 08:46:38 +00:00
|
|
|
|
|
|
|
/* Get the container format */
|
2010-09-23 16:33:27 +00:00
|
|
|
if (GST_IS_DISCOVERER_CONTAINER_INFO (sinfo)) {
|
|
|
|
GList *tmp, *substreams;
|
2010-05-20 08:46:38 +00:00
|
|
|
|
2010-12-15 11:36:25 +00:00
|
|
|
profile = gst_encoding_container_profile_new ((gchar *) "concatenate", NULL,
|
|
|
|
gst_discoverer_stream_info_get_caps (sinfo), NULL);
|
2010-09-23 16:33:27 +00:00
|
|
|
|
2010-11-09 15:27:06 +00:00
|
|
|
substreams =
|
|
|
|
gst_discoverer_container_info_get_streams ((GstDiscovererContainerInfo
|
|
|
|
*) sinfo);
|
2010-09-23 16:33:27 +00:00
|
|
|
|
2010-05-20 08:46:38 +00:00
|
|
|
/* For each on the formats add stream profiles */
|
2010-09-23 16:33:27 +00:00
|
|
|
for (tmp = substreams; tmp; tmp = tmp->next) {
|
|
|
|
GstDiscovererStreamInfo *stream = GST_DISCOVERER_STREAM_INFO (tmp->data);
|
2011-01-27 16:46:19 +00:00
|
|
|
GstEncodingProfile *sprof = NULL;
|
2010-12-15 11:36:25 +00:00
|
|
|
|
|
|
|
if (GST_IS_DISCOVERER_VIDEO_INFO (stream)) {
|
|
|
|
sprof = (GstEncodingProfile *)
|
|
|
|
gst_encoding_video_profile_new (gst_discoverer_stream_info_get_caps
|
|
|
|
(stream), NULL, NULL, 1);
|
|
|
|
} else if (GST_IS_DISCOVERER_AUDIO_INFO (stream)) {
|
|
|
|
sprof = (GstEncodingProfile *)
|
|
|
|
gst_encoding_audio_profile_new (gst_discoverer_stream_info_get_caps
|
|
|
|
(stream), NULL, NULL, 1);
|
2011-01-27 16:46:19 +00:00
|
|
|
} else {
|
2010-12-15 11:36:25 +00:00
|
|
|
GST_WARNING ("Unsupported streams");
|
2011-01-27 16:46:19 +00:00
|
|
|
}
|
2010-12-15 11:36:25 +00:00
|
|
|
|
2011-01-27 16:46:19 +00:00
|
|
|
if (sprof)
|
|
|
|
gst_encoding_container_profile_add_profile (profile, sprof);
|
2010-05-20 08:46:38 +00:00
|
|
|
}
|
2010-09-23 16:33:27 +00:00
|
|
|
if (substreams)
|
|
|
|
gst_discoverer_stream_info_list_free (substreams);
|
2010-05-20 08:46:38 +00:00
|
|
|
} else {
|
|
|
|
GST_ERROR ("No container format !!!");
|
|
|
|
}
|
|
|
|
|
2010-09-23 16:33:27 +00:00
|
|
|
if (sinfo)
|
|
|
|
gst_discoverer_stream_info_unref (sinfo);
|
|
|
|
|
2012-09-10 00:26:49 +00:00
|
|
|
return GST_ENCODING_PROFILE (profile);
|
2010-05-20 08:46:38 +00:00
|
|
|
}
|