1 /* GStreamer Editing Services
2 * Copyright (C) 2010 Edward Hervey <bilboed@bilboed.com>
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., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
28 #include <glib/gstdio.h>
30 #include <gst/pbutils/encoding-profile.h>
33 static guint repeat = 0;
34 GESTimelinePipeline *pipeline = NULL;
36 static gboolean thumbnail_cb (gpointer pipeline);
38 #define TEST_PATH "test_thumbnail.jpg"
41 thumbnail_cb (gpointer user)
45 GESTimelinePipeline *p;
47 p = GES_TIMELINE_PIPELINE (user);
49 caps = gst_caps_from_string ("image/jpeg");
50 GST_INFO ("getting thumbnails");
52 /* check raw rgb use-case with scaling */
53 b = ges_timeline_pipeline_get_thumbnail_rgb24 (p, 320, 240);
57 /* check encoding use-case from caps */
59 b = ges_timeline_pipeline_get_thumbnail (p, caps);
63 g_assert (ges_timeline_pipeline_save_thumbnail (p, -1, -1, (gchar *)
64 "image/jpeg", (gchar *) TEST_PATH, NULL));
65 g_assert (g_file_test (TEST_PATH, G_FILE_TEST_EXISTS));
68 gst_caps_unref (caps);
72 static GESTimelinePipeline *
73 create_timeline (void)
75 GESTimelinePipeline *pipeline;
77 GESTrack *tracka, *trackv;
78 GESTimeline *timeline;
81 timeline = ges_timeline_new ();
83 tracka = GES_TRACK (ges_audio_track_new ());
84 trackv = GES_TRACK (ges_video_track_new ());
86 layer = (GESLayer *) ges_simple_layer_new ();
88 /* Add the tracks and the layer to the timeline */
89 if (!ges_timeline_add_layer (timeline, layer) ||
90 !ges_timeline_add_track (timeline, tracka) ||
91 !ges_timeline_add_track (timeline, trackv))
94 /* Add the main audio/video file */
95 src = GES_CLIP (ges_test_clip_new ());
97 "vpattern", GES_VIDEO_TEST_PATTERN_SNOW,
98 "duration", 10 * GST_SECOND, NULL);
100 ges_simple_layer_add_object ((GESSimpleLayer *) layer, GES_CLIP (src), 0);
102 pipeline = ges_timeline_pipeline_new ();
104 if (!ges_timeline_pipeline_add_timeline (pipeline, timeline))
111 bus_message_cb (GstBus * bus, GstMessage * message, GMainLoop * mainloop)
113 switch (GST_MESSAGE_TYPE (message)) {
114 case GST_MESSAGE_ERROR:
116 g_main_loop_quit (mainloop);
118 case GST_MESSAGE_EOS:
120 g_print ("Looping again\n");
121 /* No need to change state before */
122 gst_element_seek_simple (GST_ELEMENT (pipeline), GST_FORMAT_TIME,
123 GST_SEEK_FLAG_FLUSH, 0);
124 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
128 g_main_loop_quit (mainloop);
137 main (int argc, gchar ** argv)
140 GOptionEntry options[] = {
147 ctx = g_option_context_new ("tests thumbnail supoprt (produces no output)");
148 g_option_context_set_summary (ctx, "");
149 g_option_context_add_main_entries (ctx, options, NULL);
150 g_option_context_add_group (ctx, gst_init_get_option_group ());
152 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
153 g_print ("Error initializing: %s\n", err->message);
154 g_option_context_free (ctx);
158 g_option_context_free (ctx);
159 /* Initialize the GStreamer Editing Services */
162 /* Create the pipeline */
163 pipeline = create_timeline ();
167 ges_timeline_pipeline_set_mode (pipeline, TIMELINE_MODE_PREVIEW);
169 /* Play the pipeline */
170 mainloop = g_main_loop_new (NULL, FALSE);
172 g_print ("thumbnailing every 1 seconds\n");
173 g_timeout_add (1000, thumbnail_cb, pipeline);
175 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
176 gst_bus_add_signal_watch (bus);
177 g_signal_connect (bus, "message", G_CALLBACK (bus_message_cb), mainloop);
179 if (gst_element_set_state (GST_ELEMENT (pipeline),
180 GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
181 g_print ("Failed to start the encoding\n");
184 g_main_loop_run (mainloop);
186 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
187 gst_object_unref (pipeline);