Media (Intel® Video Processing Library, Intel Media SDK)
Access community support with transcoding, decoding, and encoding in applications using media tools like Intel® oneAPI Video Processing Library and Intel® Media SDK
Announcements
The Intel Media SDK project is no longer active. For continued support and access to new features, Intel Media SDK users are encouraged to read the transition guide on upgrading from Intel® Media SDK to Intel® Video Processing Library (VPL), and to move to VPL as soon as possible.
For more information, see the VPL website.

Using D3D11Texture2D to encode using oneVPL

Max_Gud
New Contributor I
1,273 Views

Is it possible to directly encode ID3D11Texture2D video frames and continue using the new internal memory model?

Could you help me with this?
Below is the code in which I am trying to perform texture encoding, but I don't understand how to get information for encoding based on input data.

 
 
 
mfxStatus Encode_tex(uint64_t ts, uint32_t tex_handle,
       uint64_t lock_key,
       uint64_t *next_key,
       mfxBitstream **pBS)
{
 
mfxHDL pDeviceHDL = nullptr, pResource = nullptr;
mfxHandleType pDeviceType = {};
mfxResourceType pResourceType = {};
 
mfxStatus sts = MFX_ERR_NONE;
*pBS = nullptr;
int nTaskIdx = GetFreeTaskIndex(t_TaskPool, mU16_TaskPool);
while (nTaskIdx == -1) {
 
mfxU8 *pTemp = mfx_Bitstream.Data;
memcpy(&mfx_Bitstream, &t_TaskPool[n_FirstSyncTask].mfxBS,
       sizeof(mfxBitstream));
 
t_TaskPool[n_FirstSyncTask].mfxBS.Data = pTemp;
t_TaskPool[n_FirstSyncTask].mfxBS.DataLength = 0;
t_TaskPool[n_FirstSyncTask].mfxBS.DataOffset = 0;
t_TaskPool[n_FirstSyncTask].syncp = nullptr;
nTaskIdx = n_FirstSyncTask;
n_FirstSyncTask = (n_FirstSyncTask + 1) % mU16_TaskPool;
*pBS = &mfx_Bitstream;
}
 
sts = MFXMemory_GetSurfaceForEncode(mfx_session, &mfx_FrameSurface);
 
mfxFrameSurface1 *pSurface = mfx_FrameSurface;
 
/*Preparing for Linux and DX12Resource support*/
pSurface->FrameInterface->GetDeviceHandle(pSurface, &pDeviceHDL,
  &pDeviceType);
pSurface->FrameInterface->GetNativeHandle(pSurface, &pResource,
  &pResourceType);
pSurface->FrameInterface->AddRef(pSurface);
 
if (pDeviceType == MFX_HANDLE_D3D11_DEVICE) {
 
if (pResourceType == MFX_RESOURCE_DX11_TEXTURE) {
 
 
 
}
} else if (pDeviceType == MFX_HANDLE_VA_DISPLAY) {
if (pResourceType == MFX_RESOURCE_VA_SURFACE) {
}
}
 
pSurface->Data.TimeStamp = ts;
 
sts = mfx_FrameSurface->FrameInterface->AddRef(pSurface);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
 
for (;;) {
// Encode a frame asynchronously (returns immediately)
sts = mfx_VideoEnc->EncodeFrameAsync(
&mfx_EncCtrl, pSurface, &t_TaskPool[nTaskIdx].mfxBS,
&t_TaskPool[nTaskIdx].syncp);
 
if (MFX_ERR_NONE < sts && !t_TaskPool[nTaskIdx].syncp) {
// Repeat the call if warning and no output
if (MFX_WRN_DEVICE_BUSY == sts)
MSDK_SLEEP(
1000); // Wait if device is busy, then repeat the same call
} else if (MFX_ERR_NONE < sts && t_TaskPool[nTaskIdx].syncp) {
sts = MFX_ERR_NONE; // Ignore warnings if output is available
break;
} else if (MFX_ERR_NOT_ENOUGH_BUFFER == sts) {
// Allocate more bitstream buffer memory here if needed...
break;
} else {
break;
}
}
 
sts = mfx_FrameSurface->FrameInterface->Synchronize(pSurface, 60000);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
sts = pSurface->FrameInterface->Release(pSurface);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
sts = mfx_FrameSurface->FrameInterface->Release(pSurface);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
 
return sts;
}
0 Kudos
7 Replies
Max_Gud
New Contributor I
1,272 Views

