Save an MPEG2 compressed file from live stream

Paul Barber paul.barber at
Mon Dec 22 02:49:22 PST 2014

Thanks to Sérgio Agostinho I have a way to make sure the filesink file 
is closed before exiting the program, but I have trouble with the pad 
probe callback. (Apologies for the long post)

Sérgio Agostinho wrote:
Install the probe on the filesink sink pad. Send the eos on mpegpsmux sink
pad. Once you enter the callback of the probe, your file should be properly

The callback that I create is entered, but it never returns. Is this to 
be expected? I would be grateful for pointers. I have tried to distil 
down the code in the following:

I have a GTK window with g_signal_connect for "key_press_event" to end 
the program when Esc is pressed.
The mux sink pad is a request pad so I add a callback for pad-added on 
the mux before the pipeline is linked up:
g_signal_connect (data->mux, "pad-added", G_CALLBACK (cb_new_mux_pad), 

In this callback, keep a pointer to mux sink pad for later:
static void cb_new_mux_pad (GstElement *element, GstPad *pad, GstAppData 
     data->mux_pad = pad;

Set pipeline to play and then run gtk_main()

On exit, call gtk_main_quit() then add a callback on the filesink sink pad:
pad = gst_element_get_static_pad (data->filesink, "sink");
gst_pad_add_probe (pad, 
(GstPadProbeCallback) cb_pad_event, data, NULL);
gst_object_unref (pad);

Send an EOS into the mux sink pad we already have a reference to:
gst_pad_send_event (data->mux_pad, gst_event_new_eos ());

In the probe pad callback, just set some flag (data->EOS) that we can 
check for it later:
static GstPadProbeReturn cb_pad_event (GstPad *pad, GstPadProbeInfo 
*info, GstAppData *data)
   GstEvent *event;

   event = GST_PAD_PROBE_INFO_EVENT(info);

   if (event->type == GST_EVENT_EOS){
       g_message("EOS received at %s on %s.", gst_pad_get_name (pad), 
       data->EOS = TRUE;

   g_print("Return from pad callback\n");

The EOS is received, the problem is that this pad callback never 
returns, the program hangs.

More information about the gstreamer-devel mailing list