ges: Port to gst_print*
[platform/upstream/gst-editing-services.git] / examples / c / simple1.c
1 /* GStreamer Editing Services
2  * Copyright (C) 2010 Edward Hervey <bilboed@bilboed.com>
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 #include <stdlib.h>
23
24 int
25 main (int argc, gchar ** argv)
26 {
27   GError *err = NULL;
28   GOptionContext *ctx;
29   GESPipeline *pipeline;
30   GESTimeline *timeline;
31   GESTrack *tracka, *trackv;
32   GESLayer *layer1, *layer2;
33   GESUriClip *src;
34   GMainLoop *mainloop;
35
36   gint inpoint = 0, duration = 10;
37   gboolean mute = FALSE;
38   gchar *audiofile = NULL;
39   GOptionEntry options[] = {
40     {"inpoint", 'i', 0, G_OPTION_ARG_INT, &inpoint,
41         "in-point in the file (in seconds, default:0s)", "seconds"},
42     {"duration", 'd', 0, G_OPTION_ARG_INT, &duration,
43         "duration to use from the file (in seconds, default:10s)", "seconds"},
44     {"mute", 'm', 0, G_OPTION_ARG_NONE, &mute,
45         "Whether to mute the audio from the file",},
46     {"audiofile", 'a', 0, G_OPTION_ARG_FILENAME, &audiofile,
47           "Use this audiofile instead of the original audio from the file",
48         "audiofile"},
49     {NULL}
50   };
51
52   ctx =
53       g_option_context_new
54       ("- Plays an video file with sound (origin/muted/replaced)");
55   g_option_context_add_main_entries (ctx, options, NULL);
56   g_option_context_add_group (ctx, gst_init_get_option_group ());
57
58   if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
59     gst_print ("Error initializing %s\n", err->message);
60     g_option_context_free (ctx);
61     g_clear_error (&err);
62     exit (1);
63   }
64
65   if (argc == 1) {
66     gst_print ("%s", g_option_context_get_help (ctx, TRUE, NULL));
67     exit (0);
68   }
69   g_option_context_free (ctx);
70
71   ges_init ();
72
73   /* Create an Audio/Video pipeline with two layers */
74   pipeline = ges_pipeline_new ();
75
76   timeline = ges_timeline_new ();
77
78   tracka = GES_TRACK (ges_audio_track_new ());
79   trackv = GES_TRACK (ges_video_track_new ());
80
81   layer1 = ges_layer_new ();
82   layer2 = ges_layer_new ();
83   g_object_set (layer2, "priority", 1, NULL);
84
85   if (!ges_timeline_add_layer (timeline, layer1) ||
86       !ges_timeline_add_layer (timeline, layer2) ||
87       !ges_timeline_add_track (timeline, tracka) ||
88       !ges_timeline_add_track (timeline, trackv) ||
89       !ges_pipeline_set_timeline (pipeline, timeline))
90     return -1;
91
92   if (1) {
93     gchar *uri = gst_filename_to_uri (argv[1], NULL);
94     /* Add the main audio/video file */
95     src = ges_uri_clip_new (uri);
96     g_free (uri);
97     g_object_set (src, "start", 0, "in-point", inpoint * GST_SECOND,
98         "duration", duration * GST_SECOND, "mute", mute, NULL);
99     ges_layer_add_clip (layer1, GES_CLIP (src));
100   }
101
102   /* Play the pipeline */
103   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
104   mainloop = g_main_loop_new (NULL, FALSE);
105   g_timeout_add_seconds (duration + 1, (GSourceFunc) g_main_loop_quit,
106       mainloop);
107   g_main_loop_run (mainloop);
108
109   return 0;
110 }