2010-04-20 11:08:27 +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-04-20 11:08:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2010-07-07 04:21:38 +00:00
|
|
|
#include <stdio.h>
|
2010-04-20 11:08:27 +00:00
|
|
|
#include <stdlib.h>
|
2010-05-24 08:59:43 +00:00
|
|
|
#include <string.h>
|
2010-04-20 11:08:27 +00:00
|
|
|
#include <glib.h>
|
2011-12-30 16:18:18 +00:00
|
|
|
#include <glib/gprintf.h>
|
2010-04-20 11:08:27 +00:00
|
|
|
#include <ges/ges.h>
|
2010-12-15 11:36:25 +00:00
|
|
|
#include <gst/pbutils/encoding-profile.h>
|
2010-04-20 11:08:27 +00:00
|
|
|
|
2010-06-02 09:49:08 +00:00
|
|
|
/* GLOBAL VARIABLE */
|
|
|
|
static guint repeat = 0;
|
2011-01-12 16:52:10 +00:00
|
|
|
static GESTimelinePipeline *pipeline = NULL;
|
2010-09-16 07:07:05 +00:00
|
|
|
static gboolean seenerrors = FALSE;
|
2010-06-02 09:49:08 +00:00
|
|
|
|
2011-08-28 01:57:13 +00:00
|
|
|
void load_project (gchar * uri);
|
|
|
|
|
2010-09-24 18:31:53 +00:00
|
|
|
static gchar *
|
|
|
|
ensure_uri (gchar * location)
|
|
|
|
{
|
|
|
|
if (gst_uri_is_valid (location))
|
|
|
|
return g_strdup (location);
|
2012-05-02 07:44:25 +00:00
|
|
|
else
|
|
|
|
return gst_filename_to_uri (location, NULL);
|
2010-09-24 18:31:53 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 16:52:10 +00:00
|
|
|
static gboolean
|
2010-07-15 17:50:22 +00:00
|
|
|
thumbnail_cb (gpointer pipeline)
|
|
|
|
{
|
|
|
|
static int i = 0;
|
|
|
|
GESTimelinePipeline *p = (GESTimelinePipeline *) pipeline;
|
|
|
|
gchar *filename;
|
2010-08-31 11:29:37 +00:00
|
|
|
gboolean res;
|
2010-07-15 17:50:22 +00:00
|
|
|
|
|
|
|
filename = g_strdup_printf ("thumbnail%d.jpg", i++);
|
|
|
|
|
2010-08-31 11:29:37 +00:00
|
|
|
res = ges_timeline_pipeline_save_thumbnail (p, -1, -1,
|
2010-07-15 17:50:22 +00:00
|
|
|
(gchar *) "image/jpeg", filename);
|
2010-08-31 11:29:37 +00:00
|
|
|
|
|
|
|
g_free (filename);
|
|
|
|
|
|
|
|
return res;
|
2010-07-15 17:50:22 +00:00
|
|
|
}
|
2010-05-24 08:59:43 +00:00
|
|
|
|
2011-01-12 16:52:10 +00:00
|
|
|
static gboolean
|
2010-06-03 17:14:41 +00:00
|
|
|
check_time (char *time)
|
|
|
|
{
|
2012-04-17 15:18:44 +00:00
|
|
|
static GRegex *re = NULL;
|
2010-06-03 17:14:41 +00:00
|
|
|
|
2012-04-17 15:18:44 +00:00
|
|
|
if (!re) {
|
|
|
|
if (NULL == (re = g_regex_new ("^[0-9]+(.[0-9]+)?$", G_REGEX_EXTENDED, 0,
|
2012-05-02 07:44:25 +00:00
|
|
|
NULL)))
|
2011-03-15 13:02:14 +00:00
|
|
|
return FALSE;
|
2010-06-03 17:14:41 +00:00
|
|
|
}
|
|
|
|
|
2012-04-17 15:18:44 +00:00
|
|
|
if (g_regex_match (re, time, 0, NULL))
|
2010-06-03 17:14:41 +00:00
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-01-12 16:52:10 +00:00
|
|
|
static guint64
|
2010-06-03 17:14:41 +00:00
|
|
|
str_to_time (char *time)
|
|
|
|
{
|
|
|
|
if (check_time (time)) {
|
|
|
|
return (guint64) (atof (time) * GST_SECOND);
|
|
|
|
}
|
2011-01-17 15:46:15 +00:00
|
|
|
GST_ERROR ("%s not a valid time", time);
|
2010-06-03 17:14:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-20 11:08:27 +00:00
|
|
|
static GstEncodingProfile *
|
2010-05-19 10:38:21 +00:00
|
|
|
make_encoding_profile (gchar * audio, gchar * video, gchar * video_restriction,
|
2011-08-01 11:40:48 +00:00
|
|
|
gchar * audio_preset, gchar * video_preset, gchar * container)
|
2010-04-20 11:08:27 +00:00
|
|
|
{
|
2010-12-15 11:36:25 +00:00
|
|
|
GstEncodingContainerProfile *profile;
|
|
|
|
GstEncodingProfile *stream;
|
2010-06-21 09:47:44 +00:00
|
|
|
GstCaps *caps;
|
2010-04-20 11:08:27 +00:00
|
|
|
|
2010-06-21 09:47:44 +00:00
|
|
|
caps = gst_caps_from_string (container);
|
2010-12-15 11:36:25 +00:00
|
|
|
profile =
|
|
|
|
gst_encoding_container_profile_new ((gchar *) "ges-test4", NULL, caps,
|
|
|
|
NULL);
|
2010-06-21 09:47:44 +00:00
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
2011-11-30 15:15:35 +00:00
|
|
|
if (audio) {
|
|
|
|
caps = gst_caps_from_string (audio);
|
|
|
|
stream = (GstEncodingProfile *)
|
|
|
|
gst_encoding_audio_profile_new (caps, audio_preset, NULL, 0);
|
|
|
|
gst_encoding_container_profile_add_profile (profile, stream);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
2010-06-21 09:47:44 +00:00
|
|
|
|
2011-11-30 15:15:35 +00:00
|
|
|
if (video) {
|
|
|
|
caps = gst_caps_from_string (video);
|
|
|
|
stream = (GstEncodingProfile *)
|
|
|
|
gst_encoding_video_profile_new (caps, video_preset, NULL, 0);
|
|
|
|
if (video_restriction)
|
|
|
|
gst_encoding_profile_set_restriction (stream,
|
|
|
|
gst_caps_from_string (video_restriction));
|
|
|
|
gst_encoding_container_profile_add_profile (profile, stream);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
2010-06-21 09:47:44 +00:00
|
|
|
|
2010-12-15 11:36:25 +00:00
|
|
|
return (GstEncodingProfile *) profile;
|
2010-04-20 11:08:27 +00:00
|
|
|
}
|
|
|
|
|
2010-09-24 18:31:53 +00:00
|
|
|
static GESTimeline *
|
2011-11-30 15:15:35 +00:00
|
|
|
create_timeline (int nbargs, gchar ** argv, gchar * audio, gchar * video)
|
2010-04-20 11:08:27 +00:00
|
|
|
{
|
|
|
|
GESTimelineLayer *layer;
|
2011-11-30 15:15:35 +00:00
|
|
|
GESTrack *tracka = NULL, *trackv = NULL;
|
2010-04-20 11:08:27 +00:00
|
|
|
GESTimeline *timeline;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
timeline = ges_timeline_new ();
|
|
|
|
|
2011-11-30 15:15:35 +00:00
|
|
|
if (audio)
|
|
|
|
tracka = ges_track_audio_raw_new ();
|
|
|
|
if (video)
|
|
|
|
trackv = ges_track_video_raw_new ();
|
2010-04-20 11:08:27 +00:00
|
|
|
|
2013-02-08 20:11:22 +00:00
|
|
|
/* We are only going to be doing one layer of clips */
|
2010-04-20 11:08:27 +00:00
|
|
|
layer = (GESTimelineLayer *) ges_simple_timeline_layer_new ();
|
|
|
|
|
|
|
|
/* Add the tracks and the layer to the timeline */
|
|
|
|
if (!ges_timeline_add_layer (timeline, layer) ||
|
2011-11-30 15:15:35 +00:00
|
|
|
!(!audio || ges_timeline_add_track (timeline, tracka)) ||
|
|
|
|
!(!video || ges_timeline_add_track (timeline, trackv)))
|
2011-01-17 15:46:15 +00:00
|
|
|
goto build_failure;
|
2010-04-20 11:08:27 +00:00
|
|
|
|
|
|
|
/* Here we've finished initializing our timeline, we're
|
|
|
|
* ready to start using it... by solely working with the layer !*/
|
|
|
|
|
|
|
|
for (i = 0; i < nbargs / 3; i++) {
|
2013-02-15 02:34:48 +00:00
|
|
|
GESClip *clip;
|
2010-05-19 10:38:21 +00:00
|
|
|
|
2010-05-26 16:19:41 +00:00
|
|
|
char *source = argv[i * 3];
|
|
|
|
char *arg0 = argv[(i * 3) + 1];
|
2010-06-04 10:17:56 +00:00
|
|
|
guint64 duration = str_to_time (argv[(i * 3) + 2]);
|
2010-05-26 16:19:41 +00:00
|
|
|
|
|
|
|
if (!g_strcmp0 ("+pattern", source)) {
|
2013-02-15 02:34:48 +00:00
|
|
|
clip = GES_CLIP (ges_test_clip_new_for_nick (arg0));
|
|
|
|
if (!clip) {
|
2011-01-17 15:46:15 +00:00
|
|
|
g_error ("%s is an invalid pattern name!\n", arg0);
|
|
|
|
goto build_failure;
|
|
|
|
}
|
2010-05-26 16:19:41 +00:00
|
|
|
|
2013-02-15 02:34:48 +00:00
|
|
|
g_object_set (G_OBJECT (clip), "duration", duration, NULL);
|
2010-05-26 16:19:41 +00:00
|
|
|
|
2011-01-17 15:46:15 +00:00
|
|
|
g_printf ("Adding <pattern:%s> duration %" GST_TIME_FORMAT "\n", arg0,
|
|
|
|
GST_TIME_ARGS (duration));
|
2010-05-26 16:19:41 +00:00
|
|
|
}
|
|
|
|
|
2010-05-27 10:06:00 +00:00
|
|
|
else if (!g_strcmp0 ("+transition", source)) {
|
2011-01-17 15:46:15 +00:00
|
|
|
if (duration <= 0) {
|
|
|
|
g_error ("durations must be greater than 0");
|
|
|
|
goto build_failure;
|
|
|
|
}
|
|
|
|
|
2013-02-15 02:34:48 +00:00
|
|
|
clip = GES_CLIP (ges_transition_clip_new_for_nick (arg0));
|
2010-05-27 10:06:00 +00:00
|
|
|
|
2013-02-15 02:34:48 +00:00
|
|
|
if (!clip) {
|
2010-05-27 10:06:00 +00:00
|
|
|
g_error ("invalid transition type\n");
|
2011-01-17 15:46:15 +00:00
|
|
|
goto build_failure;
|
|
|
|
}
|
2010-06-04 10:17:56 +00:00
|
|
|
|
2013-02-15 02:34:48 +00:00
|
|
|
g_object_set (G_OBJECT (clip), "duration", duration, NULL);
|
2010-05-27 10:06:00 +00:00
|
|
|
|
2011-01-17 15:46:15 +00:00
|
|
|
g_printf ("Adding <transition:%s> duration %" GST_TIME_FORMAT "\n", arg0,
|
|
|
|
GST_TIME_ARGS (duration));
|
2010-05-27 10:06:00 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-06-16 11:22:15 +00:00
|
|
|
else if (!g_strcmp0 ("+title", source)) {
|
2013-02-15 02:34:48 +00:00
|
|
|
clip = GES_CLIP (ges_title_clip_new ());
|
2010-06-16 11:22:15 +00:00
|
|
|
|
2013-02-15 02:34:48 +00:00
|
|
|
g_object_set (clip, "duration", duration, "text", arg0, NULL);
|
2010-06-16 11:22:15 +00:00
|
|
|
|
2011-01-17 15:46:15 +00:00
|
|
|
g_printf ("Adding <title:%s> duration %" GST_TIME_FORMAT "\n", arg0,
|
|
|
|
GST_TIME_ARGS (duration));
|
2010-06-16 11:22:15 +00:00
|
|
|
}
|
|
|
|
|
2010-05-26 16:19:41 +00:00
|
|
|
else {
|
2010-06-09 15:11:56 +00:00
|
|
|
gchar *uri;
|
|
|
|
guint64 inpoint;
|
|
|
|
|
2010-09-24 18:31:53 +00:00
|
|
|
if (!(uri = ensure_uri (source))) {
|
2011-01-31 19:01:24 +00:00
|
|
|
GST_ERROR ("couldn't create uri for '%s'", source);
|
2011-01-17 15:46:15 +00:00
|
|
|
goto build_failure;
|
2010-09-24 18:31:53 +00:00
|
|
|
}
|
2010-06-09 15:11:56 +00:00
|
|
|
|
2011-01-17 15:46:15 +00:00
|
|
|
inpoint = str_to_time (argv[i * 3 + 1]);
|
2013-02-15 02:34:48 +00:00
|
|
|
clip = GES_CLIP (ges_uri_clip_new (uri));
|
|
|
|
g_object_set (clip,
|
2010-05-26 16:19:41 +00:00
|
|
|
"in-point", (guint64) inpoint, "duration", (guint64) duration, NULL);
|
|
|
|
|
2011-01-17 15:46:15 +00:00
|
|
|
g_printf ("Adding clip %s inpoint:%" GST_TIME_FORMAT " duration:%"
|
2010-05-26 16:19:41 +00:00
|
|
|
GST_TIME_FORMAT "\n", uri, GST_TIME_ARGS (inpoint),
|
|
|
|
GST_TIME_ARGS (duration));
|
|
|
|
|
2010-05-24 08:59:43 +00:00
|
|
|
g_free (uri);
|
|
|
|
}
|
2010-05-26 16:19:41 +00:00
|
|
|
|
2010-04-20 11:08:27 +00:00
|
|
|
/* Since we're using a GESSimpleTimelineLayer, objects will be automatically
|
|
|
|
* appended to the end of the layer */
|
2013-02-15 02:34:48 +00:00
|
|
|
ges_timeline_layer_add_clip (layer, clip);
|
2010-04-20 11:08:27 +00:00
|
|
|
}
|
|
|
|
|
2010-09-24 18:31:53 +00:00
|
|
|
return timeline;
|
2011-01-17 15:46:15 +00:00
|
|
|
|
|
|
|
build_failure:
|
|
|
|
{
|
2013-03-16 22:05:04 +00:00
|
|
|
gst_object_unref (timeline);
|
2011-01-17 15:46:15 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-09-24 18:31:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GESTimelinePipeline *
|
2011-11-30 15:15:35 +00:00
|
|
|
create_pipeline (gchar * load_path, gchar * save_path, int argc, char **argv,
|
|
|
|
gchar * audio, gchar * video)
|
2010-09-24 18:31:53 +00:00
|
|
|
{
|
2011-01-17 15:46:15 +00:00
|
|
|
GESTimelinePipeline *pipeline = NULL;
|
|
|
|
GESTimeline *timeline = NULL;
|
2010-09-24 18:31:53 +00:00
|
|
|
|
2011-01-17 15:46:15 +00:00
|
|
|
/* Timeline creation */
|
2010-09-24 18:31:53 +00:00
|
|
|
if (load_path) {
|
|
|
|
gchar *uri;
|
2011-01-17 15:46:15 +00:00
|
|
|
|
|
|
|
g_printf ("Loading project from : %s\n", load_path);
|
2010-09-24 18:31:53 +00:00
|
|
|
|
|
|
|
if (!(uri = ensure_uri (load_path))) {
|
2011-01-17 15:46:15 +00:00
|
|
|
g_error ("couldn't create uri for '%s'", load_path);
|
|
|
|
goto failure;
|
2010-09-24 18:31:53 +00:00
|
|
|
}
|
|
|
|
g_printf ("reading from '%s' (arguments ignored)\n", load_path);
|
2012-09-23 00:05:42 +00:00
|
|
|
if (!(timeline = ges_timeline_new_from_uri (uri, NULL))) {
|
2011-01-17 15:46:15 +00:00
|
|
|
g_error ("failed to create timeline from file '%s'", load_path);
|
|
|
|
goto failure;
|
2010-09-24 18:31:53 +00:00
|
|
|
}
|
2011-01-17 15:46:15 +00:00
|
|
|
g_printf ("loaded project successfully\n");
|
2010-09-24 18:31:53 +00:00
|
|
|
g_free (uri);
|
2013-03-30 12:37:43 +00:00
|
|
|
} else {
|
2011-01-17 15:46:15 +00:00
|
|
|
/* Normal timeline creation */
|
2013-03-30 12:37:43 +00:00
|
|
|
if (!(timeline = create_timeline (argc, argv, audio, video)))
|
|
|
|
goto failure;
|
|
|
|
}
|
2010-09-24 18:31:53 +00:00
|
|
|
|
2011-01-17 15:46:15 +00:00
|
|
|
/* save project if path is given. we do this now in case GES crashes or
|
|
|
|
* hangs during playback. */
|
|
|
|
if (save_path) {
|
|
|
|
gchar *uri;
|
|
|
|
if (!(uri = ensure_uri (save_path))) {
|
|
|
|
g_error ("couldn't create uri for '%s", save_path);
|
|
|
|
goto failure;
|
2010-09-24 18:31:53 +00:00
|
|
|
}
|
2012-11-24 03:09:28 +00:00
|
|
|
ges_timeline_save_to_uri (timeline, uri, NULL, TRUE, NULL);
|
2011-01-17 15:46:15 +00:00
|
|
|
g_free (uri);
|
2010-09-24 18:31:53 +00:00
|
|
|
}
|
|
|
|
|
2010-04-20 11:08:27 +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))
|
2011-01-17 15:46:15 +00:00
|
|
|
goto failure;
|
2010-04-20 11:08:27 +00:00
|
|
|
|
|
|
|
return pipeline;
|
2011-01-17 15:46:15 +00:00
|
|
|
|
|
|
|
failure:
|
|
|
|
{
|
|
|
|
if (timeline)
|
2013-03-16 22:05:04 +00:00
|
|
|
gst_object_unref (timeline);
|
2011-01-17 15:46:15 +00:00
|
|
|
if (pipeline)
|
2013-03-16 22:05:04 +00:00
|
|
|
gst_object_unref (pipeline);
|
2011-01-17 15:46:15 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-04-20 11:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bus_message_cb (GstBus * bus, GstMessage * message, GMainLoop * mainloop)
|
|
|
|
{
|
|
|
|
switch (GST_MESSAGE_TYPE (message)) {
|
2011-05-05 18:02:28 +00:00
|
|
|
case GST_MESSAGE_ERROR:{
|
|
|
|
GError *err = NULL;
|
|
|
|
gchar *dbg_info = NULL;
|
|
|
|
|
|
|
|
gst_message_parse_error (message, &err, &dbg_info);
|
|
|
|
g_printerr ("ERROR from element %s: %s\n",
|
|
|
|
GST_OBJECT_NAME (message->src), err->message);
|
|
|
|
g_printerr ("Debugging info: %s\n", (dbg_info) ? dbg_info : "none");
|
|
|
|
g_error_free (err);
|
|
|
|
g_free (dbg_info);
|
2010-09-16 07:07:05 +00:00
|
|
|
seenerrors = TRUE;
|
2010-04-20 11:08:27 +00:00
|
|
|
g_main_loop_quit (mainloop);
|
|
|
|
break;
|
2011-05-05 18:02:28 +00:00
|
|
|
}
|
2010-04-20 11:08:27 +00:00
|
|
|
case GST_MESSAGE_EOS:
|
2010-06-02 09:49:08 +00:00
|
|
|
if (repeat > 0) {
|
2010-11-11 16:39:32 +00:00
|
|
|
g_printerr ("Looping again\n");
|
|
|
|
if (!gst_element_seek_simple (GST_ELEMENT (pipeline), GST_FORMAT_TIME,
|
|
|
|
GST_SEEK_FLAG_FLUSH, 0))
|
|
|
|
g_printerr ("seeking failed\n");
|
|
|
|
else
|
|
|
|
g_printerr ("seeking succeeded\n");
|
2010-06-02 09:49:08 +00:00
|
|
|
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
|
2010-11-11 16:39:32 +00:00
|
|
|
g_printerr ("Looping set\n");
|
2010-06-02 09:49:08 +00:00
|
|
|
repeat -= 1;
|
|
|
|
} else {
|
2010-11-11 16:39:32 +00:00
|
|
|
g_printerr ("Done\n");
|
2010-06-02 09:49:08 +00:00
|
|
|
g_main_loop_quit (mainloop);
|
|
|
|
}
|
2010-04-20 11:08:27 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-12 16:45:23 +00:00
|
|
|
static void
|
|
|
|
print_enum (GType enum_type)
|
2010-06-03 17:13:42 +00:00
|
|
|
{
|
2011-01-12 16:45:23 +00:00
|
|
|
GEnumClass *enum_class = G_ENUM_CLASS (g_type_class_ref (enum_type));
|
|
|
|
guint i;
|
2010-06-03 17:13:42 +00:00
|
|
|
|
2011-01-12 16:45:23 +00:00
|
|
|
GST_ERROR ("%d", enum_class->n_values);
|
2010-11-25 13:03:07 +00:00
|
|
|
|
2011-01-12 16:45:23 +00:00
|
|
|
for (i = 0; i < enum_class->n_values; i++) {
|
2011-01-17 15:46:15 +00:00
|
|
|
g_printf ("%s\n", enum_class->values[i].value_nick);
|
2010-06-03 17:13:42 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 16:45:23 +00:00
|
|
|
g_type_class_unref (enum_class);
|
2010-06-03 17:13:42 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 16:45:23 +00:00
|
|
|
static void
|
|
|
|
print_transition_list (void)
|
2010-06-03 17:13:42 +00:00
|
|
|
{
|
2011-01-12 16:45:23 +00:00
|
|
|
print_enum (GES_VIDEO_STANDARD_TRANSITION_TYPE_TYPE);
|
|
|
|
}
|
2010-06-11 13:28:43 +00:00
|
|
|
|
2011-01-12 16:45:23 +00:00
|
|
|
static void
|
|
|
|
print_pattern_list (void)
|
|
|
|
{
|
|
|
|
print_enum (GES_VIDEO_TEST_PATTERN_TYPE);
|
2010-06-03 17:13:42 +00:00
|
|
|
}
|
|
|
|
|
2011-08-28 01:57:13 +00:00
|
|
|
void
|
|
|
|
load_project (gchar * uri)
|
|
|
|
{
|
|
|
|
GESFormatter *formatter;
|
|
|
|
GESTimeline *timeline;
|
|
|
|
GMainLoop *mainloop;
|
|
|
|
GESTimelinePipeline *pipeline;
|
|
|
|
GstBus *bus;
|
|
|
|
|
|
|
|
formatter = GES_FORMATTER (ges_pitivi_formatter_new ());
|
|
|
|
timeline = ges_timeline_new ();
|
|
|
|
pipeline = ges_timeline_pipeline_new ();
|
|
|
|
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
|
|
|
|
mainloop = g_main_loop_new (NULL, FALSE);
|
|
|
|
|
|
|
|
ges_timeline_pipeline_add_timeline (pipeline, timeline);
|
2012-09-23 00:05:42 +00:00
|
|
|
ges_formatter_load_from_uri (formatter, timeline, uri, NULL);
|
2011-08-28 01:57:13 +00:00
|
|
|
ges_timeline_pipeline_set_mode (pipeline, TIMELINE_MODE_PREVIEW_VIDEO);
|
|
|
|
|
|
|
|
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
|
|
|
|
gst_bus_add_signal_watch (bus);
|
|
|
|
g_signal_connect (bus, "message", G_CALLBACK (bus_message_cb), mainloop);
|
|
|
|
g_main_loop_run (mainloop);
|
|
|
|
}
|
|
|
|
|
2010-04-20 11:08:27 +00:00
|
|
|
int
|
|
|
|
main (int argc, gchar ** argv)
|
|
|
|
{
|
|
|
|
GError *err = NULL;
|
|
|
|
gchar *outputuri = NULL;
|
2010-06-09 15:11:56 +00:00
|
|
|
gchar *container = (gchar *) "application/ogg";
|
|
|
|
gchar *audio = (gchar *) "audio/x-vorbis";
|
|
|
|
gchar *video = (gchar *) "video/x-theora";
|
|
|
|
gchar *video_restriction = (gchar *) "ANY";
|
2011-08-01 11:40:48 +00:00
|
|
|
gchar *audio_preset = NULL;
|
|
|
|
gchar *video_preset = NULL;
|
2011-11-30 14:44:45 +00:00
|
|
|
gchar *exclude_args = NULL;
|
2010-04-20 11:08:27 +00:00
|
|
|
static gboolean render = FALSE;
|
|
|
|
static gboolean smartrender = FALSE;
|
2010-06-03 17:13:42 +00:00
|
|
|
static gboolean list_transitions = FALSE;
|
|
|
|
static gboolean list_patterns = FALSE;
|
2010-07-15 17:50:22 +00:00
|
|
|
static gdouble thumbinterval = 0;
|
2011-11-30 14:44:45 +00:00
|
|
|
static gboolean verbose = FALSE;
|
2010-09-24 18:31:53 +00:00
|
|
|
gchar *save_path = NULL;
|
|
|
|
gchar *load_path = NULL;
|
2011-08-28 01:57:13 +00:00
|
|
|
gchar *project_path = NULL;
|
2010-04-20 11:08:27 +00:00
|
|
|
GOptionEntry options[] = {
|
2010-07-15 17:50:22 +00:00
|
|
|
{"thumbnail", 'm', 0.0, G_OPTION_ARG_DOUBLE, &thumbinterval,
|
|
|
|
"Take thumbnails every n seconds (saved in current directory)", "N"},
|
2010-04-20 11:08:27 +00:00
|
|
|
{"render", 'r', 0, G_OPTION_ARG_NONE, &render,
|
|
|
|
"Render to outputuri", NULL},
|
|
|
|
{"smartrender", 's', 0, G_OPTION_ARG_NONE, &smartrender,
|
|
|
|
"Render to outputuri, and avoid decoding/reencoding", NULL},
|
|
|
|
{"outputuri", 'o', 0, G_OPTION_ARG_STRING, &outputuri,
|
|
|
|
"URI to encode to", "URI (<protocol>://<location>)"},
|
|
|
|
{"format", 'f', 0, G_OPTION_ARG_STRING, &container,
|
|
|
|
"Container format", "<GstCaps>"},
|
|
|
|
{"vformat", 'v', 0, G_OPTION_ARG_STRING, &video,
|
|
|
|
"Video format", "<GstCaps>"},
|
|
|
|
{"aformat", 'a', 0, G_OPTION_ARG_STRING, &audio,
|
2010-05-19 10:38:21 +00:00
|
|
|
"Audio format", "<GstCaps>"},
|
2010-05-06 17:57:25 +00:00
|
|
|
{"vrestriction", 'x', 0, G_OPTION_ARG_STRING, &video_restriction,
|
2010-05-19 10:38:21 +00:00
|
|
|
"Video restriction", "<GstCaps>"},
|
2011-08-01 11:40:48 +00:00
|
|
|
{"apreset", 0, 0, G_OPTION_ARG_STRING, &audio_preset,
|
|
|
|
"Encoding audio profile preset", "<GstPresetName>"},
|
|
|
|
{"vpreset", 0, 0, G_OPTION_ARG_STRING, &video_preset,
|
|
|
|
"Encoding video profile preset", "<GstPresetName>"},
|
2010-06-03 17:13:42 +00:00
|
|
|
{"repeat", 'l', 0, G_OPTION_ARG_INT, &repeat,
|
2010-06-02 09:49:08 +00:00
|
|
|
"Number of time to repeat timeline", NULL},
|
2010-06-03 17:13:42 +00:00
|
|
|
{"list-transitions", 't', 0, G_OPTION_ARG_NONE, &list_transitions,
|
|
|
|
"List valid transition types and exit", NULL},
|
|
|
|
{"list-patterns", 'p', 0, G_OPTION_ARG_NONE, &list_patterns,
|
|
|
|
"List patterns and exit", NULL},
|
2010-09-24 18:31:53 +00:00
|
|
|
{"save", 'z', 0, G_OPTION_ARG_STRING, &save_path,
|
|
|
|
"Save project to file before rendering", "<path>"},
|
|
|
|
{"load", 'q', 0, G_OPTION_ARG_STRING, &load_path,
|
|
|
|
"Load project from file before rendering", "<path>"},
|
2011-11-30 14:44:45 +00:00
|
|
|
{"verbose", 0, 0, G_OPTION_ARG_NONE, &verbose,
|
|
|
|
"Output status information and property notifications", NULL},
|
|
|
|
{"exclude", 'X', 0, G_OPTION_ARG_NONE, &exclude_args,
|
|
|
|
"Do not output status information of TYPE", "TYPE1,TYPE2,..."},
|
2011-08-28 01:57:13 +00:00
|
|
|
{"load-xptv", 'y', 0, G_OPTION_ARG_STRING, &project_path,
|
|
|
|
"Load xptv project from file for previewing", "<path>"},
|
2010-04-20 11:08:27 +00:00
|
|
|
{NULL}
|
|
|
|
};
|
|
|
|
GOptionContext *ctx;
|
|
|
|
GMainLoop *mainloop;
|
|
|
|
GstBus *bus;
|
|
|
|
|
2011-01-26 21:50:00 +00:00
|
|
|
ctx = g_option_context_new ("- plays or renders a timeline.");
|
2010-04-20 11:08:27 +00:00
|
|
|
g_option_context_set_summary (ctx,
|
2011-08-01 11:42:17 +00:00
|
|
|
"ges-launch renders a timeline, which can be specified on the commandline,\n"
|
|
|
|
"or loaded from a file using the -q option.\n\n"
|
|
|
|
"A timeline is a list of files, patterns, and transitions to be rendered\n"
|
|
|
|
"one after the other. Files and Patterns provide video and audio as the\n"
|
|
|
|
"primary input, and transitions animate between the end of one file/pattern\n"
|
|
|
|
"and the beginning of a new one. Hence, transitions can only be listed\n"
|
|
|
|
"in between patterns or files.\n\n"
|
|
|
|
"A file is a triplet of filename, inpoint (in seconds) and\n"
|
|
|
|
"duration (in seconds). If the duration is 0, the full file length is used.\n\n"
|
|
|
|
"Patterns and transitions are triplets that begin with either \"+pattern\"\n"
|
|
|
|
"or \"+transition\", followed by a <type> and duration (in seconds, must be\n"
|
|
|
|
"greater than 0)\n\n"
|
|
|
|
"Durations in all cases can be fractions of a second.\n\n"
|
|
|
|
"Example:\n"
|
|
|
|
"ges-launch file1.avi 0 45 +transition crossfade 3.5 file2.avi 0 0");
|
2010-04-20 11:08:27 +00:00
|
|
|
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)) {
|
2010-11-11 16:39:32 +00:00
|
|
|
g_printerr ("Error initializing: %s\n", err->message);
|
2010-04-20 11:08:27 +00:00
|
|
|
g_option_context_free (ctx);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2011-01-12 16:45:23 +00:00
|
|
|
/* Initialize the GStreamer Editing Services */
|
2011-02-07 12:19:18 +00:00
|
|
|
if (!ges_init ()) {
|
|
|
|
g_printerr ("Error initializing GES\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
2011-01-12 16:45:23 +00:00
|
|
|
|
2010-06-03 17:13:42 +00:00
|
|
|
if (list_transitions) {
|
|
|
|
print_transition_list ();
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (list_patterns) {
|
|
|
|
print_pattern_list ();
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
2011-08-28 01:57:13 +00:00
|
|
|
if (project_path) {
|
|
|
|
load_project (project_path);
|
|
|
|
exit (0);
|
|
|
|
}
|
2010-09-24 18:31:53 +00:00
|
|
|
if (((!load_path && (argc < 4))) || (outputuri && (!render && !smartrender))) {
|
2011-01-17 15:46:15 +00:00
|
|
|
g_printf ("%s", g_option_context_get_help (ctx, TRUE, NULL));
|
2010-04-20 11:08:27 +00:00
|
|
|
g_option_context_free (ctx);
|
2010-09-16 07:07:05 +00:00
|
|
|
exit (1);
|
2010-04-20 11:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_option_context_free (ctx);
|
|
|
|
|
2011-11-30 15:15:35 +00:00
|
|
|
/* normalize */
|
|
|
|
if (strcmp (audio, "none") == 0)
|
|
|
|
audio = NULL;
|
|
|
|
if (strcmp (video, "none") == 0)
|
|
|
|
video = NULL;
|
|
|
|
|
2010-04-20 11:08:27 +00:00
|
|
|
/* Create the pipeline */
|
2011-11-30 15:15:35 +00:00
|
|
|
pipeline = create_pipeline (load_path, save_path, argc - 1, argv + 1,
|
|
|
|
audio, video);
|
2010-04-20 11:08:27 +00:00
|
|
|
if (!pipeline)
|
2010-09-16 07:07:05 +00:00
|
|
|
exit (1);
|
2010-04-20 11:08:27 +00:00
|
|
|
|
|
|
|
/* Setup profile/encoding if needed */
|
|
|
|
if (render || smartrender) {
|
2010-06-21 09:47:21 +00:00
|
|
|
GstEncodingProfile *prof;
|
|
|
|
|
2011-08-01 11:40:48 +00:00
|
|
|
prof = make_encoding_profile (audio, video, video_restriction, audio_preset,
|
|
|
|
video_preset, container);
|
2010-04-20 11:08:27 +00:00
|
|
|
|
|
|
|
if (!prof ||
|
|
|
|
!ges_timeline_pipeline_set_render_settings (pipeline, outputuri, prof)
|
|
|
|
|| !ges_timeline_pipeline_set_mode (pipeline,
|
|
|
|
smartrender ? TIMELINE_MODE_SMART_RENDER : TIMELINE_MODE_RENDER))
|
2010-09-16 07:07:05 +00:00
|
|
|
exit (1);
|
2010-06-21 09:47:21 +00:00
|
|
|
|
|
|
|
g_free (outputuri);
|
2010-12-15 11:36:25 +00:00
|
|
|
gst_encoding_profile_unref (prof);
|
2010-04-20 11:08:27 +00:00
|
|
|
} else {
|
|
|
|
ges_timeline_pipeline_set_mode (pipeline, TIMELINE_MODE_PREVIEW);
|
|
|
|
}
|
|
|
|
|
2011-11-30 14:44:45 +00:00
|
|
|
if (verbose) {
|
|
|
|
gchar **exclude_list =
|
|
|
|
exclude_args ? g_strsplit (exclude_args, ",", 0) : NULL;
|
|
|
|
g_signal_connect (pipeline, "deep-notify",
|
|
|
|
G_CALLBACK (gst_object_default_deep_notify), exclude_list);
|
|
|
|
}
|
|
|
|
|
2010-04-20 11:08:27 +00:00
|
|
|
/* Play the pipeline */
|
|
|
|
mainloop = g_main_loop_new (NULL, FALSE);
|
|
|
|
|
2010-07-15 17:50:22 +00:00
|
|
|
if (thumbinterval != 0.0) {
|
2011-01-17 15:46:15 +00:00
|
|
|
g_printf ("thumbnailing every %f seconds\n", thumbinterval);
|
2010-07-15 17:50:22 +00:00
|
|
|
g_timeout_add (1000 * thumbinterval, thumbnail_cb, pipeline);
|
|
|
|
}
|
|
|
|
|
2010-04-20 11:08:27 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
if (gst_element_set_state (GST_ELEMENT (pipeline),
|
|
|
|
GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
|
2011-01-17 15:46:15 +00:00
|
|
|
g_error ("Failed to start the encoding\n");
|
2010-04-20 11:08:27 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
g_main_loop_run (mainloop);
|
|
|
|
|
|
|
|
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
|
|
|
|
|
2010-06-17 09:45:27 +00:00
|
|
|
gst_object_unref (pipeline);
|
|
|
|
|
2010-09-16 07:07:05 +00:00
|
|
|
return (int) seenerrors;
|
2010-04-20 11:08:27 +00:00
|
|
|
}
|