如何在 Unity 中通过 gstreamer 从 c++ 正确接收视频发件人
我正在尝试使用VideoWriter(使用WSL的c++端)使用Opencv传输流,以使用VideoCapture(Unity端)将其传输到网络上的另一台电脑上。
受此示例启发: https://opencv94.rssing.com/chan-61447116 /article1201-live.html
我想将 OpenCV 中的视频从 C++ 发送到 Unity。
所以我在 C++ 端有这段代码:
cv::VideoWriter writer;
writer.open("appsrc ! videoconvert ! x264enc tune=zerolatency bitrate=500 speed-preset=superfast ! rtph264pay ! udpsink host=127.0.0.1 port=5000",
cv::CAP_GSTREAMER,
0,
5,
cv::Size (640, 480),
true);
当我运行 C++ 程序时,它可以工作,并且我可以使用编写器。
在统一方面,我有这个:
VideoCapture capture = new VideoCapture();
bool opened = capture.open("udpsrc port=5000 ! rtph264pay ! decodebin ! videoconvert ! appsink sync=false", Videoio.CAP_GSTREAMER);
但我总是在打开时出错,所以我无法连接到 c++。
我认为在这种情况下管道可能是错误的。
Unity 上真的可以接收来自 gstreamer 的视频吗?
注意:c++端是使用WSL ubuntu 18.06制作的
I am trying to transfer a stream using Opencv using VideoWriter (c++ side using WSL) to get it on another pc on the network using VideoCapture (Unity side).
Inspired by this example: https://opencv94.rssing.com/chan-61447116/article1201-live.html
I want to send a video from OpenCV from C++ to Unity.
So I have this code on the c++ side:
cv::VideoWriter writer;
writer.open("appsrc ! videoconvert ! x264enc tune=zerolatency bitrate=500 speed-preset=superfast ! rtph264pay ! udpsink host=127.0.0.1 port=5000",
cv::CAP_GSTREAMER,
0,
5,
cv::Size (640, 480),
true);
When I run the c++ program it works and I'm able to use the writer.
on the unity side I have this:
VideoCapture capture = new VideoCapture();
bool opened = capture.open("udpsrc port=5000 ! rtph264pay ! decodebin ! videoconvert ! appsink sync=false", Videoio.CAP_GSTREAMER);
But I always get false on opened so I cant' connect to the c++.
I think the pipelines can be wrong in this case.
Is it really possible to receive a video from gstreamer on Unity?
Note: the c++ side was made using WSL ubuntu 18.06
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
主要原因可能是您的发送方正在流式传输到端口 5000,而您的接收方尝试从端口 5200 读取数据。假设 unity 与 writer 是同一主机,您可以尝试:
发送方:
Unity 接收方:
[编辑:用户 @felipe 最终报告 2022 年 3 月 25 日 Unity 不支持 OpenCVForUnity]
Main cause may be that your sender is streaming to port 5000 while your receiver tries to read from port 5200. Assuming unity is the same host as writer, you would try:
Sender:
Unity receiver:
[EDIT: user @felipe finally reported that OpenCVForUnity is not supported on Unity today 25/mar/2022]