2010-05-24 15:39:07 +00:00
|
|
|
/* GStreamer Editing Services
|
|
|
|
* Copyright (C) 2010 Brandon Lewis <brandon@alum.berkeley.edu>
|
|
|
|
*
|
|
|
|
* 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 <ges/ges.h>
|
2010-07-07 04:21:38 +00:00
|
|
|
#include <stdlib.h>
|
2010-05-24 15:39:07 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
char *name;
|
|
|
|
} transition_type;
|
|
|
|
|
2010-06-09 15:09:10 +00:00
|
|
|
GESTimelineObject *make_source (char *path, guint64 start, guint64 duration,
|
|
|
|
gint priority);
|
|
|
|
|
|
|
|
gboolean print_transition_data (GESTimelineObject * tr);
|
|
|
|
|
|
|
|
GESTimelinePipeline *make_timeline (char *nick, double tdur, char *patha,
|
|
|
|
float adur, char *pathb, float bdur);
|
|
|
|
|
2010-05-25 11:44:57 +00:00
|
|
|
GESTimelineObject *
|
|
|
|
make_source (char *path, guint64 start, guint64 duration, gint priority)
|
|
|
|
{
|
|
|
|
char *uri = g_strdup_printf ("file://%s", path);
|
|
|
|
|
|
|
|
GESTimelineObject *ret =
|
|
|
|
GES_TIMELINE_OBJECT (ges_timeline_filesource_new (uri));
|
|
|
|
|
2010-05-25 14:44:58 +00:00
|
|
|
g_object_set (ret,
|
|
|
|
"start", (guint64) start,
|
|
|
|
"duration", (guint64) duration,
|
|
|
|
"priority", (guint32) priority, "in-point", (guint64) 0, NULL);
|
2010-05-25 11:44:57 +00:00
|
|
|
|
|
|
|
g_free (uri);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
print_transition_data (GESTimelineObject * tr)
|
|
|
|
{
|
2010-06-09 15:09:10 +00:00
|
|
|
GESTrackObject *trackobj;
|
|
|
|
GstElement *gnlobj;
|
2010-05-25 11:44:57 +00:00
|
|
|
guint64 start, duration;
|
|
|
|
gint priority;
|
|
|
|
char *name;
|
|
|
|
|
2010-06-09 15:09:10 +00:00
|
|
|
if (!tr)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
trackobj = GES_TRACK_OBJECT (tr->trackobjects->data);
|
|
|
|
gnlobj = trackobj->gnlobject;
|
|
|
|
|
2010-05-25 11:44:57 +00:00
|
|
|
g_object_get (gnlobj, "start", &start, "duration", &duration,
|
|
|
|
"priority", &priority, "name", &name, NULL);
|
2010-05-25 17:10:27 +00:00
|
|
|
g_print ("gnlobject for %s: %f %f %d\n", name,
|
|
|
|
((gfloat) start) / GST_SECOND,
|
|
|
|
((gfloat) duration) / GST_SECOND, priority);
|
2010-05-25 11:44:57 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-05-26 09:38:19 +00:00
|
|
|
GESTimelinePipeline *
|
2010-05-27 10:04:05 +00:00
|
|
|
make_timeline (char *nick, double tdur, char *patha, float adur,
|
2010-05-26 11:27:46 +00:00
|
|
|
char *pathb, float bdur)
|
2010-05-26 09:38:19 +00:00
|
|
|
{
|
|
|
|
GESTimeline *timeline;
|
2010-05-31 13:42:23 +00:00
|
|
|
GESTrack *trackv, *tracka;
|
2010-05-26 09:38:19 +00:00
|
|
|
GESTimelineLayer *layer1;
|
|
|
|
GESTimelineObject *srca, *srcb;
|
2010-06-09 15:09:10 +00:00
|
|
|
GESTimelinePipeline *pipeline;
|
|
|
|
guint64 aduration, bduration, tduration, tstart;
|
|
|
|
GESTimelineTransition *tr = NULL;
|
|
|
|
|
|
|
|
pipeline = ges_timeline_pipeline_new ();
|
2010-05-26 09:38:19 +00:00
|
|
|
|
|
|
|
ges_timeline_pipeline_set_mode (pipeline, TIMELINE_MODE_PREVIEW_VIDEO);
|
|
|
|
|
|
|
|
timeline = ges_timeline_new ();
|
|
|
|
ges_timeline_pipeline_add_timeline (pipeline, timeline);
|
|
|
|
|
|
|
|
trackv = ges_track_video_raw_new ();
|
|
|
|
ges_timeline_add_track (timeline, trackv);
|
|
|
|
|
2010-05-31 13:42:23 +00:00
|
|
|
tracka = ges_track_audio_raw_new ();
|
|
|
|
ges_timeline_add_track (timeline, tracka);
|
|
|
|
|
2010-05-26 09:38:19 +00:00
|
|
|
layer1 = GES_TIMELINE_LAYER (ges_timeline_layer_new ());
|
|
|
|
g_object_set (layer1, "priority", (gint32) 0, NULL);
|
|
|
|
|
|
|
|
if (!ges_timeline_add_layer (timeline, layer1))
|
|
|
|
exit (-1);
|
|
|
|
|
2010-06-09 15:09:10 +00:00
|
|
|
aduration = (guint64) (adur * GST_SECOND);
|
|
|
|
bduration = (guint64) (bdur * GST_SECOND);
|
|
|
|
tduration = (guint64) (tdur * GST_SECOND);
|
|
|
|
tstart = aduration - tduration;
|
2010-05-26 09:38:19 +00:00
|
|
|
srca = make_source (patha, 0, aduration, 1);
|
|
|
|
srcb = make_source (pathb, tstart, bduration, 2);
|
|
|
|
ges_timeline_layer_add_object (layer1, srca);
|
|
|
|
ges_timeline_layer_add_object (layer1, srcb);
|
|
|
|
g_timeout_add_seconds (1, (GSourceFunc) print_transition_data, srca);
|
|
|
|
g_timeout_add_seconds (1, (GSourceFunc) print_transition_data, srcb);
|
|
|
|
|
|
|
|
if (tduration != 0) {
|
2010-06-11 17:34:39 +00:00
|
|
|
g_print ("creating transition at %" GST_TIME_FORMAT " of %f duration (%"
|
|
|
|
GST_TIME_FORMAT ")\n", GST_TIME_ARGS (tstart), tdur,
|
|
|
|
GST_TIME_ARGS (tduration));
|
2010-05-27 10:04:05 +00:00
|
|
|
if (!(tr = ges_timeline_transition_new_for_nick (nick)))
|
|
|
|
g_error ("invalid transition type %s\n", nick);
|
|
|
|
|
2010-05-26 09:38:19 +00:00
|
|
|
g_object_set (tr,
|
|
|
|
"start", (guint64) tstart,
|
|
|
|
"duration", (guint64) tduration, "in-point", (guint64) 0, NULL);
|
|
|
|
ges_timeline_layer_add_object (layer1, GES_TIMELINE_OBJECT (tr));
|
|
|
|
g_timeout_add_seconds (1, (GSourceFunc) print_transition_data, tr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pipeline;
|
|
|
|
}
|
|
|
|
|
2010-05-24 15:39:07 +00:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
GError *err = NULL;
|
|
|
|
GOptionContext *ctx;
|
|
|
|
GESTimelinePipeline *pipeline;
|
|
|
|
GMainLoop *mainloop;
|
2010-06-09 15:09:10 +00:00
|
|
|
gchar *type = (gchar *) "crossfade";
|
|
|
|
gdouble adur, bdur, tdur;
|
2010-05-24 15:39:07 +00:00
|
|
|
|
|
|
|
GOptionEntry options[] = {
|
2010-05-26 11:05:18 +00:00
|
|
|
{"type", 't', 0, G_OPTION_ARG_STRING, &type,
|
|
|
|
"type of transition to create", "<smpte-transition>"},
|
|
|
|
{"duration", 'd', 0, G_OPTION_ARG_DOUBLE, &tdur,
|
2010-05-24 15:39:07 +00:00
|
|
|
"duration of transition", "seconds"},
|
|
|
|
{NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!g_thread_supported ())
|
|
|
|
g_thread_init (NULL);
|
|
|
|
|
|
|
|
ctx = g_option_context_new ("- transition between two media 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_print ("Error initializing %s\n", err->message);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2010-05-24 15:51:31 +00:00
|
|
|
if (argc < 4) {
|
2010-05-24 15:39:07 +00:00
|
|
|
g_print ("%s", g_option_context_get_help (ctx, TRUE, NULL));
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_option_context_free (ctx);
|
|
|
|
|
|
|
|
ges_init ();
|
|
|
|
|
2010-05-26 11:05:18 +00:00
|
|
|
|
2010-06-09 15:09:10 +00:00
|
|
|
adur = (gdouble) atof (argv[2]);
|
|
|
|
bdur = (gdouble) atof (argv[4]);
|
2010-05-24 15:39:07 +00:00
|
|
|
|
2010-05-27 10:04:05 +00:00
|
|
|
pipeline = make_timeline (type, tdur, argv[1], adur, argv[3], bdur);
|
2010-05-24 15:51:31 +00:00
|
|
|
|
2010-05-24 15:39:07 +00:00
|
|
|
mainloop = g_main_loop_new (NULL, FALSE);
|
2010-05-26 09:38:19 +00:00
|
|
|
g_timeout_add_seconds ((adur + bdur) + 1, (GSourceFunc) g_main_loop_quit,
|
|
|
|
mainloop);
|
2010-05-24 15:39:07 +00:00
|
|
|
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
|
|
|
|
g_main_loop_run (mainloop);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|