1 /* GStreamer Editing Services
2 * Copyright (C) 2010 Brandon Lewis <brandon@alum.berkeley.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
30 GESTimelineObject *make_source (gchar * path, guint64 start, guint64 inpoint,
31 guint64 duration, gint priority);
33 gboolean print_transition_data (GESTimelineObject * tr);
35 GESTimelinePipeline *make_timeline (gchar * nick, double tdur, gchar * patha,
36 gfloat adur, gdouble ainpoint, gchar * pathb, gfloat bdur,
40 make_source (gchar * path, guint64 start, guint64 duration, guint64 inpoint,
43 char *uri = g_strdup_printf ("file://%s", path);
45 GESTimelineObject *ret =
46 GES_TIMELINE_OBJECT (ges_timeline_filesource_new (uri));
49 "start", (guint64) start,
50 "duration", (guint64) duration,
51 "priority", (guint32) priority, "in-point", (guint64) inpoint, NULL);
59 print_transition_data (GESTimelineObject * tr)
61 GESTrackObject *trackobj;
63 guint64 start, duration;
66 GList *trackobjects, *tmp;
71 if (!(trackobjects = ges_timeline_object_get_track_objects (tr)))
73 if (!(trackobj = GES_TRACK_OBJECT (trackobjects->data)))
75 if (!(gnlobj = ges_track_object_get_gnlobject (trackobj)))
78 g_object_get (gnlobj, "start", &start, "duration", &duration,
79 "priority", &priority, "name", &name, NULL);
80 g_print ("gnlobject for %s: %f %f %d\n", name,
81 ((gfloat) start) / GST_SECOND,
82 ((gfloat) duration) / GST_SECOND, priority);
84 for (tmp = trackobjects; tmp; tmp = tmp->next) {
85 g_object_unref (GES_TRACK_OBJECT (tmp->data));
88 g_list_free (trackobjects);
94 make_timeline (gchar * nick, gdouble tdur, gchar * patha, gfloat adur,
95 gdouble ainp, gchar * pathb, gfloat bdur, gdouble binp)
97 GESTimeline *timeline;
98 GESTrack *trackv, *tracka;
99 GESTimelineLayer *layer1;
100 GESTimelineObject *srca, *srcb;
101 GESTimelinePipeline *pipeline;
102 guint64 aduration, bduration, tduration, tstart, ainpoint, binpoint;
103 GESTimelineStandardTransition *tr = NULL;
105 pipeline = ges_timeline_pipeline_new ();
107 ges_timeline_pipeline_set_mode (pipeline, TIMELINE_MODE_PREVIEW_VIDEO);
109 timeline = ges_timeline_new ();
110 ges_timeline_pipeline_add_timeline (pipeline, timeline);
112 trackv = ges_track_video_raw_new ();
113 ges_timeline_add_track (timeline, trackv);
115 tracka = ges_track_audio_raw_new ();
116 ges_timeline_add_track (timeline, tracka);
118 layer1 = GES_TIMELINE_LAYER (ges_timeline_layer_new ());
119 g_object_set (layer1, "priority", (gint32) 0, NULL);
121 if (!ges_timeline_add_layer (timeline, layer1))
124 aduration = (guint64) (adur * GST_SECOND);
125 bduration = (guint64) (bdur * GST_SECOND);
126 tduration = (guint64) (tdur * GST_SECOND);
127 ainpoint = (guint64) (ainp * GST_SECOND);
128 binpoint = (guint64) (binp * GST_SECOND);
129 tstart = aduration - tduration;
130 srca = make_source (patha, 0, aduration, ainpoint, 1);
131 srcb = make_source (pathb, tstart, bduration, binpoint, 2);
132 ges_timeline_layer_add_object (layer1, srca);
133 ges_timeline_layer_add_object (layer1, srcb);
134 g_timeout_add_seconds (1, (GSourceFunc) print_transition_data, srca);
135 g_timeout_add_seconds (1, (GSourceFunc) print_transition_data, srcb);
137 if (tduration != 0) {
138 g_print ("creating transition at %" GST_TIME_FORMAT " of %f duration (%"
139 GST_TIME_FORMAT ")\n", GST_TIME_ARGS (tstart), tdur,
140 GST_TIME_ARGS (tduration));
141 if (!(tr = ges_timeline_standard_transition_new_for_nick (nick)))
142 g_error ("invalid transition type %s\n", nick);
145 "start", (guint64) tstart,
146 "duration", (guint64) tduration, "in-point", (guint64) 0, NULL);
147 ges_timeline_layer_add_object (layer1, GES_TIMELINE_OBJECT (tr));
148 g_timeout_add_seconds (1, (GSourceFunc) print_transition_data, tr);
155 main (int argc, char **argv)
159 GESTimelinePipeline *pipeline;
161 gchar *type = (gchar *) "crossfade";
162 gchar *patha, *pathb;
163 gdouble adur, bdur, tdur, ainpoint, binpoint;
165 GOptionEntry options[] = {
166 {"type", 't', 0, G_OPTION_ARG_STRING, &type,
167 "type of transition to create", "<smpte-transition>"},
168 {"duration", 'd', 0, G_OPTION_ARG_DOUBLE, &tdur,
169 "duration of transition", "seconds"},
173 if (!g_thread_supported ())
174 g_thread_init (NULL);
176 ctx = g_option_context_new ("- transition between two media files");
177 g_option_context_set_summary (ctx,
178 "Select two files, and optionally a transition duration and type.\n"
179 "A file is a triplet of filename, inpoint (in seconds) and duration (in seconds).\n"
180 "Example:\n" "transition file1.avi 0 5 file2.avi 25 5 -d 2 -t crossfade");
181 g_option_context_add_main_entries (ctx, options, NULL);
182 g_option_context_add_group (ctx, gst_init_get_option_group ());
184 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
185 g_print ("Error initializing %s\n", err->message);
190 g_print ("%s", g_option_context_get_help (ctx, TRUE, NULL));
194 g_option_context_free (ctx);
199 ainpoint = (gdouble) atof (argv[2]);
200 adur = (gdouble) atof (argv[3]);
202 binpoint = (gdouble) atof (argv[5]);
203 bdur = (gdouble) atof (argv[6]);
206 make_timeline (type, tdur, patha, adur, ainpoint, pathb, bdur, binpoint);
208 mainloop = g_main_loop_new (NULL, FALSE);
209 g_timeout_add_seconds ((adur + bdur) + 1, (GSourceFunc) g_main_loop_quit,
211 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
212 g_main_loop_run (mainloop);