ges: Port to gst_print*
[platform/upstream/gst-editing-services.git] / examples / c / text_properties.c
1 /* GStreamer Editing Services
2  * Copyright (C) 2010 Brandon Lewis <brandon@alum.berkeley.edu>
3  *
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.
8  *
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.
13  *
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., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #include <stdlib.h>
21 #include <ges/ges.h>
22
23 typedef struct
24 {
25   int type;
26   char *name;
27 } transition_type;
28
29 GESClip *make_source (char *path, guint64 start, guint64 duration,
30     gint priority, gchar * text);
31
32 GESPipeline *make_timeline (char *path, float duration, char *text);
33
34 GESClip *
35 make_source (char *path, guint64 start, guint64 duration, gint priority,
36     gchar * text)
37 {
38   gchar *uri = gst_filename_to_uri (path, NULL);
39
40   GESClip *ret = GES_CLIP (ges_uri_clip_new (uri));
41
42   g_object_set (ret,
43       "start", (guint64) start,
44       "duration", (guint64) duration,
45       "priority", (guint32) priority, "in-point", (guint64) 0,
46       "text", text, NULL);
47
48   g_free (uri);
49
50   return ret;
51 }
52
53 GESPipeline *
54 make_timeline (char *path, float duration, char *text)
55 {
56   GESTimeline *timeline;
57   GESTrack *trackv, *tracka;
58   GESLayer *layer1;
59   GESClip *srca;
60   GESPipeline *pipeline;
61   guint64 aduration;
62
63   pipeline = ges_pipeline_new ();
64
65   ges_pipeline_set_mode (pipeline, GES_PIPELINE_MODE_PREVIEW_VIDEO);
66
67   timeline = ges_timeline_new ();
68   ges_pipeline_set_timeline (pipeline, timeline);
69
70   trackv = GES_TRACK (ges_video_track_new ());
71   ges_timeline_add_track (timeline, trackv);
72
73   tracka = GES_TRACK (ges_audio_track_new ());
74   ges_timeline_add_track (timeline, tracka);
75
76   layer1 = GES_LAYER (ges_layer_new ());
77   g_object_set (layer1, "priority", (gint32) 0, NULL);
78
79   if (!ges_timeline_add_layer (timeline, layer1))
80     exit (-1);
81
82   aduration = (guint64) (duration * GST_SECOND);
83   srca = make_source (path, 0, aduration, 1, text);
84   ges_layer_add_clip (layer1, srca);
85
86   return pipeline;
87 }
88
89 int
90 main (int argc, char **argv)
91 {
92   GError *err = NULL;
93   GOptionContext *ctx;
94   GESPipeline *pipeline;
95   GMainLoop *mainloop;
96   gdouble duration;
97   char *path, *text;
98
99   GOptionEntry options[] = {
100     {"duration", 'd', 0, G_OPTION_ARG_DOUBLE, &duration,
101         "duration of transition", "seconds"},
102     {"path", 'p', 0, G_OPTION_ARG_STRING, &path,
103         "path to file", "path"},
104     {"text", 't', 0, G_OPTION_ARG_STRING, &text,
105         "text to render", "text"},
106     {NULL}
107   };
108
109   ctx = g_option_context_new ("- transition between two media files");
110   g_option_context_add_main_entries (ctx, options, NULL);
111   g_option_context_add_group (ctx, gst_init_get_option_group ());
112
113   if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
114     gst_print ("Error initializing %s\n", err->message);
115     g_option_context_free (ctx);
116     g_clear_error (&err);
117     exit (1);
118   }
119
120   if (argc > 1) {
121     gst_print ("%s", g_option_context_get_help (ctx, TRUE, NULL));
122     exit (0);
123   }
124
125   g_option_context_free (ctx);
126
127   ges_init ();
128
129   pipeline = make_timeline (path, duration, text);
130
131   mainloop = g_main_loop_new (NULL, FALSE);
132   g_timeout_add_seconds ((duration) + 1, (GSourceFunc) g_main_loop_quit,
133       mainloop);
134   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
135   g_main_loop_run (mainloop);
136
137   return 0;
138 }