WPFMediaKit의 최신 버전을 사용하고 있습니다. 내가 뭘 하려는지 Samplegrabber 비디오 파일의 비디오 프레임을 캡처 할 수 있도록 샘플 비트 맵으로 가질 수있는 샘플 응용 프로그램을 작성하는 것입니다.Samplegrabber는 AVI/MPEG 파일에서는 정상적으로 작동하지만 WMV에서는 고르지 않습니다
지금까지 그래프를 구성하고 렌더링 할 때 다음 코드를 사용해 보았습니다. 그러나이 코드를 사용하여 .wmv 비디오 파일을 재생할 때 samplegrabber가 연결되면 불안정하거나 고르지 않게 재생됩니다. samplegrabber 필터를 추가하는 행을 주석 처리하면 정상적으로 작동합니다. 나는이 (가) .WMV 또는 ASF는 형식 비동기 또는 뭔가있는 말을 몇 가지를 읽고
private void SetupSampleGrabber(ISampleGrabber sampleGrabber)
{
FrameCount = 0;
var mediaType = new AMMediaType
{
majorType = MediaType.Video,
subType = MediaSubType.RGB24,
formatType = FormatType.VideoInfo
};
int hr = sampleGrabber.SetMediaType(mediaType);
DsUtils.FreeAMMediaType(mediaType);
DsError.ThrowExceptionForHR(hr);
hr = sampleGrabber.SetCallback(this, 0);
DsError.ThrowExceptionForHR(hr);
}
: 다시, 등 AVI/MPEG로 올바르게 samplegrabber와
protected virtual void OpenSource()
{
FrameCount = 0;
/* Make sure we clean up any remaining mess */
FreeResources();
if (m_sourceUri == null)
return;
string fileSource = m_sourceUri.OriginalString;
if (string.IsNullOrEmpty(fileSource))
return;
try
{
/* Creates the GraphBuilder COM object */
m_graph = new FilterGraphNoThread() as IGraphBuilder;
if (m_graph == null)
throw new Exception("Could not create a graph");
/* Add our prefered audio renderer */
InsertAudioRenderer(AudioRenderer);
var filterGraph = m_graph as IFilterGraph2;
if (filterGraph == null)
throw new Exception("Could not QueryInterface for the IFilterGraph2");
IBaseFilter renderer = CreateVideoMixingRenderer9(m_graph, 1);
IBaseFilter sourceFilter;
/* Have DirectShow find the correct source filter for the Uri */
var hr = filterGraph.AddSourceFilter(fileSource, fileSource, out sourceFilter);
DsError.ThrowExceptionForHR(hr);
/* We will want to enum all the pins on the source filter */
IEnumPins pinEnum;
hr = sourceFilter.EnumPins(out pinEnum);
DsError.ThrowExceptionForHR(hr);
IntPtr fetched = IntPtr.Zero;
IPin[] pins = { null };
/* Counter for how many pins successfully rendered */
int pinsRendered = 0;
m_sampleGrabber = (ISampleGrabber)new SampleGrabber();
SetupSampleGrabber(m_sampleGrabber);
hr = m_graph.AddFilter(m_sampleGrabber as IBaseFilter, "SampleGrabber");
DsError.ThrowExceptionForHR(hr);
/* Loop over each pin of the source filter */
while (pinEnum.Next(pins.Length, pins, fetched) == 0)
{
if (filterGraph.RenderEx(pins[0],
AMRenderExFlags.RenderToExistingRenderers,
IntPtr.Zero) >= 0)
pinsRendered++;
Marshal.ReleaseComObject(pins[0]);
}
Marshal.ReleaseComObject(pinEnum);
Marshal.ReleaseComObject(sourceFilter);
if (pinsRendered == 0)
throw new Exception("Could not render any streams from the source Uri");
/* Configure the graph in the base class */
SetupFilterGraph(m_graph);
HasVideo = true;
/* Sets the NaturalVideoWidth/Height */
//SetNativePixelSizes(renderer);
}
catch (Exception ex)
{
/* This exection will happen usually if the media does
* not exist or could not open due to not having the
* proper filters installed */
FreeResources();
/* Fire our failed event */
InvokeMediaFailed(new MediaFailedEventArgs(ex.Message, ex));
}
InvokeMediaOpened();
}
및 작동 . 디코딩 할 WMAsfReader를 삽입하려고 시도했지만 일단 VMR9로 이동하면 동일한 동작이 발생합니다. 또한 IBaseFilter renderer = CreateVideoMixingRenderer9(m_graph, 1);
라인을 주석 처리하고 filterGraph.Render(pins[0]);
을 가지고있을 때 제대로 작동하도록했습니다. 유일한 단점은 이제 내 컨트롤 대신 자체 Activemovie widow에서 렌더링되지만, samplegrabber는 올바르게 건너 뛰고 건너 뛰지 않고 렌더링된다는 것입니다. . 그래서 버그가 VMR9/samplegrabbing 어딘가에 있다고 생각합니다.
어떤 도움이 필요합니까? 나는 이것에 초보적이다.
감사합니다. 대신 WPFMediakit에서 VMR7을 사용할 수 있는지 또는 VMR9가 구현되는 방식과 유사한 코드를 기반으로 자체적으로 롤업 할 수 있는지 조사 할 것입니다. 이 문제점으로 발견 한 점은 다른 컴퓨터에서 다른 결과를 얻는다는 것입니다. 즉, 어젯밤에이 집을 가져 왔고 WMV는 고르지 않게 재생했습니다. 그래프가 똑같이 나오는 지 아니면 각각 그래프가 나오는지를 graphedit으로 조사하려고합니다. 또는 하드웨어 가속 기능을 사용할 수도 있습니다. –