/tests/examples/simple1.c

https://github.com/freesteph/gst-editing-services · C · 112 lines · 74 code · 16 blank · 22 comment · 6 complexity · 81139fe8fdc299279a674a5deacd35e4 MD5 · raw file

  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., 59 Temple Place - Suite 330,
  17. * Boston, MA 02111-1307, USA.
  18. */
  19. #include <stdlib.h>
  20. #include <ges/ges.h>
  21. #include <stdlib.h>
  22. int
  23. main (int argc, gchar ** argv)
  24. {
  25. GError *err = NULL;
  26. GOptionContext *ctx;
  27. GESTimelinePipeline *pipeline;
  28. GESTimeline *timeline;
  29. GESTrack *tracka, *trackv;
  30. GESTimelineLayer *layer1, *layer2;
  31. GESTimelineFileSource *src;
  32. GMainLoop *mainloop;
  33. gint inpoint = 0, duration = 10;
  34. gboolean mute = FALSE;
  35. gchar *audiofile = NULL;
  36. GOptionEntry options[] = {
  37. {"inpoint", 'i', 0, G_OPTION_ARG_INT, &inpoint,
  38. "in-point in the file (in seconds, default:0s)", "seconds"},
  39. {"duration", 'd', 0, G_OPTION_ARG_INT, &duration,
  40. "duration to use from the file (in seconds, default:10s)", "seconds"},
  41. {"mute", 'm', 0, G_OPTION_ARG_NONE, &mute,
  42. "Whether to mute the audio from the file",},
  43. {"audiofile", 'a', 0, G_OPTION_ARG_FILENAME, &audiofile,
  44. "Use this audiofile instead of the original audio from the file",
  45. "audiofile"},
  46. {NULL}
  47. };
  48. /* Initialization and option parsing */
  49. if (!g_thread_supported ())
  50. g_thread_init (NULL);
  51. ctx =
  52. g_option_context_new
  53. ("- Plays an video file with sound (origin/muted/replaced)");
  54. g_option_context_add_main_entries (ctx, options, NULL);
  55. g_option_context_add_group (ctx, gst_init_get_option_group ());
  56. if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
  57. g_print ("Error initializing %s\n", err->message);
  58. exit (1);
  59. }
  60. if (argc == 1) {
  61. g_print ("%s", g_option_context_get_help (ctx, TRUE, NULL));
  62. exit (0);
  63. }
  64. g_option_context_free (ctx);
  65. ges_init ();
  66. /* Create an Audio/Video pipeline with two layers */
  67. pipeline = ges_timeline_pipeline_new ();
  68. timeline = ges_timeline_new ();
  69. tracka = ges_track_audio_raw_new ();
  70. trackv = ges_track_video_raw_new ();
  71. layer1 = (GESTimelineLayer *) ges_simple_timeline_layer_new ();
  72. layer2 = (GESTimelineLayer *) ges_simple_timeline_layer_new ();
  73. g_object_set (layer2, "priority", 1, NULL);
  74. if (!ges_timeline_add_layer (timeline, layer1) ||
  75. !ges_timeline_add_layer (timeline, layer2) ||
  76. !ges_timeline_add_track (timeline, tracka) ||
  77. !ges_timeline_add_track (timeline, trackv) ||
  78. !ges_timeline_pipeline_add_timeline (pipeline, timeline))
  79. return -1;
  80. if (1) {
  81. gchar *uri = g_strdup_printf ("file://%s", argv[1]);
  82. /* Add the main audio/video file */
  83. src = ges_timeline_filesource_new (uri);
  84. g_free (uri);
  85. g_object_set (src, "in-point", inpoint * GST_SECOND,
  86. "duration", duration * GST_SECOND, "mute", mute, NULL);
  87. ges_timeline_layer_add_object (layer1, GES_TIMELINE_OBJECT (src));
  88. }
  89. /* Play the pipeline */
  90. gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
  91. mainloop = g_main_loop_new (NULL, FALSE);
  92. g_timeout_add_seconds (duration + 1, (GSourceFunc) g_main_loop_quit,
  93. mainloop);
  94. g_main_loop_run (mainloop);
  95. return 0;
  96. }