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.
29 GESTimelineObject *make_source (char *path, guint64 start, guint64 duration,
32 GESTimelineObject *make_overlay (char *text, guint64 start, guint64 duration,
33 gint priority, guint32 color, gdouble xpos, gdouble ypos);
35 GESTimelinePipeline *make_timeline (char *path, float duration, char *text,
36 guint32 color, gdouble xpos, gdouble ypos);
38 #define DEFAULT_DURATION 5
39 #define DEFAULT_POS 0.5
42 make_source (char *path, guint64 start, guint64 duration, gint priority)
44 char *uri = g_strdup_printf ("file://%s", path);
46 GESTimelineObject *ret =
47 GES_TIMELINE_OBJECT (ges_timeline_filesource_new (uri));
50 "start", (guint64) start,
51 "duration", (guint64) duration,
52 "priority", (guint32) priority, "in-point", (guint64) 0, NULL);
60 make_overlay (char *text, guint64 start, guint64 duration, gint priority,
61 guint32 color, gdouble xpos, gdouble ypos)
63 GESTimelineObject *ret =
64 GES_TIMELINE_OBJECT (ges_timeline_text_overlay_new ());
67 "text", (gchar *) text,
68 "start", (guint64) start,
69 "duration", (guint64) duration,
70 "priority", (guint32) priority,
71 "in-point", (guint64) 0,
72 "color", (guint32) color,
73 "valignment", (gint) GES_TEXT_VALIGN_POSITION,
74 "halignment", (gint) GES_TEXT_HALIGN_POSITION,
75 "xpos", (gdouble) xpos, "ypos", (gdouble) ypos, NULL);
81 make_timeline (char *path, float duration, char *text, guint32 color,
82 gdouble xpos, gdouble ypos)
84 GESTimeline *timeline;
85 GESTrack *trackv, *tracka;
86 GESTimelineLayer *layer1;
87 GESTimelineObject *srca;
88 GESTimelineObject *overlay;
89 GESTimelinePipeline *pipeline;
92 pipeline = ges_timeline_pipeline_new ();
94 ges_timeline_pipeline_set_mode (pipeline, TIMELINE_MODE_PREVIEW_VIDEO);
96 timeline = ges_timeline_new ();
97 ges_timeline_pipeline_add_timeline (pipeline, timeline);
99 trackv = ges_track_video_raw_new ();
100 ges_timeline_add_track (timeline, trackv);
102 tracka = ges_track_audio_raw_new ();
103 ges_timeline_add_track (timeline, tracka);
105 layer1 = GES_TIMELINE_LAYER (ges_timeline_layer_new ());
106 g_object_set (layer1, "priority", (gint32) 0, NULL);
108 if (!ges_timeline_add_layer (timeline, layer1))
111 aduration = (guint64) (duration * GST_SECOND);
112 srca = make_source (path, 0, aduration, 1);
113 overlay = make_overlay (text, 0, aduration, 0, color, xpos, ypos);
114 ges_timeline_layer_add_object (layer1, srca);
115 ges_timeline_layer_add_object (layer1, overlay);
121 main (int argc, char **argv)
125 GESTimelinePipeline *pipeline;
127 gdouble duration = DEFAULT_DURATION;
130 gdouble xpos = DEFAULT_POS, ypos = DEFAULT_POS;
132 GOptionEntry options[] = {
133 {"duration", 'd', 0, G_OPTION_ARG_DOUBLE, &duration,
134 "duration of segment", "seconds"},
135 {"path", 'p', 0, G_OPTION_ARG_STRING, &path,
136 "path to file", "path"},
137 {"text", 't', 0, G_OPTION_ARG_STRING, &text,
138 "text to render", "text"},
139 {"color", 'c', 0, G_OPTION_ARG_INT64, &color,
140 "color of the text", "color"},
141 {"xpos", 'x', 0, G_OPTION_ARG_DOUBLE, &xpos,
142 "horizontal position of the text", "color"},
143 {"ypos", 'y', 0, G_OPTION_ARG_DOUBLE, &ypos,
144 "vertical position of the text", "color"},
148 if (!g_thread_supported ())
149 g_thread_init (NULL);
151 ctx = g_option_context_new ("- file segment playback with text overlay");
152 g_option_context_add_main_entries (ctx, options, NULL);
153 g_option_context_add_group (ctx, gst_init_get_option_group ());
155 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
156 g_print ("Error initializing %s\n", err->message);
161 g_print ("%s", g_option_context_get_help (ctx, TRUE, NULL));
165 g_option_context_free (ctx);
169 pipeline = make_timeline (path, duration, text, color, xpos, ypos);
171 mainloop = g_main_loop_new (NULL, FALSE);
172 g_timeout_add_seconds ((duration) + 1, (GSourceFunc) g_main_loop_quit,
174 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
175 g_main_loop_run (mainloop);