是否可以将HTTP URL用作DirectShow .NET中源过滤器的源位置?
我正在使用 DirectShow.Net 库创建一个过滤器图,该过滤器图通过使用 http 地址和 WM Asf Writer 来流式传输视频。然后,在网页上,我可以使用对象元素在 Windows Media Player 对象中呈现视频源。所以现在我很好奇是否可以使用某种类型的 FilterSource 读取该 http 地址。我看到有些人使用 AsyncReader 作为 IBaseFilter,然后将其转换为 IFileSourceFilter 并调用 load 方法并向其传递网络的 url。但我无法使用“http://localhost:8080”的 url 成功执行此操作。我猜这是因为它不是实际的“文件源”。我尝试在 IFileSourceFilter Load 方法中使用 AMMediaType ,其主要类型为 MediaType.URLStream ,子类型为 MediaSubType.Asf ,但仍然没有成功。如果有人能帮助我解决这个问题,我会象征性地吻他们,因为我已经为此工作了一段时间了。请哦请帮助我。
在我的代码中,我相应地创建了 FilterGraph 和 CaptureGraph。然后创建一个 AsyncReader 实例并将其转换为 IBaseFilter。接下来,我将其转换为 IFileSourceFilter 并调用 Load 方法,并向其传递“http://localhost:8080”url。然后将其添加到 FilterGraph。然后,我创建视频渲染过滤器并添加它,但是当我尝试调用 CaptureGraphBuilder2 对象的 RenderStream 方法时,它会抛出“未指定错误”异常。这是我的代码...
var fGraph = new FilterGraph() as IFilterGraph2;
var cGraph = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;
cGraph.SetFiltergraph(fGraph);
var tmp = new AsyncReader() as IBaseFilter;
// This is where I tried to load it with a media type.
//media = new AMMediaType { majorType = MediaType.URLStream, subType = MediaSubType.Asf };
//((IFileSourceFilter)tmp).Load(_streamingURL, media);
//DsUtils.FreeAMMediaType(media);
((IFileSourceFilter)tmp).Load(_streamingURL, null);
hr = fGraph.AddFilter(tmp, "SourceFilter");
DsError.ThrowExceptionForHR(hr);
var vRender = new VideoRenderer() as IBaseFilter;
var aRender = new AudioRender() as IBaseFilter;
hr = fGraph.AddFilter(vRender, "vRenderer");
DsError.ThrowExceptionForHR(hr);
hr = cGraph.RenderStream(null, MediaType.Video, tmp, null, vRender); // This is where it throws an "Unspecified Error".
DsError.ThrowExceptionForHR(hr);
hr = fGraph.AddFilter(aRender, "aRenderer");
DsError.ThrowExceptionForHR(hr);
hr = cGraph.RenderStream(null, MediaType.Audio, tmp, null, aRender);
DsError.ThrowExceptionForHR(hr);
var mcx = fGraph as IMediaControl;
hr = mcx.Run();
DsError.ThrowExceptionForHR(hr);
因此,如果您对我有任何建议,我将不胜感激。再次感谢您的所有帮助。
I'm using the DirectShow.Net Library to create a filter graph that streams video by using an http address and the WM Asf Writer. Then on the webpage I'm able to use the object element to render the video feed in a Windows Media Player object. So now I'm curious if it is possible to read from that http address with some type of FilterSource. I have seen that some people use the AsyncReader as an IBaseFilter, and then casting it as an IFileSourceFilter and calling the load method and passing it a url for their network. But I haven't been able to successfully do this with a url of "http://localhost:8080". I'm guessing this is because it's not an actual "file source". I have tried using a AMMediaType with a majorType of MediaType.URLStream and subType of MediaSubType.Asf in the IFileSourceFilter Load method, but still no luck. If someone could help me figure this out I would figuratively kiss them, seeing that I have been working on this for some time now. Please oh please help me.
In my code I'm creating the FilterGraph and CaptureGraph accordingly. Then creating an AsyncReader instance and casting it as an IBaseFilter. Next I cast it as an IFileSourceFilter and call the Load method passing it the "http://localhost:8080" url. Then add it to the FilterGraph. Then I create the video render filter and add it, but when I try to call the RenderStream method of the CaptureGraphBuilder2 object it throws an "Unspecified Error" exception. Here is what I have for code...
var fGraph = new FilterGraph() as IFilterGraph2;
var cGraph = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;
cGraph.SetFiltergraph(fGraph);
var tmp = new AsyncReader() as IBaseFilter;
// This is where I tried to load it with a media type.
//media = new AMMediaType { majorType = MediaType.URLStream, subType = MediaSubType.Asf };
//((IFileSourceFilter)tmp).Load(_streamingURL, media);
//DsUtils.FreeAMMediaType(media);
((IFileSourceFilter)tmp).Load(_streamingURL, null);
hr = fGraph.AddFilter(tmp, "SourceFilter");
DsError.ThrowExceptionForHR(hr);
var vRender = new VideoRenderer() as IBaseFilter;
var aRender = new AudioRender() as IBaseFilter;
hr = fGraph.AddFilter(vRender, "vRenderer");
DsError.ThrowExceptionForHR(hr);
hr = cGraph.RenderStream(null, MediaType.Video, tmp, null, vRender); // This is where it throws an "Unspecified Error".
DsError.ThrowExceptionForHR(hr);
hr = fGraph.AddFilter(aRender, "aRenderer");
DsError.ThrowExceptionForHR(hr);
hr = cGraph.RenderStream(null, MediaType.Audio, tmp, null, aRender);
DsError.ThrowExceptionForHR(hr);
var mcx = fGraph as IMediaControl;
hr = mcx.Run();
DsError.ThrowExceptionForHR(hr);
So if you have any advice for me I would greatly appreciate it. Thanks again for all your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过更多研究后,我找到了一些可以帮助我解决问题的信息。下面的图表添加了一个以 http url 作为源的源过滤器,然后将流渲染到视频渲染器过滤器和音频渲染过滤器。
tmpStreaming.asf 文件是使用通过网络接收器设置的 WM Asf Writer 过滤器创建的。如果您需要有关如何执行此操作的示例,请参阅 WindowsMediaLib .Net Framework 示例中的 AsfNet 项目。如果您遇到同样的问题,希望这会有所帮助。
After some more research I was able to find some information that helped me solve my issue. Here's the graph the adds a source filter with a http url as it's source and then renders the stream to a video renderer filter and an audio render filter.
The tmpStreaming.asf file is created using an WM Asf Writer filter set up with a network sink. In case you need an example of how to do this it's in the WindowsMediaLib .Net Framework samples as the AsfNet project. Hope this helps if you come across same issue.