Advertisement
Guest User

PlayVideo_doesntwork

a guest
Oct 28th, 2017
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.73 KB | None | 0 0
  1. #include <gst/gst.h>
  2. #include <glib.h>
  3.  
  4. static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data)
  5. {
  6.   GMainLoop *loop = (GMainLoop *) data;
  7.  
  8.   switch (GST_MESSAGE_TYPE (msg)) {
  9.  
  10.     case GST_MESSAGE_EOS:
  11.       g_print ("End of stream\n");
  12.       g_main_loop_quit (loop);
  13.       break;
  14.  
  15.     case GST_MESSAGE_ERROR: {
  16.       gchar  *debug;
  17.       GError *error;
  18.  
  19.       gst_message_parse_error (msg, &error, &debug);
  20.       g_free (debug);
  21.  
  22.       g_printerr ("Error: %s\n", error->message);
  23.       g_error_free (error);
  24.  
  25.       g_main_loop_quit (loop);
  26.       break;
  27.     }
  28.     default:
  29.       break;
  30.   }
  31.  
  32.   return TRUE;
  33. }
  34.  
  35. int main (int argc, char *argv[])
  36. {
  37.   GMainLoop *loop;
  38.  
  39.   GstElement *pipeline, *videosrc, *colorspace, *videoenc,
  40.     *videoq, *audiosrc, *conv, *audioenc, *audioq, *muxer,
  41.           *sink;
  42.  
  43.   GstBus *bus;
  44.  
  45.   /* Initialisation */
  46.   gst_init (NULL, NULL);
  47.  
  48.   loop = g_main_loop_new (NULL, FALSE);
  49.  
  50.   /* Create gstreamer elements */
  51.   pipeline = gst_pipeline_new ("audio-player");
  52.   videosrc = gst_element_factory_make ("filesrc", "videosrc");
  53.   muxer = gst_element_factory_make ("qtdemux", "mux");
  54.   videoenc = gst_element_factory_make ("decodebin", "videoenc"); //avdec_mpeg4
  55.   sink = gst_element_factory_make ("autovideosink", "sink"); //autovideosink
  56.  
  57.   if (!pipeline || !videosrc  || !videoenc || !muxer
  58.        || !sink) {
  59.     g_printerr ("One element could not be created. Exiting.\n");
  60.     return -1;
  61.   }
  62.  
  63.   /* Set up the pipeline */
  64.   g_print ("Elements are created\n");
  65.  
  66.   /* set the properties of other elements */
  67.   printf("location = %s \n", argv[1]);
  68.   g_object_set (G_OBJECT (videosrc), "location", argv[1], NULL);
  69.  
  70.   /* we add a message handler */
  71.   bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  72.   gst_bus_add_watch (bus, bus_call, loop);
  73.   gst_object_unref (bus);
  74.  
  75.   /* we add all elements into the pipeline */
  76.   gst_bin_add_many (GST_BIN (pipeline),
  77.     videosrc, muxer, videoenc, sink, NULL);
  78.  
  79.   g_print ("Added all the Elements into the pipeline\n");
  80.  
  81.   /* we link the elements together */
  82.   int reslinkmany = gst_element_link_many (videosrc, muxer,
  83.                          videoenc, sink, NULL);
  84.  
  85.     printf("reslinkmany = %d \n", reslinkmany);
  86.  
  87.   g_print ("Linked all the Elements together\n");
  88.   /* Set the pipeline to "playing" state*/
  89.   g_print ("Playing the video\n");
  90.   gst_element_set_state (pipeline, GST_STATE_PLAYING);
  91.  
  92.   /* Iterate */
  93.   g_print ("Running...\n");
  94.   g_main_loop_run (loop);
  95.  
  96.   /* Out of the main loop, clean up nicely */
  97.   g_print ("Returned, stopping playback\n");
  98.   gst_element_set_state (pipeline, GST_STATE_NULL);
  99.  
  100.   g_print ("Deleting pipeline\n");
  101.   gst_object_unref (GST_OBJECT (pipeline));
  102.  
  103.   return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement