Dynamic pipeline: record frames before mux/filesink is linked

Sylvain Garrigues sylgar at gmail.com
Sat Jan 21 18:16:16 UTC 2023


I’m trying to setup a pipeline which can record parts of the currently displayed stream on demand (I have a ctrl-c handler installed which start/stop the recording), INCLUDING 5 seconds before the signal is emitted. It works perfectly except the recording doesn’t start 5 seconds before the signal but 2/3 seconds after.

I have this pipeline:
filesrc location="longvideo.mp4" -> qtdemux -> tee -> queue -> h264parse -> … -> autovideosink
On the other branch of the tee i.e. the recording one I have: tee -> queue (named queue_recording)

I have set the recording queue to act like a 10 seconds ring buffer:
queue_recording.set_property_from_str("max-size-time", "10000000000");
queue_recording.set_property_from_str("max-size-buffers", "0");
queue_recording.set_property_from_str("max-size-bytes", "0");
queue_recording.set_property_from_str("leaky", "2");

(This is Rust code).

I have the pipeline playing and start watching the video.

When I hit ctrl-C and my program detects it, it add matroskamux -> filesink location="record.mkv" to the pipeline and link the video_0 sink pad of the matroskamux to queue_recording which was already there.

Since I hit ctrl-c more than 10 seconds after the video is playing, I expected the resulting record.mpv to display frames from 10 seconds before the crtl-c signal since the queue_recording has stored those frame on the sink side and there was no consumer on the src side before the matrosmamux was linked.

Can anybody explain me why I don’t get what I expect (the recording starting 10 seconds before the signal), and how you would solve my problem? 

I already manage, when hitting ctrl-c another time to stop the recording, to block the src_1 pad of the tee win a probe and send an EOS to the queue and unlink it, and when the pipeline bus gets the eos message from filesink (via message forward), I can remove the queue / matroskamux / filesink pair - just waiting for another signal to start another recording. I can share the source code if needed. 


More information about the gstreamer-devel mailing list