Changing filesink location dynamically

Nicolas Dufresne nicolas at ndufresne.ca
Wed Feb 1 19:35:22 UTC 2017


Let's say it's more complicated then that.

Le mercredi 01 février 2017 à 08:30 -0800, ivan-perez a écrit :
> So, in one thread of my application in C, I try to stop the recording
> of the
> first video and then create a new one after 50 seconds. This is my
> code:
> 
>     /* pipeline started */
>     int i;
>     for (i = 2; i < 10; i++) {
>         sleep(10);
>         gst_element_send_event(mp4mux, gst_event_new_eos());
>         gst_element_set_state(fsink, GST_STATE_NULL);

You may get random wrong state error doing that. Since the flow will
continue. As you want to drop the flow during the following sleep, you
probably want to setup a valve, and set the "drop" property to true
during the wait.

>         
>         sleep(50);
>         g_object_set(fsink, "location", "video{$i}.mp4", NULL);/* of
> course
> with that `$i` properly set */
>         gst_element_set_state(fsink, GST_STATE_PLAYING);

I have doubt this is sufficient. The pads in the mp4mux ! fsink chain
will have the EOS flag set. You need to send a flush-start followed by
flush-stop event in order to reset those elements pads. Afterward, you
probably need to set a pad offset on the mp4mux pad(s) in order to
compensate for the time that has been running meanwhile (that I would
test first).

>     }
> 
> What do I get? Right after the EOS event is sent into the pipeline,
> the
> whole pipeline stops. I get a GST_MESSAGE_EOS in the main loop and it
> therefore stops. It's like that EOS is going up in the pipeline and
> being
> transmitted into all the elements, while what I want is that the EOS
> event
> is only sent to the 'mp4mux' and its children (i.e. the 'filesink'
> element).
> What's more, the video is not playable (VLC says its format is not
> correct).
> 
> What am I doing wrong? Thanks in advance!

For this last step, you have to drop the EOS event from being sent to
your pipeline. For that you'll have to create your own subclass of
GstBin and drop EOS event in handle_message() vfunc.

While at it, you'll need data probes to monitor the running-time for
when you'll start recording again. Instead of using sleeps, you could
look at the delays in running-time instead of using 10/50s sleeps.

Nicolas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20170201/59301201/attachment.sig>


More information about the gstreamer-devel mailing list