简体   繁体   English

Directshow:如何更改视频的大小和帧速率?

[英]Directshow : How to change Size and frame rate of video?

(at first, sorry for my English) (起初,对不起我的英语)

I have a DirectShow filter graph like this:我有一个这样的 DirectShow 过滤器图:

在此处输入图像描述

and this is my code:这是我的代码:

   HRESULT BuildGraph(IGraphBuilder *pGraph, LPCOLESTR srcFile1)
  {
   HRESULT hr = S_OK;

//graph builder
CComPtr<ICaptureGraphBuilder2> pBuilder;
hr = pBuilder.CoCreateInstance(CLSID_CaptureGraphBuilder2);
CHECK_HR(hr, L"Can't create Capture Graph Builder");
hr = pBuilder->SetFiltergraph(pGraph);
CHECK_HR(hr, L"Can't SetFiltergraph");

//add File Source (Async.)
CComPtr<IBaseFilter> pFileSourceAsync;
hr = pFileSourceAsync.CoCreateInstance(CLSID_GSN_FileSourceAsync);
CHECK_HR(hr, L"Can't create File Source (Async.)");
hr = pGraph->AddFilter(pFileSourceAsync, L"File Source (Async.)");
CHECK_HR(hr, L"Can't add File Source (Async.) to graph");

//set source filename
CComQIPtr<IFileSourceFilter, &IID_IFileSourceFilter> pFileSourceAsync_src(pFileSourceAsync);
if (!pFileSourceAsync_src)
    CHECK_HR(E_NOINTERFACE, L"Can't get IFileSourceFilter");
hr = pFileSourceAsync_src->Load(srcFile1, NULL);
CHECK_HR(hr, L"Can't load file");

//add LAV Splitter
CComPtr<IBaseFilter> pLAVSplitter;
hr = pLAVSplitter.CoCreateInstance(CLSID_GSN_LAVSplitter);
CHECK_HR(hr, L"Can't create LAV Splitter");
hr = pGraph->AddFilter(pLAVSplitter, L"LAV Splitter");
CHECK_HR(hr, L"Can't add LAV Splitter to graph");

//add LAV Video Decoder
CComPtr<IBaseFilter> pLAVVideoDecoder;
hr = pLAVVideoDecoder.CoCreateInstance(CLSID_GSN_LAVVideoDecoder);
CHECK_HR(hr, L"Can't create LAV Video Decoder");
hr = pGraph->AddFilter(pLAVVideoDecoder, L"LAV Video Decoder");
CHECK_HR(hr, L"Can't add LAV Video Decoder to graph");

//add Infinite Pin Tee Filter
CComPtr<IBaseFilter> pInfinitePinTeeFilter;
hr = pInfinitePinTeeFilter.CoCreateInstance(CLSID_GSN_InfinitePinTeeFilter);
CHECK_HR(hr, L"Can't create Infinite Pin Tee Filter");
hr = pGraph->AddFilter(pInfinitePinTeeFilter, L"Infinite Pin Tee Filter");
CHECK_HR(hr, L"Can't add Infinite Pin Tee Filter to graph");

//add AVI Decompressor
CComPtr<IBaseFilter> pAVIDecompressor;
hr = pAVIDecompressor.CoCreateInstance(CLSID_GSN_AVIDecompressor);
CHECK_HR(hr, L"Can't create AVI Decompressor");
hr = pGraph->AddFilter(pAVIDecompressor, L"AVI Decompressor");
CHECK_HR(hr, L"Can't add AVI Decompressor to graph");

//add Color Space Converter
CComPtr<IBaseFilter> pColorSpaceConverter;
hr = pColorSpaceConverter.CoCreateInstance(CLSID_GSN_ColorSpaceConverter);
CHECK_HR(hr, L"Can't create Color Space Converter");
hr = pGraph->AddFilter(pColorSpaceConverter, L"Color Space Converter");
CHECK_HR(hr, L"Can't add Color Space Converter to graph");

//add Decklink Video Render
CComPtr<IBaseFilter> pDecklinkVideoRender;
hr = pDecklinkVideoRender.CoCreateInstance(CLSID_GSN_DecklinkVideoRender);
CHECK_HR(hr, L"Can't create Decklink Video Render");
hr = pGraph->AddFilter(pDecklinkVideoRender, L"Decklink Video Render");
CHECK_HR(hr, L"Can't add Decklink Video Render to graph");

//add Enhanced Video Renderer
CComPtr<IBaseFilter> pEnhancedVideoRenderer;
hr = pEnhancedVideoRenderer.CoCreateInstance(CLSID_GSN_EnhancedVideoRenderer);
CHECK_HR(hr, L"Can't create Enhanced Video Renderer");
hr = pGraph->AddFilter(pEnhancedVideoRenderer, L"Enhanced Video Renderer");
CHECK_HR(hr, L"Can't add Enhanced Video Renderer to graph");

//connect File Source (Async.) and LAV Splitter
hr = pGraph->ConnectDirect(GetPin(pFileSourceAsync, L"Output"), GetPin(pLAVSplitter, L"Input"), NULL);
CHECK_HR(hr, L"Can't connect File Source (Async.) and LAV Splitter");

//connect LAV Splitter and LAV Video Decoder
hr = pGraph->ConnectDirect(GetPin(pLAVSplitter, L"Video"), GetPin(pLAVVideoDecoder, L"Input"), NULL);
CHECK_HR(hr, L"Can't connect LAV Splitter and LAV Video Decoder");

//connect LAV Video Decoder and Infinite Pin Tee Filter
hr = pGraph->ConnectDirect(GetPin(pLAVVideoDecoder, L"Output"), GetPin(pInfinitePinTeeFilter, L"Input"), NULL);
CHECK_HR(hr, L"Can't connect LAV Video Decoder and Infinite Pin Tee Filter");

//connect Infinite Pin Tee Filter and AVI Decompressor
hr = pGraph->ConnectDirect(GetPin(pInfinitePinTeeFilter, L"Output2"), GetPin(pAVIDecompressor, L"XForm In"), NULL);
CHECK_HR(hr, L"Can't connect Infinite Pin Tee Filter and AVI Decompressor");

//connect Infinite Pin Tee Filter and Decklink Video Render
hr = pGraph->ConnectDirect(GetPin(pInfinitePinTeeFilter, L"Output4"), GetPin(pDecklinkVideoRender, L"In"), NULL);
CHECK_HR(hr, L"Can't connect Infinite Pin Tee Filter and Decklink Video Render");

//connect AVI Decompressor and Color Space Converter
hr = pGraph->ConnectDirect(GetPin(pAVIDecompressor, L"XForm Out"), GetPin(pColorSpaceConverter, L"Input"), NULL);
CHECK_HR(hr, L"Can't connect AVI Decompressor and Color Space Converter");

//connect Color Space Converter and Enhanced Video Renderer
hr = pGraph->ConnectDirect(GetPin(pColorSpaceConverter, L"XForm Out"), GetPin(pEnhancedVideoRenderer, L"EVR Input0"), NULL);
CHECK_HR(hr, L"Can't connect Color Space Converter and Enhanced Video Renderer");

return S_OK;
}

