2010-06-23 16:22:56 +00:00
|
|
|
/* GStreamer Editing Services
|
|
|
|
* Copyright (C) 2010 Brandon Lewis <brandon@alum.berkeley.edu>
|
|
|
|
*
|
|
|
|
* 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-06-23 16:22:56 +00:00
|
|
|
*/
|
|
|
|
|
2010-06-28 15:23:49 +00:00
|
|
|
#include <stdlib.h>
|
2010-06-23 16:22:56 +00:00
|
|
|
#include <ges/ges.h>
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
char *name;
|
|
|
|
} transition_type;
|
|
|
|
|
2013-01-20 15:42:29 +00:00
|
|
|
GESClip *make_source (char *path, guint64 start, guint64 duration,
|
2010-06-23 16:22:56 +00:00
|
|
|
gint priority);
|
|
|
|
|
2013-01-20 15:42:29 +00:00
|
|
|
GESClip *make_overlay (char *text, guint64 start, guint64 duration,
|
2011-08-08 16:57:37 +00:00
|
|
|
gint priority, guint32 color, gdouble xpos, gdouble ypos);
|
2010-06-23 16:22:56 +00:00
|
|
|
|
2013-07-01 14:27:54 +00:00
|
|
|
GESPipeline *make_timeline (char *path, float duration, char *text,
|
2011-08-08 16:57:37 +00:00
|
|
|
guint32 color, gdouble xpos, gdouble ypos);
|
|
|
|
|
|
|
|
#define DEFAULT_DURATION 5
|
|
|
|
#define DEFAULT_POS 0.5
|
2010-06-23 16:22:56 +00:00
|
|
|
|
2013-01-20 15:42:29 +00:00
|
|
|
GESClip *
|
2010-06-23 16:22:56 +00:00
|
|
|
make_source (char *path, guint64 start, guint64 duration, gint priority)
|
|
|
|
{
|
2012-05-01 18:05:51 +00:00
|
|
|
gchar *uri = gst_filename_to_uri (path, NULL);
|
2010-06-23 16:22:56 +00:00
|
|
|
|
2013-01-20 15:44:57 +00:00
|
|
|
GESClip *ret = GES_CLIP (ges_uri_clip_new (uri));
|
2010-06-23 16:22:56 +00:00
|
|
|
|
|
|
|
g_object_set (ret,
|
|
|
|
"start", (guint64) start,
|
|
|
|
"duration", (guint64) duration,
|
|
|
|
"priority", (guint32) priority, "in-point", (guint64) 0, NULL);
|
|
|
|
|
|
|
|
g_free (uri);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-01-20 15:42:29 +00:00
|
|
|
GESClip *
|
2011-08-03 10:37:14 +00:00
|
|
|
make_overlay (char *text, guint64 start, guint64 duration, gint priority,
|
2011-08-08 16:57:37 +00:00
|
|
|
guint32 color, gdouble xpos, gdouble ypos)
|
2010-06-23 16:22:56 +00:00
|
|
|
{
|
2013-01-27 19:02:19 +00:00
|
|
|
GESClip *ret = GES_CLIP (ges_text_overlay_clip_new ());
|
2010-06-23 16:22:56 +00:00
|
|
|
|
|
|
|
g_object_set (ret,
|
|
|
|
"text", (gchar *) text,
|
|
|
|
"start", (guint64) start,
|
|
|
|
"duration", (guint64) duration,
|
2011-08-03 10:37:14 +00:00
|
|
|
"priority", (guint32) priority,
|
2011-08-08 16:57:37 +00:00
|
|
|
"in-point", (guint64) 0,
|
|
|
|
"color", (guint32) color,
|
|
|
|
"valignment", (gint) GES_TEXT_VALIGN_POSITION,
|
|
|
|
"halignment", (gint) GES_TEXT_HALIGN_POSITION,
|
|
|
|
"xpos", (gdouble) xpos, "ypos", (gdouble) ypos, NULL);
|
2010-06-23 16:22:56 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-07-01 14:27:54 +00:00
|
|
|
GESPipeline *
|
2011-08-08 16:57:37 +00:00
|
|
|
make_timeline (char *path, float duration, char *text, guint32 color,
|
|
|
|
gdouble xpos, gdouble ypos)
|
2010-06-23 16:22:56 +00:00
|
|
|
{
|
|
|
|
GESTimeline *timeline;
|
|
|
|
GESTrack *trackv, *tracka;
|
2013-04-23 23:04:04 +00:00
|
|
|
GESLayer *layer1;
|
2013-01-20 15:42:29 +00:00
|
|
|
GESClip *srca;
|
|
|
|
GESClip *overlay;
|
2013-07-01 14:27:54 +00:00
|
|
|
GESPipeline *pipeline;
|
2010-06-23 16:22:56 +00:00
|
|
|
guint64 aduration;
|
|
|
|
|
2013-07-01 14:27:54 +00:00
|
|
|
pipeline = ges_pipeline_new ();
|
2010-06-23 16:22:56 +00:00
|
|
|
|
2014-02-17 11:34:04 +00:00
|
|
|
ges_pipeline_set_mode (pipeline, GES_PIPELINE_MODE_PREVIEW_VIDEO);
|
2010-06-23 16:22:56 +00:00
|
|
|
|
|
|
|
timeline = ges_timeline_new ();
|
2014-02-04 09:45:58 +00:00
|
|
|
ges_pipeline_set_timeline (pipeline, timeline);
|
2010-06-23 16:22:56 +00:00
|
|
|
|
2013-03-28 17:51:45 +00:00
|
|
|
trackv = GES_TRACK (ges_video_track_new ());
|
2010-06-23 16:22:56 +00:00
|
|
|
ges_timeline_add_track (timeline, trackv);
|
|
|
|
|
2013-03-28 17:51:45 +00:00
|
|
|
tracka = GES_TRACK (ges_audio_track_new ());
|
2010-06-23 16:22:56 +00:00
|
|
|
ges_timeline_add_track (timeline, tracka);
|
|
|
|
|
2013-04-23 23:04:04 +00:00
|
|
|
layer1 = GES_LAYER (ges_layer_new ());
|
2010-06-23 16:22:56 +00:00
|
|
|
g_object_set (layer1, "priority", (gint32) 0, NULL);
|
|
|
|
|
|
|
|
if (!ges_timeline_add_layer (timeline, layer1))
|
|
|
|
exit (-1);
|
|
|
|
|
|
|
|
aduration = (guint64) (duration * GST_SECOND);
|
|
|
|
srca = make_source (path, 0, aduration, 1);
|
2011-08-08 16:57:37 +00:00
|
|
|
overlay = make_overlay (text, 0, aduration, 0, color, xpos, ypos);
|
2013-04-23 23:04:04 +00:00
|
|
|
ges_layer_add_clip (layer1, srca);
|
|
|
|
ges_layer_add_clip (layer1, overlay);
|
2010-06-23 16:22:56 +00:00
|
|
|
|
|
|
|
return pipeline;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
GError *err = NULL;
|
|
|
|
GOptionContext *ctx;
|
2013-07-01 14:27:54 +00:00
|
|
|
GESPipeline *pipeline;
|
2010-06-23 16:22:56 +00:00
|
|
|
GMainLoop *mainloop;
|
2011-08-08 16:57:37 +00:00
|
|
|
gdouble duration = DEFAULT_DURATION;
|
2012-05-01 18:05:51 +00:00
|
|
|
char *path = NULL, *text;
|
2011-08-03 10:37:14 +00:00
|
|
|
guint64 color;
|
2011-08-08 16:57:37 +00:00
|
|
|
gdouble xpos = DEFAULT_POS, ypos = DEFAULT_POS;
|
2010-06-23 16:22:56 +00:00
|
|
|
|
|
|
|
GOptionEntry options[] = {
|
|
|
|
{"duration", 'd', 0, G_OPTION_ARG_DOUBLE, &duration,
|
2011-08-08 16:57:37 +00:00
|
|
|
"duration of segment", "seconds"},
|
2010-06-23 16:22:56 +00:00
|
|
|
{"path", 'p', 0, G_OPTION_ARG_STRING, &path,
|
|
|
|
"path to file", "path"},
|
|
|
|
{"text", 't', 0, G_OPTION_ARG_STRING, &text,
|
|
|
|
"text to render", "text"},
|
2011-08-03 10:37:14 +00:00
|
|
|
{"color", 'c', 0, G_OPTION_ARG_INT64, &color,
|
|
|
|
"color of the text", "color"},
|
2011-08-08 16:57:37 +00:00
|
|
|
{"xpos", 'x', 0, G_OPTION_ARG_DOUBLE, &xpos,
|
|
|
|
"horizontal position of the text", "color"},
|
|
|
|
{"ypos", 'y', 0, G_OPTION_ARG_DOUBLE, &ypos,
|
|
|
|
"vertical position of the text", "color"},
|
2010-06-23 16:22:56 +00:00
|
|
|
{NULL}
|
|
|
|
};
|
|
|
|
|
2011-08-08 16:57:37 +00:00
|
|
|
ctx = g_option_context_new ("- file segment playback with text overlay");
|
2010-06-23 16:22:56 +00:00
|
|
|
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)) {
|
|
|
|
g_print ("Error initializing %s\n", err->message);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > 1) {
|
|
|
|
g_print ("%s", g_option_context_get_help (ctx, TRUE, NULL));
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_option_context_free (ctx);
|
|
|
|
|
|
|
|
ges_init ();
|
|
|
|
|
2012-05-01 18:05:51 +00:00
|
|
|
if (path == NULL)
|
|
|
|
g_error ("Must specify --path=/path/to/media/file option\n");
|
|
|
|
|
2011-08-08 16:57:37 +00:00
|
|
|
pipeline = make_timeline (path, duration, text, color, xpos, ypos);
|
2010-06-23 16:22:56 +00:00
|
|
|
|
|
|
|
mainloop = g_main_loop_new (NULL, FALSE);
|
|
|
|
g_timeout_add_seconds ((duration) + 1, (GSourceFunc) g_main_loop_quit,
|
|
|
|
mainloop);
|
|
|
|
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
|
|
|
|
g_main_loop_run (mainloop);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|