Hello!
I am developing video playback feature for the game engine. All I need is to get raw IYUV data from H264 video to make a texture. It works properly on most of platforms, but I have troubles with AMD graphics (image is corrupted).
HRESULT hr = S_OK; IMFSample *pSample = NULL; IMFMediaBuffer *pBuf = NULL; IMFMediaType *pVideoType = NULL; size_t cSamples = 0; DWORD streamIndex, flags; LONGLONG llTimeStamp; hr = m_pReader->ReadSample( MF_SOURCE_READER_FIRST_VIDEO_STREAM, // Stream index. 0, // Flags.&streamIndex, // Receives the actual stream index. &flags, // Receives status flags.&llTimeStamp, // Receives the time stamp.&pSample // Receives the sample or NULL. ); if (FAILED(hr)) { return false; } wprintf(L"Stream %d (%I64d)\n", streamIndex, llTimeStamp); if (flags & MF_SOURCE_READERF_ENDOFSTREAM) { wprintf(L"\tEnd of stream\n"); } if (flags & MF_SOURCE_READERF_NEWSTREAM) { wprintf(L"\tNew stream\n"); } if (flags & MF_SOURCE_READERF_NATIVEMEDIATYPECHANGED) { wprintf(L"\tNative type changed\n"); } if (flags & MF_SOURCE_READERF_CURRENTMEDIATYPECHANGED) { wprintf(L"\tCurrent type changed\n"); m_pReader->GetCurrentMediaType( (DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM,&pVideoType); // Get the frame dimensions and stride UINT32 w, h; MFGetAttributeSize(pVideoType, MF_MT_FRAME_SIZE, &w, &h); m_width = w; m_height = h; m_aspectRatio = (float)(w) / (float)(h); } if (flags & MF_SOURCE_READERF_STREAMTICK) { wprintf(L"\tStream tick\n"); } if (pSample) { ++cSamples; } else { return false; } if (FAILED(hr)) { wprintf(L"ProcessSamples FAILED, hr = 0x%x\n", hr); } else { wprintf(L"Processed %d samples\n", cSamples); } pSample->ConvertToContiguousBuffer(&pBuf); DWORD nCurrLen = 0; pBuf->GetCurrentLength(&nCurrLen); uint8_t *imgBuff; DWORD buffCurrLen = 0; DWORD buffMaxLen = 0; pBuf->Lock(&imgBuff, &buffMaxLen, &buffCurrLen); uint32_t luminanceStride = sizeof(uint8_t) * m_width; uint32_t chrominanceStride = sizeof(uint16_t) * (m_width / 2); // two buffers for luminance and chrominance. void *luminanceSource = imgBuff; void *chrominanceSource = offset_by_bytes(luminanceSource , lumStride * m_height);
Thanks in advance!