Save an MPEG2 compressed file from live stream

Sérgio Agostinho sergio.r.agostinho at
Mon Dec 22 04:36:00 PST 2014

Hi Paul, 

Can you try only invoking the gtk_main_quit() only after you enter and exit the EOS callback. 

In theory you only need to add the probe with the downstream event mask, unless there’s an actual reason to block data flow.
gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, (GstPadProbeCallback) cb_pad_event, data, NULL);

Where is it locking exactly? Is it when you send the message
g_message("EOS received at %s on %s.", gst_pad_get_name (pad), gst_element_get_name(gst_pad_get_parent_element(pad)));


When the you are in 
> On 22 Dec 2014, at 11:49, Paul Barber <paul.barber at> wrote:
> 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
> closed.
> 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), data);
> In this callback, keep a pointer to mux sink pad for later:
> static void cb_new_mux_pad (GstElement *element, GstPad *pad, GstAppData *data)
> {
>    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, GST_PAD_PROBE_TYPE_BLOCK|GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, (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), gst_element_get_name(gst_pad_get_parent_element(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.
> Cheers,
> Paul.
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel at

More information about the gstreamer-devel mailing list