DirectX flickering video

Ok, so I wrote a custom VMR9 Allocator / Presenter that seems to work fine. However, when I try to copy video snippets from Allocator / Presenter surfaces to my application surfaces, the video appears to flicker. Sound playback is fine, so I'm pretty sure it's not a problem with the car getting stuck or anything. This is the code I have in my render loop.

g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 0, 0, 0), 1.0f, 0);

// render the scene
if (SUCCEEDED(g_pd3dDevice->BeginScene()))
{
//g_pd3dDevice->SetRenderTarget(0, g_pd3dSurface);

g_pd3dDevice->StretchRect(vmr9_ap->renderSurface, src, g_pd3dSurface, dest, D3DTEXF_NONE);

    // end the scene
    g_pd3dDevice->EndScene();
}

      

However, if I change it to this (by commenting out the clear buffer)

// g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 0, 0, 0), 1.0f, 0);

// render the scene
if (SUCCEEDED(g_pd3dDevice->BeginScene()))
{
//g_pd3dDevice->SetRenderTarget(0, g_pd3dSurface);

g_pd3dDevice->StretchRect(vmr9_ap->renderSurface, src, g_pd3dSurface, dest, D3DTEXF_NONE);

    // end the scene
    g_pd3dDevice->EndScene();
}

      

this flicker goes away. I'm worried this is somehow bad type / hacks and might cause more problems than it solves. Does anyone have experience in this area? Is there a better solution?

Thank!

+2


source to share


3 answers


If you intend to redraw the entire viewport in every frame, there is no reason to do clarity, and it can actually bring a lot of performance gains, so go! As for your flicker, it could be something else. Do you do you draw a WM_PAINT message? If so, you can also intercept the WM_ERASEBKGND message and just return 1 when you receive it. This prevents Windows from trying to erase the background and helped me get rid of some of the flickering in the past.

FYI: Ever done a cheat in Doom or Quake, and when you step outside the wall, things start to leave trails all over? This is because they do not clear the back buffer, as under normal circumstances the entire scene will be redrawn every time anyway. I say if it's good enough for an id, that's good enough for me! :)



Edit: Oh, and what more! I'm not sure if this is required or not, but I always make my own clear AFTER the call to BeginScene (). May also contribute to your flicker.

+3


source


TBH I think you are better off writing your own directshow render filter that copies the data directly to the texture and then draws a square across the screen with the texture. You will get much better performance. Writing a render is actually pretty straightforward. Especially when you appreciate that you don't have to expose it to the operating system, so most of the hard-hitting DirectShow hurdles don't need to bounce.



Edit: Look at the "Dump Filter", it's included in the Microsoft DirectShow helper code ...

0


source


I faced the same problem. In my case, the flickering reason was the call to StretchRect inside the BeginScene / EndScene pair.

0


source







All Articles