Previously, the old way of working with memory was used with the creation of the D3D11 device, the function presented below was used with it. But it doesn't work with the new method.

 

mfxStatus simple_copytex(mfxHDL pthis, mfxMemId mid, mfxU32 tex_handle,
mfxU64 lock_key, mfxU64 *next_key)
{
pthis; // To suppress warning for this unused parameter
 
CustomMemId *memId = (CustomMemId *)mid;
ID3D11Texture2D *pSurface = (ID3D11Texture2D *)memId->memId;
 
IDXGIKeyedMutex *km = 0;
ID3D11Texture2D *input_tex = 0;
HRESULT hr;
 
hr = g_pD3D11Device->OpenSharedResource((HANDLE)(uintptr_t)tex_handle,
IID_ID3D11Texture2D,
(void **)&input_tex);
if (FAILED(hr)) {
return MFX_ERR_INVALID_HANDLE;
}
 
hr = input_tex->QueryInterface(IID_IDXGIKeyedMutex, (void **)&km);
if (FAILED(hr)) {
input_tex->Release();
return MFX_ERR_INVALID_HANDLE;
}
 
input_tex->SetEvictionPriority(DXGI_RESOURCE_PRIORITY_MAXIMUM);
 
km->AcquireSync(lock_key, INFINITE);
 
D3D11_TEXTURE2D_DESC desc = {0};
input_tex->GetDesc(&desc);
D3D11_BOX SrcBox = {0, 0, 0, desc.Width, desc.Height, 1};
g_pD3D11Ctx->CopySubresourceRegion(pSurface, 0, 0, 0, 0, input_tex, 0,
   &SrcBox);
 
km->ReleaseSync(*next_key);
 
km->Release();
input_tex->Release();
 
return MFX_ERR_NONE;
}
0 Kudos
AthiraM_Intel
Moderator
1,228 Views

Hi,


Thank you for posting in Intel Communities.


Could you please share the following details:


  1. oneVPL version
  2. OS and Hardware details
  3. Sample reproducer code and exact commands you used to reproduce the issue from our side


Thank you


0 Kudos
Max_Gud
New Contributor I
1,215 Views

OneVPL 2.9

Windows 10 22H2, dGPU Intel Arc A380 and 12700K with UHD770.

I posted code examples in the first 2 posts

0 Kudos
AthiraM_Intel
Moderator
1,184 Views

Hi,


Thank you for the quick response.


To assist you better kindly attach the complete cpp file and input files along with the commands you used so that we can try to reproduce the same from our end.


Thank you.


0 Kudos
Max_Gud
New Contributor I
1,174 Views

The code is part of the plugin for OBS Studio, if it is possible to check the operability in such conditions, then a sample for verification can be downloaded from the link https://github.com/ma3uk/obs-qsv-onevpl/releases

 

You can find the full code at the link obs-qsv-onevpl/obs-qsvonevpl at dev · ma3uk/obs-qsv-onevpl (github.com) 

 

 

0 Kudos
AthiraM_Intel
Moderator
1,086 Views

Hi,


Thank you for the details. We are working on this internally. We will get back to you with an update.




Thanks


0 Kudos
Max_Gud
New Contributor I
527 Views

Hello, the ability to use Texture2D was added in version 2.10. But I ran into a problem using the new API.
Encoding using a texture works, but a few minutes after the recording starts, the encoding process is interrupted with the error MFX_ERR_LOCK_MEMORY, further attempts to start the encoding process immediately stop with the error MFX_ERR_LOCK_MEMORY.

0 Kudos
Reply