从原始的未压缩字节的源显示实时视频在C#:WPF与赢形式 [英] Displaying live video from a raw uncompressed byte source in C#: WPF vs. Win forms

查看:196
本文介绍了从原始的未压缩字节的源显示实时视频在C#:WPF与赢形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个是通过一环形缓冲存储器被推作为原料,未压缩字节流的实时16位灰度视频流(每像素2字节,2 ^ 18个像素/帧,32帧/秒) 。 (这是从一个科学级摄像头的,通过一个PCI图像采集)。我希望做一些简单的处理上的视频(剪辑的动态范围,上色,加覆盖),然后显示它在一个窗口中,使用C#。

I have a live 16-bit gray-scale video stream that is pushed through a ring-buffer in memory as a raw, uncompressed byte stream (2 bytes per pixel, 2^18 pixels/frame, 32 frames/sec). (This is coming from a scientific grade camera, via a PCI frame-grabber). I would like to do some simple processing on the video (clip dynamic range, colorize, add overlays) and then show it in a window, using C#.

我有这使用Windows窗体和放大器的工作; GDI(对于每一帧,建立一个位图对象,写入原始32位RGB像素值的基础上我的后处理步骤,然后绘制使用Graphics类的帧)。但这种使用,我想用其他的东西CPU的显著块。所以我很感兴趣,使用WPF其GPU加速的视频显示。 (我也想开始使用WPF为它的数据绑定和放大器;布局功能)

I have this working using Windows Forms & GDI (for each frame, build a Bitmap object, write raw 32-bit RGB pixel values based on my post-processing steps, and then draw the frame using the Graphics class). But this uses a significant chunk of CPU that I'd like to use for other things. So I'm interested in using WPF for its GPU-accelerated video display. (I'd also like to start using WPF for its data binding & layout features.)

但我以前从未使用WPF,所以我不能确定如何接近这一点。大部分是我在网上找的有关视频和放大器; WPF涉及从磁盘读取的压缩视频文件(例如WMV),或使用了Windows已经理解的驱动器层从一个消费级相机获取的流。所以它似乎并不适用于此(但纠正我,如果我错了,这个)

But I've never used WPF before, so I'm unsure how to approach this. Most of what I find online about video & WPF involves reading a compressed video file from disk (e.g. WMV), or getting a stream from a consumer-grade camera using a driver layer that Windows already understands. So it doesn't seem to apply here (but correct me if I'm wrong about this).

所以,我的问题:


  • 有没有在内存中播放视频从原料,压缩字节(一个简单明了,基于WPF的方式,即使只是8位灰度或24位RGB)?

  • Is there a straighforward, WPF-based way to play video from raw, uncompressed bytes in memory (even if just as 8-bit grayscale, or 24-bit RGB)?

我将需要建立DirectShow过滤器(或其他的DirectShow /媒体基金会十岁上下的东西),以获得在GPU上的工作后处理?

Will I need to build DirectShow filters (or other DirectShow/Media Foundation-ish things) to get the post-processing working on the GPU?

此外,对于文档,示例,博客等是适合这些任务,任何一般的意见/建议将是赞赏。谢谢

Also, any general advice / suggestions for documentation, examples, blogs, etc that are appropriate to these tasks would be appreciated. Thanks!


后续:一些试验后,我发现 WriteableBitmap的是我的需要速度不够快,而且非常容易正确使用:只需拨打 WritePixels()和绑定到它的任何图片控件将自我更新。 InteropBitmap 内存映射的部分是相当快的,但我不得不写P /调用KERNEL32.DLL要使用它的.NET 3.5。

Follow-up: After some experimentation, I found WriteableBitmap to be fast enough for my needs, and extremely easy to use correctly: Simply call WritePixels() and any Image controls bound to it will update themselves. InteropBitmap with memory-mapped sections is noticeably faster, but I had to write p/invokes to kernel32.dll to use it on .NET 3.5.

推荐答案

我VideoRendererElement,虽然很有效,确实使用一些两轮牛车,使其工作。您可能还需要在.NET 3.5 SP1的WriteableBitmap的尝试。

My VideoRendererElement, though very efficient, does use some hackery to make it work. You may also want to experiment with the WriteableBitmap in .NET 3.5 SP1.

另外,InteropBitmap非常快。大大超过世行更有效,因为它没有双缓冲。尽管它可以受到视频撕裂

Also the InteropBitmap is very fast too. Much more efficient than the WB as it's not double buffered. Though it can be subject to video tearing.

这篇关于从原始的未压缩字节的源显示实时视频在C#:WPF与赢形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