从获得MPEG-2节目/传输流的位图信息? [英] Get bitmap info from MPEG-2 Program / Transport Stream?

查看:220
本文介绍了从获得MPEG-2节目/传输流的位图信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了呈现在我的WPF应用程序一个DirectShow图形,我用一个样本采集写一个位图到内存中,并在code别处读它。这似乎是一个奇怪的解决方案,但似乎是得到一个WPF刷出它的唯一途径。

In order to render a DirectShow graph in my WPF application, I use a sample grabber to write a bitmap to memory, and read it elsewhere in code. This may seem as a wierd solution, but seems to be the only way to get a WPF brush out of it.

以下code给我,我需要对位图的信息:

The following code gives me the information I need about the bitmap:

AMMediaType mt = grabber.GetConnectedMediaType();
VideoInfoHeader header = (VideoInfoHeader)Marshal.PtrToStructure(mt.formatPtr, typeof VideoInfoHeader);
header.BmiHeader // ...

现在, header.BmiHeader 是类型的 BITMAPINFOHEADER 并提供诸如在宽度位图的高度即可。我需要这些信息来写位图到内存中。

Now, header.BmiHeader is of type BitmapInfoHeader and provides information such as the width and height of the bitmap. I need this information to write the bitmap to memory.

不过,这code似乎并不总是工作。例如,当样品采集过滤器连接到MPEG-2节目流针,。为什么我的code不能与某些媒体类型的工作,什么其他的方法在那里得到它的BITMAPINFOHEADER结构?

However, this code does not seem to work always. For example, when the sample grabber filter is connected to a MPEG-2 Program Stream pin, header will be null. Why does my code not work with certain media types, and what other ways are there to get it's BitmapInfoHeader structure?

请注意,即使我现在用的是 directshow.net 库,在C ++的答案也欢迎。

Please note that even though I am using the directshow.net library, answers in C++ are also welcome.

修改:这是我的曲线图的样子:

Edit: This is how my graph looks like:

*source* -> MPEG2-Demultiplexer -> SampleGrabber -> MS DTV-DVD Video Decoder -> Video Renderer

我不能放置去coder和渲染器之间的采集。关于解复用的视频脚:

I'm not allowed to place the grabber between the decoder and renderer. About the demux's video pin:

Major Type: Video

Sub Type: MPEG2_VIDEO
Format: MPEG2Video

我已经连接了样本采集后,它的输入引脚也具有上述的媒体类型。当我在我的应用程序中打开该图形文件,并使用 grabber.GetConnectedMediaType(); ,我也得到了相同的介质类型。但是, formatPtr 或( pbFormat 在C ++中)这种媒体类型是0。

After I have connected the sample grabber, it's input pin also has the above media type. When I open this graph file in my application and use grabber.GetConnectedMediaType();, I also get the same media type. However, the formatPtr or (pbFormat in C++) of this media type is 0.

推荐答案

如果你想有一个位图,您需要在您收到uncom pressed视频某处放置样品采集。当samplegrabber是MPEG-2节目流针的背后,你会收到一个MPEG2节目流。当然,有可能得到一个位图出来了,但你需要手动解复用和DECOM preSS。这两者都是要在DirectShow过滤器来执行任务。

If you want a bitmap, you need to place the sample grabber somewhere where you receive uncompressed video. When the samplegrabber is behind the MPEG-2 Program Stream pin, you will receive a mpeg2 program stream. Of course it it possible to get a bitmap out of that, but then you need to demultiplex and decompress manually. Both are task which you want to perform in the directshow filter.

但是,即使你收到uncom pressed视频,你可能仍然得到不同的格式。因德codeR您可以收到RGB24,YUY2,YV12,...查看MediaSubType什么你到底收到。如果你总是想收到RGB24,您可以使用包含在SDK中的RGBFilters / TransNull24过滤器。另请参见这个答案

But even if you receive uncompressed video, you might still get different formats. depending on the decoder you can receive RGB24, YUY2, YV12, ... Check the MediaSubType for what you exactly receive. If you always want to receive RGB24, you can use the RGBFilters/TransNull24 filter which is included in the sdk. See also this answer.

修改:另外也请注意,如果你不光要​​解决,而且本身的位图,你必须把去coder和渲染器之间的samplegrabber。如果MS德codeR不能正常工作,请尝试 ffdshow的

Edit: One additional note, if you not only want the resolution, but also the bitmap itself, you have to put the samplegrabber between the decoder and renderer. If the MS Decoder is not working, try ffdshow.

这篇关于从获得MPEG-2节目/传输流的位图信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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