Sharov
Sharov

Reputation: 460

Gstreamer (-sharp)-- how to add my custom sink to splitmuxsink

I want to add my custom sink for splitmuxsink, namely I want to split h264 stream from ip camera into chunks by 10 seconds, but I want it in some controlled by me buffer. Smth like pipeline below but instead of file, I want to handle appsink event "NewSample" and work with 10 second buffer on my own, not to store to file:

gst-launch-1.0  rtspsrc buffer-mode=0  location=rtsp://camera?videocodec=h264 ! rtph264depay ! h264parse ! splitmuxsink location="data_%02d.mp4" max-size-time=10000000000 

So, I want to reproduce it in my C# code and use my custom sink instead of default one (filesink). In docs it is stated:

By default, it uses mp4mux and filesink, but they can be changed via the 'muxer' and 'sink' properties.

Here is my code:

    var rtph264depay = ElementFactory.Make("rtph264depay", "rtph264depay");
    var h264parse = ElementFactory.Make("h264parse", "h264parse");
    var splitmuxsink = ElementFactory.Make("splitmuxsink", "splitmuxsink");
    splitmuxsink["max-size-time"] = 10000000000;
    splitmuxsink["async-finalize"] = false;

  
    var tempBin = splitmuxsink as Bin;

    var appSink = new AppSink("my_appsink");
    appSink.NewSample += AppSink_NewSample;
    appSink.EmitSignals = true;

    splitmuxsink["sink"] = appSink; 

Code above gives a warn:

WARN bin gstbin.c:1391:gst_bin_add_func: Element 'my_appsink' already has parent

WARNING **: 18:57:08.508: Could not add sink elements - splitmuxsink will not work

Given that property Parent of appSink is null. Another approach I use:

 appSink.Parent = tempBin; //or tempBin.Add(appSink)

gives the very same error.

What I'm doing wrong? Is there another approach to handle h264 chunks manually in my buffer via splitmuxsink custom sink?

Thanks in advance.

Upvotes: 1

Views: 444

Answers (1)

Sharov
Sharov

Reputation: 460

There seems to be the issue with code, which is not presented above, namely I added appSink as separate element to pipeline:

pipeline.Add(rtspsrc, rtph264depay ,h264parse, splitmuxsink,  appSink);

which is wrong, because appSink is already part of splitmuxsink. So everything seems to be working with:

    pipeline.Add(rtspsrc, rtph264depay ,h264parse, splitmuxsink ); //exclude appsink

Upvotes: 1

Related Questions