Gstreamer (-sharp) – 如何将我的自定义输出添加到splitmuxsink

huangapple go评论79阅读模式
英文:

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

问题

我想要为splitmuxsink添加自定义的输出,也就是说,我想要将来自IP摄像头的h264流按照10秒的间隔分割成块,但我希望它在我控制的缓冲区中进行。类似于下面的管道,但不是存储到文件,而是处理appsink事件"NewSample"并在我自己的缓冲区上工作,而不是存储到文件:

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

因此,我想在我的C#代码中复制它,并在默认的sink(filesink)之外使用我的自定义sink。在文档中指出:

默认情况下,它使用mp4mux和filesink,但可以通过'muxer'和'sink'属性进行更改。

以下是我的代码:

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;

上面的代码会产生一个警告:

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

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

考虑到appSink的Parent属性为空。我尝试了另一种方法:

appSink.Parent = tempBin; //或者 tempBin.Add(appSink)

但它产生了完全相同的错误。

我做错了什么?是否有另一种方法可以通过splitmuxsink自定义sink手动处理h264块到我的缓冲区中?

提前感谢您的回答。


<details>
<summary>英文:</summary>

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 &quot;NewSample&quot; 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=&quot;data_%02d.mp4&quot; 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 
[1] it is stated: &gt; By default, it uses mp4mux and filesink, but they can be changed via the &#39;muxer&#39; and &#39;sink&#39; properties. Here is my code: var rtph264depay = ElementFactory.Make(&quot;rtph264depay&quot;, &quot;rtph264depay&quot;); var h264parse = ElementFactory.Make(&quot;h264parse&quot;, &quot;h264parse&quot;); var splitmuxsink = ElementFactory.Make(&quot;splitmuxsink&quot;, &quot;splitmuxsink&quot;); splitmuxsink[&quot;max-size-time&quot;] = 10000000000; splitmuxsink[&quot;async-finalize&quot;] = false; var tempBin = splitmuxsink as Bin; var appSink = new AppSink(&quot;my_appsink&quot;); appSink.NewSample += AppSink_NewSample; appSink.EmitSignals = true; splitmuxsink[&quot;sink&quot;] = appSink; Code above gives a warn: WARN bin gstbin.c:1391:gst_bin_add_func:&lt;splitmuxsink&gt; Element &#39;my_appsink&#39; 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&#39;m doing wrong? Is there another approach to handle h264 chunks manually in my buffer via splitmuxsink custom sink? Thanks in advance. [1]: https://gstreamer.freedesktop.org/documentation/multifile/splitmuxsink.html?gi-language=c#properties </details> # 答案1 **得分**: 1 代码中存在一个问题,该问题未在上面给出,即我将appSink作为单独的元素添加到了管道中: ```python pipeline.Add(rtspsrc, rtph264depay ,h264parse, splitmuxsink, appSink);

这是错误的,因为appSink已经是splitmuxsink的一部分。所以一切似乎都可以这样工作:

pipeline.Add(rtspsrc, rtph264depay ,h264parse, splitmuxsink ); // 排除appSink
英文:

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

huangapple
  • 本文由 发表于 2023年7月10日 23:59:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76655460.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定