2010-07-16 16:37:54 +00:00
|
|
|
/* GStreamer Editing Services
|
|
|
|
* Copyright (C) 2010 Edward Hervey <bilboed@bilboed.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-04 00:25:20 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2010-07-16 16:37:54 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <glib/gstdio.h>
|
|
|
|
#include <ges/ges.h>
|
2010-12-15 11:36:25 +00:00
|
|
|
#include <gst/pbutils/encoding-profile.h>
|
2010-07-16 16:37:54 +00:00
|
|
|
|
|
|
|
/* GLOBAL VARIABLE */
|
|
|
|
static guint repeat = 0;
|
2013-07-01 14:27:54 +00:00
|
|
|
GESPipeline *pipeline = NULL;
|
2010-07-16 16:37:54 +00:00
|
|
|
|
|
|
|
static gboolean thumbnail_cb (gpointer pipeline);
|
|
|
|
|
|
|
|
#define TEST_PATH "test_thumbnail.jpg"
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
thumbnail_cb (gpointer user)
|
|
|
|
{
|
2011-12-30 16:18:40 +00:00
|
|
|
GstSample *b = NULL;
|
2010-07-16 16:37:54 +00:00
|
|
|
GstCaps *caps;
|
2013-07-01 14:27:54 +00:00
|
|
|
GESPipeline *p;
|
2010-07-16 16:37:54 +00:00
|
|
|
|
2013-09-09 15:47:02 +00:00
|
|
|
p = GES_PIPELINE (user);
|
2010-07-16 16:37:54 +00:00
|
|
|
|
|
|
|
caps = gst_caps_from_string ("image/jpeg");
|
|
|
|
GST_INFO ("getting thumbnails");
|
|
|
|
|
|
|
|
/* check raw rgb use-case with scaling */
|
2013-07-01 14:27:54 +00:00
|
|
|
b = ges_pipeline_get_thumbnail_rgb24 (p, 320, 240);
|
2010-07-16 16:37:54 +00:00
|
|
|
g_assert (b);
|
2011-12-30 16:18:40 +00:00
|
|
|
gst_sample_unref (b);
|
2010-07-16 16:37:54 +00:00
|
|
|
|
|
|
|
/* check encoding use-case from caps */
|
|
|
|
b = NULL;
|
2013-07-01 14:27:54 +00:00
|
|
|
b = ges_pipeline_get_thumbnail (p, caps);
|
2010-07-16 16:37:54 +00:00
|
|
|
g_assert (b);
|
2011-12-30 16:18:40 +00:00
|
|
|
gst_sample_unref (b);
|
2010-07-16 16:37:54 +00:00
|
|
|
|
2013-07-01 14:27:54 +00:00
|
|
|
g_assert (ges_pipeline_save_thumbnail (p, -1, -1, (gchar *)
|
2013-04-17 19:51:30 +00:00
|
|
|
"image/jpeg", (gchar *) TEST_PATH, NULL));
|
2010-07-16 16:37:54 +00:00
|
|
|
g_assert (g_file_test (TEST_PATH, G_FILE_TEST_EXISTS));
|
|
|
|
g_unlink (TEST_PATH);
|
|
|
|
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-07-01 14:27:54 +00:00
|
|
|
static GESPipeline *
|
2010-07-16 16:37:54 +00:00
|
|
|
create_timeline (void)
|
|
|
|
{
|
2013-07-01 14:27:54 +00:00
|
|
|
GESPipeline *pipeline;
|
2013-04-23 23:04:04 +00:00
|
|
|
GESLayer *layer;
|
2010-07-16 16:37:54 +00:00
|
|
|
GESTrack *tracka, *trackv;
|
|
|
|
GESTimeline *timeline;
|
2013-01-20 15:42:29 +00:00
|
|
|
GESClip *src;
|
2010-07-16 16:37:54 +00:00
|
|
|
|
|
|
|
timeline = ges_timeline_new ();
|
|
|
|
|
2013-03-28 17:51:45 +00:00
|
|
|
tracka = GES_TRACK (ges_audio_track_new ());
|
|
|
|
trackv = GES_TRACK (ges_video_track_new ());
|
2010-07-16 16:37:54 +00:00
|
|
|
|
2013-11-22 20:49:49 +00:00
|
|
|
layer = ges_layer_new ();
|
2010-07-16 16:37:54 +00:00
|
|
|
|
|
|
|
/* Add the tracks and the layer to the timeline */
|
|
|
|
if (!ges_timeline_add_layer (timeline, layer) ||
|
|
|
|
!ges_timeline_add_track (timeline, tracka) ||
|
|
|
|
!ges_timeline_add_track (timeline, trackv))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Add the main audio/video file */
|
2013-01-17 03:58:28 +00:00
|
|
|
src = GES_CLIP (ges_test_clip_new ());
|
2010-07-16 16:37:54 +00:00
|
|
|
g_object_set (src,
|
|
|
|
"vpattern", GES_VIDEO_TEST_PATTERN_SNOW,
|
2013-11-22 20:49:49 +00:00
|
|
|
"start", 0, "duration", 10 * GST_SECOND, NULL);
|
2010-07-16 16:37:54 +00:00
|
|
|
|
2013-11-22 20:49:49 +00:00
|
|
|
ges_layer_add_clip (layer, GES_CLIP (src));
|
2010-07-16 16:37:54 +00:00
|
|
|
|
2013-07-01 14:27:54 +00:00
|
|
|
pipeline = ges_pipeline_new ();
|
2010-07-16 16:37:54 +00:00
|
|
|
|
2014-02-04 09:45:58 +00:00
|
|
|
if (!ges_pipeline_set_timeline (pipeline, timeline))
|
2010-07-16 16:37:54 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return pipeline;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bus_message_cb (GstBus * bus, GstMessage * message, GMainLoop * mainloop)
|
|
|
|
{
|
|
|
|
switch (GST_MESSAGE_TYPE (message)) {
|
|
|
|
case GST_MESSAGE_ERROR:
|
2021-04-27 15:57:35 +00:00
|
|
|
gst_print ("ERROR\n");
|
2010-07-16 16:37:54 +00:00
|
|
|
g_main_loop_quit (mainloop);
|
|
|
|
break;
|
|
|
|
case GST_MESSAGE_EOS:
|
|
|
|
if (repeat > 0) {
|
2021-04-27 15:57:35 +00:00
|
|
|
gst_print ("Looping again\n");
|
2010-07-16 16:37:54 +00:00
|
|
|
/* No need to change state before */
|
|
|
|
gst_element_seek_simple (GST_ELEMENT (pipeline), GST_FORMAT_TIME,
|
|
|
|
GST_SEEK_FLAG_FLUSH, 0);
|
|
|
|
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
|
|
|
|
repeat -= 1;
|
|
|
|
} else {
|
2021-04-27 15:57:35 +00:00
|
|
|
gst_print ("Done\n");
|
2010-07-16 16:37:54 +00:00
|
|
|
g_main_loop_quit (mainloop);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, gchar ** argv)
|
|
|
|
{
|
|
|
|
GError *err = NULL;
|
|
|
|
GOptionEntry options[] = {
|
|
|
|
{NULL}
|
|
|
|
};
|
|
|
|
GOptionContext *ctx;
|
|
|
|
GMainLoop *mainloop;
|
|
|
|
GstBus *bus;
|
|
|
|
|
|
|
|
ctx = g_option_context_new ("tests thumbnail supoprt (produces no output)");
|
|
|
|
g_option_context_set_summary (ctx, "");
|
|
|
|
g_option_context_add_main_entries (ctx, options, NULL);
|
|
|
|
g_option_context_add_group (ctx, gst_init_get_option_group ());
|
|
|
|
|
|
|
|
if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
|
2021-04-27 15:57:35 +00:00
|
|
|
gst_print ("Error initializing: %s\n", err->message);
|
2010-07-16 16:37:54 +00:00
|
|
|
g_option_context_free (ctx);
|
2015-08-20 08:16:50 +00:00
|
|
|
g_clear_error (&err);
|
2010-07-16 16:37:54 +00:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_option_context_free (ctx);
|
|
|
|
/* Initialize the GStreamer Editing Services */
|
|
|
|
ges_init ();
|
|
|
|
|
|
|
|
/* Create the pipeline */
|
|
|
|
pipeline = create_timeline ();
|
|
|
|
if (!pipeline)
|
|
|
|
exit (-1);
|
|
|
|
|
2014-02-17 11:34:04 +00:00
|
|
|
ges_pipeline_set_mode (pipeline, GES_PIPELINE_MODE_PREVIEW);
|
2010-07-16 16:37:54 +00:00
|
|
|
|
|
|
|
/* Play the pipeline */
|
|
|
|
mainloop = g_main_loop_new (NULL, FALSE);
|
|
|
|
|
2021-04-27 15:57:35 +00:00
|
|
|
gst_print ("thumbnailing every 1 seconds\n");
|
2010-07-16 16:37:54 +00:00
|
|
|
g_timeout_add (1000, thumbnail_cb, pipeline);
|
|
|
|
|
|
|
|
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
|
|
|
|
gst_bus_add_signal_watch (bus);
|
|
|
|
g_signal_connect (bus, "message", G_CALLBACK (bus_message_cb), mainloop);
|
|
|
|
|
|
|
|
if (gst_element_set_state (GST_ELEMENT (pipeline),
|
|
|
|
GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
|
2021-04-27 15:57:35 +00:00
|
|
|
gst_print ("Failed to start the encoding\n");
|
2010-07-16 16:37:54 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
g_main_loop_run (mainloop);
|
|
|
|
|
|
|
|
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
|
|
|
|
gst_object_unref (pipeline);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|