Sample Grabber Sink 未设置媒体类型 GUID

Sample Grabber Sink not setting media type GUID

我正在使用 Sample Grabber Sink reference page except that I'm processing an mp4 file to get both audio and video samples (my sample code) 中的示例代码。要处理回调中的样本,我需要知道哪些是音频,哪些是视频。问题是 REFGUID guidMajorMediaType 似乎永远不会设置。

下面是打印出每个回调样本属性的结果。较小的样本(小于 750 字节)是音频,较大的样本是视频。但是 guidMajorMediaType 总是空的。我可能需要在 IMFTopologyNode's 上设置一个额外的 属性 吗?我没有发现任何明显的东西。

Sample Grabber test console starting...
Guid = {00000000-0000-0000-0000-000000000000}
Sample: start = 0, duration = 426250, bytes = 682
Guid = {00000000-0000-0000-0000-000000000000}
Sample: start = 0, duration = 416666, bytes = 353280
Guid = {00000000-0000-0000-0000-000000000000}
Sample: start = 416666, duration = 416666, bytes = 353280
Guid = {00000000-0000-0000-0000-000000000000}
Sample: start = 426250, duration = 463750, bytes = 742
Guid = {00000000-0000-0000-0000-000000000000}
Sample: start = 833333, duration = 416666, bytes = 353280
Guid = {00000000-0000-0000-0000-000000000000}
Sample: start = 890000, duration = 465000, bytes = 744
Guid = {00000000-0000-0000-0000-000000000000}
Sample: start = 1250000, duration = 416666, bytes = 353280

更新: 看起来这可能是媒体基金会的一个错误(至少它是由两个独立方重新制作的)。

来自Using the Sample Grabber Sink

The Source Reader is an alternative to the Sample Grabber Sink and has a simpler progamming model.

您真的需要 Sample Grabber Sink 吗? Source Reader 是现代的做法。我会说 Sample Grabber Sink 已弃用。

如果是:

文档不明确:MFCreateSampleGrabberSinkActivate function

Remarks To create the sample grabber sink, call IMFActivate::ActivateObject on the pointer received in the ppIActivate parameter.

在他们的例子中,"Using the Sample Grabber Sink",他们没有。

也许在 IMFActivate 上的 ActivateObject 之后使用 IMFMediaSink,您将在 OnProcessSample 中获得正确的 guidMajorMediaType。这只是一种乐观的看待这个问题的方式。但是我对此有疑问。

这似乎是一个错误。我确认 OnProcessSample 为 REFGUID guidMajorMediaType 传递 GUID_NULL。它不应该,因为所有其他参数似乎都有效。

我只是认为 Sample Grabber Sink 已被弃用,您不应该使用它。

在存在其他解决方案且没有错误的情况下,解释为什么你真的需要使用样本采集器接收器。

对我来说 "Sample Grabber Sink" 只是一种 DirectShow 方法,现在,有了 MediaSession、Source Reader、tee 节点等等...它不再有任何兴趣。

编辑

I want the simplest way to get audio and video samples to a byte * buffer from either a file or device source and ideally be able to include at least one transform (such as the H264 encoder/decoder) in between.

The Source Reader 正是这样做的。是的,你没有 byte * 缓冲区,你有 IMFSample。但是使用 IMFSample,你可以获得 byte * buffer.

But the Source Reader documentation also states "The source reader does not send the data to a destination; it is up to the application to consume the data.

使用 Sample Grabber Sink,使用数据由您决定。同样的情况。

the source reader can read a video file, but it will not render the video to the screen.

Sample Grabber Sink 不会将视频渲染到屏幕上。同样的情况。

Also, the source reader does not manage a presentation clock, handle timing issues, or synchronize video with audio.

是的,这是有区别的,但我真的看不出有什么优势。参见 MF_SAMPLEGRABBERSINK_SAMPLE_TIME_OFFSET

Offset between the time stamp on each sample received by the sample grabber, and the time when the sample grabber presents the sample.

您知道要应用哪个偏移量吗:额外的工作。同样的情况。

The SampleGrabber returns the audio and video samples in the correct order with the correct timestamps

源 reader 还 returns 音频和视频样本以正确的顺序和正确的时间戳。同样的情况。

Won't that be extra work for the Source Reader case?

不,对我来说,两种情况下的额外工作都是一样的。

还有:

使用来源Reader: 来源 Reader -> 您的应用程序

使用样本采集器水槽: MediaSession(带有 Sample Grabber Sink)-> 您的应用程序

就性能(cpu/memory/thread 用法)而言,我很确定 Source Reader 比 MediaSession 更好。

但您可以选择 Sample Grabber Sink。我只建议您告诉 Microsoft REFGUID guidMajorMediaType 存在错误。