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

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

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

问题

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

  1. 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'属性进行更改。

以下是我的代码:

  1. var rtph264depay = ElementFactory.Make("rtph264depay", "rtph264depay");
  2. var h264parse = ElementFactory.Make("h264parse", "h264parse");
  3. var splitmuxsink = ElementFactory.Make("splitmuxsink", "splitmuxsink");
  4. splitmuxsink["max-size-time"] = 10000000000;
  5. splitmuxsink["async-finalize"] = false;
  6. var tempBin = splitmuxsink as Bin;
  7. var appSink = new AppSink("my_appsink");
  8. appSink.NewSample += AppSink_NewSample;
  9. appSink.EmitSignals = true;
  10. splitmuxsink["sink"] = appSink;

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

  1. WARN bin gstbin.c:1391:gst_bin_add_func:<splitmuxsink> Element 'my_appsink' already has parent
  2. WARNING **: 18:57:08.508: Could not add sink elements - splitmuxsink will not work

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

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

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

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

提前感谢您的回答。

  1. <details>
  2. <summary>英文:</summary>
  3. 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:
  4. 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
  5. 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:
  6. &gt; By default, it uses mp4mux and filesink, but they can be changed via the &#39;muxer&#39; and &#39;sink&#39; properties.
  7. Here is my code:
  8. var rtph264depay = ElementFactory.Make(&quot;rtph264depay&quot;, &quot;rtph264depay&quot;);
  9. var h264parse = ElementFactory.Make(&quot;h264parse&quot;, &quot;h264parse&quot;);
  10. var splitmuxsink = ElementFactory.Make(&quot;splitmuxsink&quot;, &quot;splitmuxsink&quot;);
  11. splitmuxsink[&quot;max-size-time&quot;] = 10000000000;
  12. splitmuxsink[&quot;async-finalize&quot;] = false;
  13. var tempBin = splitmuxsink as Bin;
  14. var appSink = new AppSink(&quot;my_appsink&quot;);
  15. appSink.NewSample += AppSink_NewSample;
  16. appSink.EmitSignals = true;
  17. splitmuxsink[&quot;sink&quot;] = appSink;
  18. Code above gives a warn:
  19. WARN bin gstbin.c:1391:gst_bin_add_func:&lt;splitmuxsink&gt; Element &#39;my_appsink&#39; already has parent
  20. WARNING **: 18:57:08.508: Could not add sink elements - splitmuxsink will not work
  21. Given that property Parent of appSink is null. Another approach I use:
  22. appSink.Parent = tempBin; //or tempBin.Add(appSink)
  23. gives the very same error.
  24. What I&#39;m doing wrong? Is there another approach to handle h264 chunks manually in my buffer via splitmuxsink custom sink?
  25. Thanks in advance.
  26. [1]: https://gstreamer.freedesktop.org/documentation/multifile/splitmuxsink.html?gi-language=c#properties
  27. </details>
  28. # 答案1
  29. **得分**: 1
  30. 代码中存在一个问题,该问题未在上面给出,即我将appSink作为单独的元素添加到了管道中:
  31. ```python
  32. pipeline.Add(rtspsrc, rtph264depay ,h264parse, splitmuxsink, appSink);

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

  1. 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:

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

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

  1. 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:

确定