gstreamer/tests/examples/transition.c

206 lines
6.2 KiB
C
Raw Normal View History

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
2012-11-04 00:25:20 +00:00
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
2010-05-24 15:39:07 +00:00
*/
2010-06-28 15:23:49 +00:00
#include <stdlib.h>
2010-05-24 15:39:07 +00:00
#include <ges/ges.h>
#include <stdlib.h>
2010-05-24 15:39:07 +00:00
typedef struct
{
int type;
char *name;
} transition_type;
2013-01-20 15:42:29 +00:00
GESClip *make_source (gchar * path, guint64 start, guint64 inpoint,
guint64 duration, gint priority);
2010-06-09 15:09:10 +00:00
2013-01-20 15:42:29 +00:00
gboolean print_transition_data (GESClip * tr);
2010-06-09 15:09:10 +00:00
GESPipeline *make_timeline (gchar * nick, double tdur, gchar * patha,
gfloat adur, gdouble ainpoint, gchar * pathb, gfloat bdur,
gdouble binpoint);
2010-06-09 15:09:10 +00:00
2013-01-20 15:42:29 +00:00
GESClip *
make_source (gchar * path, guint64 start, guint64 duration, guint64 inpoint,
gint priority)
2010-05-25 11:44:57 +00:00
{
gchar *uri = gst_filename_to_uri (path, NULL);
2010-05-25 11:44:57 +00:00
GESClip *ret = GES_CLIP (ges_uri_clip_new (uri));
2010-05-25 11:44:57 +00:00
g_object_set (ret,
"start", (guint64) start,
"duration", (guint64) duration,
"priority", (guint32) priority, "in-point", (guint64) inpoint, NULL);
2010-05-25 11:44:57 +00:00
g_free (uri);
return ret;
}
gboolean
2013-01-20 15:42:29 +00:00
print_transition_data (GESClip * tr)
2010-05-25 11:44:57 +00:00
{
GESTrackElement *trackelement;
Cleanup import of GNL and rename gnl to nle for Non Linear Engine Conflicts: ges/ges-track-element.c gnl/Makefile.am gnl/common Conflicts: ges/ges-internal.h ges/ges-track.c ges/ges-utils.c ges/nle/.gitignore ges/nle/gnlmarshal.list ges/nle/nle.h ges/nle/nlecomposition.c ges/nle/nlecomposition.h ges/nle/nleghostpad.c ges/nle/nleghostpad.h ges/nle/nleobject.c ges/nle/nleoperation.c ges/nle/nleoperation.h ges/nle/nlesource.c ges/nle/nlesource.h ges/nle/nletypes.h ges/nle/nleurisource.c ges/nle/nleurisource.h gnl/Makefile.am gnl/gnl.c gnl/gnl.h gnl/gnl/gnl.h gnl/gnl/gnlcomposition.c gnl/gnl/gnlcomposition.h gnl/gnl/gnlghostpad.c gnl/gnl/gnlghostpad.h gnl/gnl/gnlmarshal.list gnl/gnl/gnlobject.c gnl/gnl/gnloperation.c gnl/gnl/gnloperation.h gnl/gnl/gnlsource.c gnl/gnl/gnlsource.h gnl/gnl/gnltypes.h gnl/gnl/gnlurisource.c gnl/gnl/gnlurisource.h gnl/gnlcomposition.c gnl/gnlcomposition.h gnl/gnlghostpad.c gnl/gnlghostpad.h gnl/gnlmarshal.list gnl/gnlobject.c gnl/gnlobject.h gnl/gnloperation.c gnl/gnloperation.h gnl/gnlsource.c gnl/gnlsource.h gnl/gnltypes.h gnl/gnlurisource.c gnl/gnlurisource.h gnl/tests/check/gnl/common.c gnl/tests/check/gnl/common.h gnl/tests/check/gnl/complex.c gnl/tests/check/gnl/gnlcomposition.c gnl/tests/check/gnl/gnloperation.c gnl/tests/check/gnl/gnlsource.c gnl/tests/check/gnl/seek.c gnl/tests/check/gnl/simple.c tests/check/gnl/common.c tests/check/gnl/common.h tests/check/gnl/complex.c tests/check/gnl/gnlcomposition.c tests/check/gnl/gnloperation.c tests/check/gnl/gnlsource.c tests/check/gnl/seek.c tests/check/gnl/simple.c tests/check/nle/common.c tests/check/nle/common.h tests/check/nle/complex.c tests/check/nle/nlecomposition.c tests/check/nle/nleoperation.c tests/check/nle/nlesource.c tests/check/nle/seek.c tests/check/nle/simple.c
2014-08-15 13:48:14 +00:00
GstElement *nleobj;
2010-05-25 11:44:57 +00:00
guint64 start, duration;
gint priority;
char *name;
GList *trackelements;
2010-05-25 11:44:57 +00:00
2010-06-09 15:09:10 +00:00
if (!tr)
return FALSE;
if (!(trackelements = GES_CONTAINER_CHILDREN (tr)))
return FALSE;
if (!(trackelement = GES_TRACK_ELEMENT (trackelements->data)))
return FALSE;
Cleanup import of GNL and rename gnl to nle for Non Linear Engine Conflicts: ges/ges-track-element.c gnl/Makefile.am gnl/common Conflicts: ges/ges-internal.h ges/ges-track.c ges/ges-utils.c ges/nle/.gitignore ges/nle/gnlmarshal.list ges/nle/nle.h ges/nle/nlecomposition.c ges/nle/nlecomposition.h ges/nle/nleghostpad.c ges/nle/nleghostpad.h ges/nle/nleobject.c ges/nle/nleoperation.c ges/nle/nleoperation.h ges/nle/nlesource.c ges/nle/nlesource.h ges/nle/nletypes.h ges/nle/nleurisource.c ges/nle/nleurisource.h gnl/Makefile.am gnl/gnl.c gnl/gnl.h gnl/gnl/gnl.h gnl/gnl/gnlcomposition.c gnl/gnl/gnlcomposition.h gnl/gnl/gnlghostpad.c gnl/gnl/gnlghostpad.h gnl/gnl/gnlmarshal.list gnl/gnl/gnlobject.c gnl/gnl/gnloperation.c gnl/gnl/gnloperation.h gnl/gnl/gnlsource.c gnl/gnl/gnlsource.h gnl/gnl/gnltypes.h gnl/gnl/gnlurisource.c gnl/gnl/gnlurisource.h gnl/gnlcomposition.c gnl/gnlcomposition.h gnl/gnlghostpad.c gnl/gnlghostpad.h gnl/gnlmarshal.list gnl/gnlobject.c gnl/gnlobject.h gnl/gnloperation.c gnl/gnloperation.h gnl/gnlsource.c gnl/gnlsource.h gnl/gnltypes.h gnl/gnlurisource.c gnl/gnlurisource.h gnl/tests/check/gnl/common.c gnl/tests/check/gnl/common.h gnl/tests/check/gnl/complex.c gnl/tests/check/gnl/gnlcomposition.c gnl/tests/check/gnl/gnloperation.c gnl/tests/check/gnl/gnlsource.c gnl/tests/check/gnl/seek.c gnl/tests/check/gnl/simple.c tests/check/gnl/common.c tests/check/gnl/common.h tests/check/gnl/complex.c tests/check/gnl/gnlcomposition.c tests/check/gnl/gnloperation.c tests/check/gnl/gnlsource.c tests/check/gnl/seek.c tests/check/gnl/simple.c tests/check/nle/common.c tests/check/nle/common.h tests/check/nle/complex.c tests/check/nle/nlecomposition.c tests/check/nle/nleoperation.c tests/check/nle/nlesource.c tests/check/nle/seek.c tests/check/nle/simple.c
2014-08-15 13:48:14 +00:00
if (!(nleobj = ges_track_element_get_nleobject (trackelement)))
return FALSE;
2010-06-09 15:09:10 +00:00
Cleanup import of GNL and rename gnl to nle for Non Linear Engine Conflicts: ges/ges-track-element.c gnl/Makefile.am gnl/common Conflicts: ges/ges-internal.h ges/ges-track.c ges/ges-utils.c ges/nle/.gitignore ges/nle/gnlmarshal.list ges/nle/nle.h ges/nle/nlecomposition.c ges/nle/nlecomposition.h ges/nle/nleghostpad.c ges/nle/nleghostpad.h ges/nle/nleobject.c ges/nle/nleoperation.c ges/nle/nleoperation.h ges/nle/nlesource.c ges/nle/nlesource.h ges/nle/nletypes.h ges/nle/nleurisource.c ges/nle/nleurisource.h gnl/Makefile.am gnl/gnl.c gnl/gnl.h gnl/gnl/gnl.h gnl/gnl/gnlcomposition.c gnl/gnl/gnlcomposition.h gnl/gnl/gnlghostpad.c gnl/gnl/gnlghostpad.h gnl/gnl/gnlmarshal.list gnl/gnl/gnlobject.c gnl/gnl/gnloperation.c gnl/gnl/gnloperation.h gnl/gnl/gnlsource.c gnl/gnl/gnlsource.h gnl/gnl/gnltypes.h gnl/gnl/gnlurisource.c gnl/gnl/gnlurisource.h gnl/gnlcomposition.c gnl/gnlcomposition.h gnl/gnlghostpad.c gnl/gnlghostpad.h gnl/gnlmarshal.list gnl/gnlobject.c gnl/gnlobject.h gnl/gnloperation.c gnl/gnloperation.h gnl/gnlsource.c gnl/gnlsource.h gnl/gnltypes.h gnl/gnlurisource.c gnl/gnlurisource.h gnl/tests/check/gnl/common.c gnl/tests/check/gnl/common.h gnl/tests/check/gnl/complex.c gnl/tests/check/gnl/gnlcomposition.c gnl/tests/check/gnl/gnloperation.c gnl/tests/check/gnl/gnlsource.c gnl/tests/check/gnl/seek.c gnl/tests/check/gnl/simple.c tests/check/gnl/common.c tests/check/gnl/common.h tests/check/gnl/complex.c tests/check/gnl/gnlcomposition.c tests/check/gnl/gnloperation.c tests/check/gnl/gnlsource.c tests/check/gnl/seek.c tests/check/gnl/simple.c tests/check/nle/common.c tests/check/nle/common.h tests/check/nle/complex.c tests/check/nle/nlecomposition.c tests/check/nle/nleoperation.c tests/check/nle/nlesource.c tests/check/nle/seek.c tests/check/nle/simple.c
2014-08-15 13:48:14 +00:00
g_object_get (nleobj, "start", &start, "duration", &duration,
2010-05-25 11:44:57 +00:00
"priority", &priority, "name", &name, NULL);
Cleanup import of GNL and rename gnl to nle for Non Linear Engine Conflicts: ges/ges-track-element.c gnl/Makefile.am gnl/common Conflicts: ges/ges-internal.h ges/ges-track.c ges/ges-utils.c ges/nle/.gitignore ges/nle/gnlmarshal.list ges/nle/nle.h ges/nle/nlecomposition.c ges/nle/nlecomposition.h ges/nle/nleghostpad.c ges/nle/nleghostpad.h ges/nle/nleobject.c ges/nle/nleoperation.c ges/nle/nleoperation.h ges/nle/nlesource.c ges/nle/nlesource.h ges/nle/nletypes.h ges/nle/nleurisource.c ges/nle/nleurisource.h gnl/Makefile.am gnl/gnl.c gnl/gnl.h gnl/gnl/gnl.h gnl/gnl/gnlcomposition.c gnl/gnl/gnlcomposition.h gnl/gnl/gnlghostpad.c gnl/gnl/gnlghostpad.h gnl/gnl/gnlmarshal.list gnl/gnl/gnlobject.c gnl/gnl/gnloperation.c gnl/gnl/gnloperation.h gnl/gnl/gnlsource.c gnl/gnl/gnlsource.h gnl/gnl/gnltypes.h gnl/gnl/gnlurisource.c gnl/gnl/gnlurisource.h gnl/gnlcomposition.c gnl/gnlcomposition.h gnl/gnlghostpad.c gnl/gnlghostpad.h gnl/gnlmarshal.list gnl/gnlobject.c gnl/gnlobject.h gnl/gnloperation.c gnl/gnloperation.h gnl/gnlsource.c gnl/gnlsource.h gnl/gnltypes.h gnl/gnlurisource.c gnl/gnlurisource.h gnl/tests/check/gnl/common.c gnl/tests/check/gnl/common.h gnl/tests/check/gnl/complex.c gnl/tests/check/gnl/gnlcomposition.c gnl/tests/check/gnl/gnloperation.c gnl/tests/check/gnl/gnlsource.c gnl/tests/check/gnl/seek.c gnl/tests/check/gnl/simple.c tests/check/gnl/common.c tests/check/gnl/common.h tests/check/gnl/complex.c tests/check/gnl/gnlcomposition.c tests/check/gnl/gnloperation.c tests/check/gnl/gnlsource.c tests/check/gnl/seek.c tests/check/gnl/simple.c tests/check/nle/common.c tests/check/nle/common.h tests/check/nle/complex.c tests/check/nle/nlecomposition.c tests/check/nle/nleoperation.c tests/check/nle/nlesource.c tests/check/nle/seek.c tests/check/nle/simple.c
2014-08-15 13:48:14 +00:00
g_print ("nleobject 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;
}
GESPipeline *
make_timeline (gchar * nick, gdouble tdur, gchar * patha, gfloat adur,
gdouble ainp, gchar * pathb, gfloat bdur, gdouble binp)
{
GESTimeline *timeline;
GESTrack *trackv, *tracka;
2013-04-23 23:04:04 +00:00
GESLayer *layer1;
2013-01-20 15:42:29 +00:00
GESClip *srca, *srcb;
GESPipeline *pipeline;
guint64 aduration, bduration, tduration, tstart, ainpoint, binpoint;
GESTransitionClip *tr = NULL;
2010-06-09 15:09:10 +00:00
pipeline = ges_pipeline_new ();
ges_pipeline_set_mode (pipeline, GES_PIPELINE_MODE_PREVIEW_VIDEO);
timeline = ges_timeline_new ();
ges_pipeline_set_timeline (pipeline, timeline);
trackv = GES_TRACK (ges_video_track_new ());
ges_timeline_add_track (timeline, trackv);
tracka = GES_TRACK (ges_audio_track_new ());
ges_timeline_add_track (timeline, tracka);
2013-04-23 23:04:04 +00:00
layer1 = GES_LAYER (ges_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);
ainpoint = (guint64) (ainp * GST_SECOND);
binpoint = (guint64) (binp * GST_SECOND);
2010-06-09 15:09:10 +00:00
tstart = aduration - tduration;
srca = make_source (patha, 0, aduration, ainpoint, 1);
srcb = make_source (pathb, tstart, bduration, binpoint, 2);
2013-04-23 23:04:04 +00:00
ges_layer_add_clip (layer1, srca);
ges_layer_add_clip (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));
if (!(tr = ges_transition_clip_new_for_nick (nick)))
g_error ("invalid transition type %s\n", nick);
g_object_set (tr,
"start", (guint64) tstart,
"duration", (guint64) tduration, "in-point", (guint64) 0, NULL);
2013-04-23 23:04:04 +00:00
ges_layer_add_clip (layer1, GES_CLIP (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;
GESPipeline *pipeline;
2010-05-24 15:39:07 +00:00
GMainLoop *mainloop;
2010-06-09 15:09:10 +00:00
gchar *type = (gchar *) "crossfade";
gchar *patha, *pathb;
gdouble adur, bdur, tdur, ainpoint, binpoint;
2010-05-24 15:39:07 +00:00
GOptionEntry options[] = {
{"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}
};
ctx = g_option_context_new ("- transition between two media files");
g_option_context_set_summary (ctx,
"Select two files, and optionally a transition duration and type.\n"
"A file is a triplet of filename, inpoint (in seconds) and duration (in seconds).\n"
"Example:\n" "transition file1.avi 0 5 file2.avi 25 5 -d 2 -t crossfade");
2010-05-24 15:39:07 +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)) {
g_print ("Error initializing %s\n", err->message);
exit (1);
}
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 ();
patha = argv[1];
ainpoint = (gdouble) atof (argv[2]);
adur = (gdouble) atof (argv[3]);
pathb = argv[4];
binpoint = (gdouble) atof (argv[5]);
bdur = (gdouble) atof (argv[6]);
pipeline =
make_timeline (type, tdur, patha, adur, ainpoint, pathb, bdur, binpoint);
2010-05-24 15:39:07 +00:00
mainloop = g_main_loop_new (NULL, FALSE);
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;
}