WPF 和 MJPEG 解码器帮助
这可能有点遥远,但这里是:我有一个 WPF 项目,需要流式传输 MJPEG 视频。 http://mjpeg.codeplex.com/ 上的库似乎是为数不多的 PnP 选项之一。它非常适合观看单个流。但是,当您尝试从一个 URI 切换到第二个 URI 时,最终结果是您从两个流中获取的帧交织到我的 WPF 页面上的同一图像对象中。两个流都是实时的,而不仅仅是前一个流的缓存。
无论我尝试什么,似乎第一个流都不会消失,并且解码器中的 stopstream 方法除了设置布尔值之外不会做任何该死的事情。
这是我如何使用该库的伪代码。我做错了什么吗?
button_click{
//Create new decoder instance
//Remove the previous image object from my WPF page
//Add a new image object to the WPF page
//Stop stream
//Set the event for a new frams
//Request the new stream with a new URI
}
我已经写信给解码器作者但没有回复。我希望使用过这个库的其他人能够阐明这一点。
This might be a little of a long shot, but here goes: I have a WPF project and need to stream MJPEG video. The library at http://mjpeg.codeplex.com/ seems to be one of the few PnP options. It works great for viewing a single stream. But, when you try to switch from one URI, to a second URI the end result is that you get frames from BOTH streams interlaced into the same image object on my WPF page. Both streams are live, not just a cache of the previous stream.
No matter what I try it seems like the first stream will not go away and the stopstream method in the decoder doesn't do a damn thing other than set a boolean value.
Here's is the pseudo code for how I'm using the library. Am I doing something wrong?
button_click{
//Create new decoder instance
//Remove the previous image object from my WPF page
//Add a new image object to the WPF page
//Stop stream
//Set the event for a new frams
//Request the new stream with a new URI
}
I have written to the decoder author with no response. I'm hoping that someone else that has used this library will be able to shed light on this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您调用
StopStream()
,稍等片刻,然后再次调用ParseStream
,它应该关闭第一个流,只显示第二个流。更好的选择是对您想要查看的每个流仅使用一个
MjpegDecoder
实例。当然,如果您不确定它是如何工作的,您可以下载代码,看看它是如何工作的。
If you call
StopStream()
, wait a bit, and then callParseStream
again, it should shut down the first stream, and only display the second one.The better alternative would be to only use a single instance of
MjpegDecoder
for each stream you would like to view.Of course, if you aren't sure how it works, you can just download the code, and see how it works.
尽管 MJPEGDecoder 库很棒,但不幸的是它在每一帧创建一个 WPF BitmapImage 和一个 System.Drawing.Bitmap。这太过分了。
我们需要的是一个字节数组,它与平台无关。然后由 UI 将其转换为实际的 Image 对象。
因此,我采用了 AForge.NET MJPEGStream.cs 对象并对它进行了一些调整,以便它发送一个字节数组位图的。
MJPEGStream.cs 非常强大并且速度非常快。我在生产中使用它来传输多达 30 个流。当 URI 更改时,它会自动停止并重新启动流,如果摄像头停止响应,它会自行重试...
请采纳此 要点,然后这样使用它:
当然,看看文档以受益其所有功能。
Although the MJPEGDecoder library is great, it unfortunately creates a WPF BitmapImage and a System.Drawing.Bitmap at each frame. This is way too much.
What we need is a byte array, which is platform independant. Then it is up to the UI to convert it to an actual Image object.
So I took the AForge.NET MJPEGStream.cs object and tweaked it a bit so it sends a byte array instead of a Bitmap.
MJPEGStream.cs is robust as hell and very fast. I am using it in production to stream up to 30 streams. It automatically stops and restarts the stream as the URI changes, retries by itself if the cam stops responding...
Please take this gist, then use it this way :
Of course, have look on the documentation to benefit all its features.