It works perfectly, But if the source is 1080p50 I want to show it as PAL (720x576 25fps) in EVR and 1080i50 in Deklink renderer.它完美运行,但如果源是 1080p50,我想在 EVR 中将其显示为 PAL (720x576 25fps),在 Deklink 渲染器中显示为 1080i50。

my question: How to change Size and frame rate of the source?我的问题:如何更改源的大小和帧速率? (what filter and Interfaces can I use...) (我可以使用什么过滤器和接口......)

Note: I googled and found many posts about changing video framerate/size while capturing with IAMStreamConfig interface, but my sources are files and the file source filters have not IAMStreamConfig interface.注意:我在谷歌上搜索并发现了许多关于在使用IAMStreamConfig接口捕获时更改视频帧速率/大小的帖子,但我的源是文件,并且文件源过滤器没有IAMStreamConfig接口。

The video resizer dsp can be used to scale down the video. 视频调整器 dsp可用于缩小视频。 But it is an DMO/MFT and not a native DirectShow filter.但它是 DMO/MFT,而不是原生 DirectShow 过滤器。 But why do you want to scale it down before the EVR?但是为什么要在 EVR 之前缩小它呢? With IMFVideoPositionMapper::MapOutputCoordinateToInputStream you can scale down the display directly.使用IMFVideoPositionMapper::MapOutputCoordinateToInputStream您可以直接缩小显示。

With the Frame Rate Converter DSP you can scale down the frame rate.使用帧速率转换器 DSP ,您可以缩小帧速率。 This is also an DMO/MFT.这也是 DMO/MFT。

Why do you want to send the Video as interlaced to the Decklink?为什么要将视频隔行扫描发送到 Decklink? I don't know any filter/dmo/mft that can do this.我不知道有任何过滤器/dmo/mft 可以做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM