Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gst/gst.h>
- #include <glib.h>
- GstElement *audioq, *videoq;
- static gboolean
- bus_call (GstBus *bus,
- GstMessage *msg,
- gpointer data)
- {
- GMainLoop *loop = (GMainLoop *) data;
- switch (GST_MESSAGE_TYPE (msg)) {
- case GST_MESSAGE_EOS:
- g_print ("End of stream\n");
- g_main_loop_quit (loop);
- break;
- case GST_MESSAGE_ERROR: {
- gchar *debug;
- GError *error;
- gst_message_parse_error (msg, &error, &debug);
- g_free (debug);
- g_printerr ("Error: %s\n", error->message);
- g_error_free (error);
- g_main_loop_quit (loop);
- break;
- }
- default:
- break;
- }
- return TRUE;
- }
- static void on_pad_added (GstElement *element,GstPad *pad,gpointer data)
- {
- g_debug ("Signal: pad-added");
- GstCaps *caps;
- GstStructure *str;
- caps = gst_pad_get_caps (pad);
- g_assert (caps != NULL);
- str = gst_caps_get_structure (caps, 0);
- g_assert (str != NULL);
- const gchar *c = gst_structure_get_name(str);
- if (g_strrstr (c, "video") || g_strrstr (c, "image")) {
- #if 0
- g_debug ("Video pad");
- GstPad *targetsink = gst_element_get_pad (audioq, "sink");
- g_assert (targetsink != NULL);
- gst_pad_link (pad, targetsink);
- gst_object_unref (targetsink);
- #endif
- }
- if (g_strrstr (c, "audio")) {
- g_debug ("Audio pad");
- GstPad *targetsink = gst_element_get_pad (videoq, "sink");
- g_assert (targetsink != NULL);
- gst_pad_link (pad, targetsink);
- gst_object_unref (targetsink);
- }
- gst_caps_unref (caps);
- }
- int
- main (int argc,
- char *argv[])
- {
- GMainLoop *loop;
- GstElement *pipeline, *filesource, *decode, *filesink, *lame, *audioconvert, *audioresample,*remux;
- GstBus *bus;
- /* Initialisation */
- gst_init (&argc, &argv);
- /* Initialisation */
- gst_init (&argc, &argv);
- loop = g_main_loop_new (NULL, FALSE);
- /* Check input arguments */
- if (argc != 3) {
- g_printerr ("Usage: %s <in filename> <out filename>\n", argv[0]);
- return -1;
- }
- pipeline = gst_pipeline_new ("player");
- filesource = gst_element_factory_make ("filesrc","file-source");
- decode = gst_element_factory_make ("decodebin2","decidebin");
- filesink = gst_element_factory_make ("filesink","file-sink");
- audioq = gst_element_factory_make ("queue","Audio-Queue");
- videoq = gst_element_factory_make ("queue","Video-Queue");
- lame = gst_element_factory_make ("lamemp3enc","AudioEncode");
- audioconvert = gst_element_factory_make ("audioconvert","AudioConvert");
- audioresample = gst_element_factory_make ("audioresample","AudioResample");
- remux = gst_element_factory_make ("mpegtsmux","ReMux");
- /* we set the input filename to the source element */
- g_object_set (G_OBJECT (filesource), "location", argv[1], NULL);
- g_object_set (G_OBJECT (filesink), "location", argv[2], NULL);
- /* we add a message handler */
- bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
- gst_bus_add_watch (bus, bus_call, loop);
- gst_object_unref (bus);
- //gst-launch -m filesrc location=/home/richard/Gstreamer/BBC1_DVBS.ts ! decodebin ! audioconvert ! audioresample ! alsasink
- /* we add all elements into the pipeline */
- gst_bin_add_many (GST_BIN (pipeline),filesource, decode, audioq, audioconvert, audioresample ,lame,remux,filesink, NULL);
- gst_element_link (filesource, decode);
- gst_element_link (audioq,audioconvert);
- gst_element_link (audioconvert,audioresample);
- gst_element_link (audioresample,lame);
- gst_element_link (lame, remux);
- gst_element_link (remux, filesink);
- // Lets forget about video for now.
- //gst_element_link (videoq, filesink);
- g_signal_connect (decode, "pad-added", G_CALLBACK (on_pad_added), NULL);
- g_print ("Now playing: %s\n", argv[1]);
- gst_element_set_state (pipeline, GST_STATE_PLAYING);
- /* Iterate */
- g_print ("Running...\n");
- g_main_loop_run (loop);
- /* Out of the main loop, clean up nicely */
- g_print ("Returned, stopping playback\n");
- gst_element_set_state (pipeline, GST_STATE_NULL);
- g_print ("Deleting pipeline\n");
- gst_object_unref (GST_OBJECT (pipeline));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement