Hello! First of all id like to express my joy towards this library. libtheoraplayer was the best and free solution to my opengl project - it's fast, it works and very easy to use. However, i started to port my project to d3d and encountered slight difficulty with video playback. Frankly speaking, im total newbie in dx environment, so the question is: how do you pass texture data via frame loop?
frame=clip->getNextFrame();
if (frame)
{...
It would very nice to have full direct x example included into examples section.
Thank you for your attention!
Last edit: Gaius Julius Caesar 2013-08-14
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'd just change the way you're copying data to speed things up. You're doing a double for loop and copying each pixel individually which is very slow. What you should be doing is just do a memcpy() from the theoravideoframe to the texture buffer. If you chose the texture format correctly when creating a video clip, the library will already prepare the frames in the format you need. This is better because pixel conversion is best done in the theora worker threads in a hardware accelerated way then you doing it in the main thread unoptimised.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You won't be able to memcpy whole buffer, because DX textures have padded rows. However even using memcpy to copy whole rows will speed things significantly. Here is a snippet from my code hastly eddited to fit your naming convention:
Hello! First of all id like to express my joy towards this library. libtheoraplayer was the best and free solution to my opengl project - it's fast, it works and very easy to use. However, i started to port my project to d3d and encountered slight difficulty with video playback. Frankly speaking, im total newbie in dx environment, so the question is: how do you pass texture data via frame loop?
frame=clip->getNextFrame();
if (frame)
{...
It would very nice to have full direct x example included into examples section.
Thank you for your attention!
Last edit: Gaius Julius Caesar 2013-08-14
Hi Caesar,
check this thread for more info: https://sourceforge.net/p/libtheoraplayer/forum/general/thread/9d59e9a8/
Also, for a general texture writing tutorial, search google for "DirectX procedural textures".
here is some basic code from my engine that might help (dx9).
load/play clip and create dynamic texture...
//-----------------------------------------------------
//Theora
pTexture2DVideo[(DWORD)Texture2DVideo].pClip = gTheora_mgr->createVideoClip((char*)pTexture2DVideo[(DWORD)Texture2DVideo].FilePath.c_str(),
TH_RGB,
0,
bUsePowerOf2);
pTexture2DVideo[(DWORD)Texture2DVideo].pClip->play();
pTexture2DVideo[(DWORD)Texture2DVideo].w = pTexture2DVideo[(DWORD)Texture2DVideo].pClip->getWidth();
pTexture2DVideo[(DWORD)Texture2DVideo].h = pTexture2DVideo[(DWORD)Texture2DVideo].pClip->getHeight();
if(ContinuosPlay)
{
pTexture2DVideo[(DWORD)Texture2DVideo].pClip->setAutoRestart(true);
}
else
{
pTexture2DVideo[(DWORD)Texture2DVideo].pClip->setAutoRestart(false);
}
//create direct x texture
HRESULT hr;
hr = gD3D_Device->CreateTexture(pTexture2DVideo[(DWORD)Texture2DVideo].w,
pTexture2DVideo[(DWORD)Texture2DVideo].h,
1,
D3DUSAGE_DYNAMIC,
D3DFMT_A8R8G8B8,
D3DPOOL_DEFAULT,
&pTexture2DVideo[(DWORD)Texture2DVideo].pTexture,
NULL);
draw video to texture...
bool FrameIsActive = false;
TheoraVideoFrame *frame = pTexture2DVideo[Index].pClip->getNextFrame();
if (frame)
{
FrameIsActive = true;
// be sure to pop the frame from the frame queue when you're done
pTexture2DVideo[Index].pClip->popFrame();
}
Last edit: David 2014-08-13
Hi David,
from the looks of it, your code seems to be ok.
I'd just change the way you're copying data to speed things up. You're doing a double for loop and copying each pixel individually which is very slow. What you should be doing is just do a memcpy() from the theoravideoframe to the texture buffer. If you chose the texture format correctly when creating a video clip, the library will already prepare the frames in the format you need. This is better because pixel conversion is best done in the theora worker threads in a hardware accelerated way then you doing it in the main thread unoptimised.
You won't be able to memcpy whole buffer, because DX textures have padded rows. However even using memcpy to copy whole rows will speed things significantly. Here is a snippet from my code hastly eddited to fit your naming convention:
for(s32 row =0;row<last_frame->getHeight();row++){
memcpy( &bits[row*lTexPitch], &mb[rowlast_frame->getHeight()4 ], last_frame->getHeight()*4 );
}
Edit: this code will work with RGBA texture and video, you will have to ensure both buffer and dx tex are in same format
Last edit: Konstanty Kalicki 2014-08-20
oh yeah, forgot about that part of directx,buy yeah, a series of line memcpy's should be good.