Skip to content

Commit

Permalink
Fix for error when reading video files where video stream is not at i…
Browse files Browse the repository at this point in the history
…ndex 0
  • Loading branch information
sskodje committed May 23, 2024
1 parent e750c2e commit 77883e4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions ScreenRecorderLibNative/SourceReaderBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,14 @@ HRESULT SourceReaderBase::OnReadSample(HRESULT status, DWORD streamIndex, DWORD
if (m_MediaTransform) {
//Run media transform to convert sample to MFVideoFormat_ARGB32
MFT_OUTPUT_STREAM_INFO info{};
hr = m_MediaTransform->GetOutputStreamInfo(streamIndex, &info);
hr = m_MediaTransform->GetOutputStreamInfo(0, &info);
if (FAILED(hr)) {
LOG_ERROR(L"GetOutputStreamInfo failed: hr = 0x%08x", hr);
}
bool transformProvidesSamples = info.dwFlags & (MFT_OUTPUT_STREAM_PROVIDES_SAMPLES | MFT_OUTPUT_STREAM_CAN_PROVIDE_SAMPLES);
MFT_OUTPUT_DATA_BUFFER outputDataBuffer;
RtlZeroMemory(&outputDataBuffer, sizeof(outputDataBuffer));
outputDataBuffer.dwStreamID = streamIndex;
outputDataBuffer.dwStreamID = 0;
if (!transformProvidesSamples) {
IMFMediaBuffer *transformBuffer = nullptr;
//create a buffer for the output sample
Expand All @@ -396,7 +396,7 @@ HRESULT SourceReaderBase::OnReadSample(HRESULT status, DWORD streamIndex, DWORD
outputDataBuffer.pSample = transformSample;
SafeRelease(&transformBuffer);
}
hr = m_MediaTransform->ProcessInput(streamIndex, sample, 0);
hr = m_MediaTransform->ProcessInput(0, sample, 0);
if (FAILED(hr)) {
LOG_ERROR(L"ProcessInput failed: hr = 0x%08x", hr);
}
Expand Down
8 changes: 4 additions & 4 deletions ScreenRecorderLibNative/VideoReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,21 @@ HRESULT VideoReader::InitializeSourceReader(
LogMediaType(pInputMediaType);
if (ppOutputMediaType) {
SafeRelease(&pMediaTransform);
hr = CreateIMFTransform(streamIndex, pInputMediaType, &pMediaTransform, &pOutputMediaType);
hr = CreateIMFTransform(0, pInputMediaType, &pMediaTransform, &pOutputMediaType);
if (FAILED(hr)) {
LOG_INFO("Failed to create a valid media output type for video reader, attempting to create an intermediate transform");
CComPtr<IMFActivate> pConverterActivate = NULL;
CONTINUE_ON_BAD_HR(hr = FindVideoDecoder(&inputSubType, nullptr, false, true, true, &pConverterActivate));
CComPtr<IMFTransform> pConverter = NULL;
CONTINUE_ON_BAD_HR(pConverterActivate->ActivateObject(IID_PPV_ARGS(&pConverter)));
CONTINUE_ON_BAD_HR(pConverter->SetInputType(streamIndex, pInputMediaType, 0));
CONTINUE_ON_BAD_HR(pConverter->SetInputType(0, pInputMediaType, 0));
GUID guidMinor;
GUID guidMajor;
for (int i = 0;; i++)
{
SafeRelease(&pMediaTransform);
IMFMediaType *mediaType;
hr = pConverter->GetOutputAvailableType(streamIndex, i, &mediaType);
hr = pConverter->GetOutputAvailableType(0, i, &mediaType);
if (FAILED(hr))
{
break;
Expand All @@ -160,7 +160,7 @@ HRESULT VideoReader::InitializeSourceReader(
CONTINUE_ON_BAD_HR(hr = pIntermediateMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
CONTINUE_ON_BAD_HR(hr = pIntermediateMediaType->SetGUID(MF_MT_SUBTYPE, guidMinor));
CONTINUE_ON_BAD_HR(hr = pSourceReader->SetCurrentMediaType(streamIndex, NULL, pIntermediateMediaType));
CONTINUE_ON_BAD_HR(hr = CreateIMFTransform(streamIndex, pIntermediateMediaType, &pMediaTransform, &pOutputMediaType));
CONTINUE_ON_BAD_HR(hr = CreateIMFTransform(0, pIntermediateMediaType, &pMediaTransform, &pOutputMediaType));
LOG_DEBUG("Successfully created video reader intermediate media transform:");
LogMediaType(pIntermediateMediaType);
break;
Expand Down

0 comments on commit 77883e4

Please sign in to comment.