我有一个C#使用DirectShowNet 库播放视频的应用程序。当我在笔记本电脑上使用 Visual C# 调试我的应用程序时,视频会被拉伸以适合容器的尺寸,即视频的纵横比不会保持不变。当我在另一台计算机(相同的操作系统)上加载并运行我的应用程序时,aspect ratio会在屏幕上维护并创建黑条。
我不希望保持纵横比。我希望另一台计算机以与我的计算机显示视频相同的方式显示视频。
为什么您认为两台计算机的行为不同和/或我该如何解决?
当我第一次在另一台计算机上看到这种行为时,我更新了那台计算机DirectX无济于事。完全相同的视频正在两个系统上运行。
编辑#1:可能filter在另一台计算机上丢失了一些东西吗?我假设默认行为DirectShow不是维护Aspect Ratio.
编辑#2:当我尝试使用IVMRWindowlessControl( VMR-7& VMR-9) 时,从 VMR 到IVMRWindowlessControl持续的转换会产生一个NULL变量。结果,我尝试IVMRAspectRatioControl使用VMR-7它并在其中一台计算机上运行。尽管要求删除纵横比保留,另一台计算机仍处于信箱模式。
编辑#3:这是使用IVMRAspectRatioControlwith的代码VMR-7:
int hr = 0;
this.graphBuilder = (IGraphBuilder)new FilterGraph();
this.vmr = new VideoMixingRenderer();
this.graphBuilder.AddFilter((IBaseFilter)vmr, "VMR");
this.aspectRatioControl = (IVMRAspectRatioControl)this.vmr;
hr = this.aspectRatioControl.SetAspectRatioMode(VMRAspectRatioMode.None);
DsError.ThrowExceptionForHR(hr);
hr = this.graphBuilder.RenderFile(filename, null);
DsError.ThrowExceptionForHR(hr);
然后我IVideoWindow用来显示视频。
尝试使用 时IVMRWindowlessControl9,在第 4行之后this.windowlessControl评估为。当我尝试使用. 以下用途:NULLcastNULLVMR-7VMR-9
this.graphBuilder = (IGraphBuilder)new FilterGraph();
this.vmr = new VideoMixingRenderer9();
this.graphBuilder.AddFilter((IBaseFilter)vmr, "VMR");
this.filterConfig = (IVMRFilterConfig9)vmr;
hr = this.filterConfig.SetNumberOfStreams(1);
DsError.ThrowExceptionForHR(hr);
hr = this.filterConfig.SetRenderingMode(VMR9Mode.Windowless);
DsError.ThrowExceptionForHR(hr);
this.windowlessControl = (IVMRWindowlessControl9)this.vmr;
hr = this.windowlessControl.SetAspectRatioMode(VMR9AspectRatioMode.None);
DsError.ThrowExceptionForHR(hr);
hr = this.graphBuilder.RenderFile(filename, null);
DsError.ThrowExceptionForHR(hr);
我不完全确定它是如何工作的,但是第二台计算机是否有可能不VMR-7支持IVMRAspectRatioControl? 两台计算机上的操作系统是相同的,但是第一台计算机(可以工作)是我编写软件的地方(它有 IDE)。第二台计算机全新安装了Windows. 在第二台计算机上,我也DirectX如前所述进行了更新。