Advertisement
Guest User

Untitled

a guest
Apr 17th, 2012
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. #include <gst/gst.h>
  2. #include <glib.h>
  3.  
  4. GstElement *audioq, *videoq;
  5.  
  6. static gboolean
  7. bus_call (GstBus *bus,
  8. GstMessage *msg,
  9. gpointer data)
  10. {
  11. GMainLoop *loop = (GMainLoop *) data;
  12.  
  13. switch (GST_MESSAGE_TYPE (msg)) {
  14.  
  15. case GST_MESSAGE_EOS:
  16. g_print ("End of stream\n");
  17. g_main_loop_quit (loop);
  18. break;
  19.  
  20. case GST_MESSAGE_ERROR: {
  21. gchar *debug;
  22. GError *error;
  23.  
  24. gst_message_parse_error (msg, &error, &debug);
  25. g_free (debug);
  26.  
  27. g_printerr ("Error: %s\n", error->message);
  28. g_error_free (error);
  29.  
  30. g_main_loop_quit (loop);
  31. break;
  32. }
  33. default:
  34. break;
  35. }
  36.  
  37. return TRUE;
  38. }
  39.  
  40.  
  41. static void on_pad_added (GstElement *element,GstPad *pad,gpointer data)
  42. {
  43. g_debug ("Signal: pad-added");
  44. GstCaps *caps;
  45. GstStructure *str;
  46.  
  47. caps = gst_pad_get_caps (pad);
  48. g_assert (caps != NULL);
  49. str = gst_caps_get_structure (caps, 0);
  50. g_assert (str != NULL);
  51.  
  52. const gchar *c = gst_structure_get_name(str);
  53. if (g_strrstr (c, "video") || g_strrstr (c, "image")) {
  54. #if 0
  55. g_debug ("Video pad");
  56. GstPad *targetsink = gst_element_get_pad (audioq, "sink");
  57. g_assert (targetsink != NULL);
  58. gst_pad_link (pad, targetsink);
  59. gst_object_unref (targetsink);
  60. #endif
  61. }
  62.  
  63. if (g_strrstr (c, "audio")) {
  64. g_debug ("Audio pad");
  65. GstPad *targetsink = gst_element_get_pad (videoq, "sink");
  66. g_assert (targetsink != NULL);
  67. gst_pad_link (pad, targetsink);
  68. gst_object_unref (targetsink);
  69. }
  70.  
  71. gst_caps_unref (caps);
  72. }
  73.  
  74. int
  75. main (int argc,
  76. char *argv[])
  77. {
  78. GMainLoop *loop;
  79.  
  80. GstElement *pipeline, *filesource, *decode, *filesink, *lame, *audioconvert, *audioresample,*remux;
  81. GstBus *bus;
  82.  
  83. /* Initialisation */
  84. gst_init (&argc, &argv);
  85.  
  86. /* Initialisation */
  87. gst_init (&argc, &argv);
  88.  
  89. loop = g_main_loop_new (NULL, FALSE);
  90.  
  91. /* Check input arguments */
  92. if (argc != 3) {
  93. g_printerr ("Usage: %s <in filename> <out filename>\n", argv[0]);
  94. return -1;
  95. }
  96.  
  97. pipeline = gst_pipeline_new ("player");
  98. filesource = gst_element_factory_make ("filesrc","file-source");
  99. decode = gst_element_factory_make ("decodebin2","decidebin");
  100. filesink = gst_element_factory_make ("filesink","file-sink");
  101. audioq = gst_element_factory_make ("queue","Audio-Queue");
  102. videoq = gst_element_factory_make ("queue","Video-Queue");
  103. lame = gst_element_factory_make ("lamemp3enc","AudioEncode");
  104. audioconvert = gst_element_factory_make ("audioconvert","AudioConvert");
  105. audioresample = gst_element_factory_make ("audioresample","AudioResample");
  106. remux = gst_element_factory_make ("mpegtsmux","ReMux");
  107.  
  108. /* we set the input filename to the source element */
  109.  
  110. g_object_set (G_OBJECT (filesource), "location", argv[1], NULL);
  111. g_object_set (G_OBJECT (filesink), "location", argv[2], NULL);
  112.  
  113.  
  114. /* we add a message handler */
  115. bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  116. gst_bus_add_watch (bus, bus_call, loop);
  117. gst_object_unref (bus);
  118.  
  119. //gst-launch -m filesrc location=/home/richard/Gstreamer/BBC1_DVBS.ts ! decodebin ! audioconvert ! audioresample ! alsasink
  120. /* we add all elements into the pipeline */
  121. gst_bin_add_many (GST_BIN (pipeline),filesource, decode, audioq, audioconvert, audioresample ,lame,remux,filesink, NULL);
  122. gst_element_link (filesource, decode);
  123.  
  124. gst_element_link (audioq,audioconvert);
  125. gst_element_link (audioconvert,audioresample);
  126. gst_element_link (audioresample,lame);
  127. gst_element_link (lame, remux);
  128. gst_element_link (remux, filesink);
  129.  
  130.  
  131. // Lets forget about video for now.
  132. //gst_element_link (videoq, filesink);
  133.  
  134. g_signal_connect (decode, "pad-added", G_CALLBACK (on_pad_added), NULL);
  135.  
  136. g_print ("Now playing: %s\n", argv[1]);
  137. gst_element_set_state (pipeline, GST_STATE_PLAYING);
  138.  
  139. /* Iterate */
  140. g_print ("Running...\n");
  141. g_main_loop_run (loop);
  142.  
  143.  
  144. /* Out of the main loop, clean up nicely */
  145. g_print ("Returned, stopping playback\n");
  146. gst_element_set_state (pipeline, GST_STATE_NULL);
  147.  
  148. g_print ("Deleting pipeline\n");
  149. gst_object_unref (GST_OBJECT (pipeline));
  150.  
  151.  
  152.  
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement