Conditional video writing in gstreamer


I’m learning GStreamer and I have some questions regarding it. I’m planning to write an application which captures rtsp video via GStreamer and writes a video to a file. The video shouldn’t be recorded all the time but according to the certain conditions (according to a timetable, an external command, etc.). How can I implement it?

I’m writing in Python because it’s the language I’m familiar with. I know it’s possible to define a pipeline with appsink (something similar to this example). I can retrieve a raw RGB frame by defining a corresponding pipeline and then write a video via such libraries as OpenCV or PyAV. However, I as far as my knowledge goes, those libraries rely heavily on ffmpeg to write video files and I’m not sure it’s a good idea to mix those two media frameworks in a single app. Are there any ways to do it in more “gstreamer native” way?

You could use GStreamer for this as well. Pipelines are not static but can be changed at runtime, so you could e.g. add/remove a branch to/from a tee element somewhere which would encode and write to a file whenever needed.

There’s of course also no problem with using an appsink and then using some non-GStremer code to write the files, but that sounds like it would just complicate the whole application if there’s no real reason to do it externally.