Connexion rapide:  

Forum: VirtualDJ Plugins

Sujet Video Effect Examples? - Page: 1

Cette partie de ce topic est ancien et peut contenir des informations obselètes ou incorrectes

SBDJPRO Infinity Member since 2006
Hi all,

I've been looking at writing some plugins for VDJ to implement a few things I would like. I've done a lot of dev work, but am not experienced with D3D at all!

I was wondering if anyone had any video effect source code using verticies they would be willing to share, so I can have a look through.

Basically - as a test I've written a standalone D3D app that implements a slideshow of pictures but scales them keeping the aspect ratio correct. I've taught myself a fair bit in doing this, it's actually a challenge I've enjoyed. The D3D interface has allowed me to explore options that allow you to easily scale and transform images quickly by implementing them as textures. The manager of one of my venues has asked if it's possible to do this when music videos aren't playing - obviously it is, but the current SlideShow plugin isn't really useable.

The standalone app works fine, and I've ported the code into a VDJ plugin. I'm only having one real problem at the moment - as soon as I present my scene it gets drawn over by a black box.

This has only happened when I render a scene using textures mapped, not when working with surfaces. I know it's something to do with my handling of the verticies, as after my plugin is activated it seems to have an impact on the verticies for other plugins. This is why I wondered if anyone had anything I could see, that dealt with verticies ;)

Thanks in advance,

Scott

 

Posté Mon 03 Sep 07 @ 6:26 am
There are plugin source codes, on the site, under plugins, just in case you hadn't seen them.
 

Posté Tue 04 Sep 07 @ 2:45 pm
SBDJPRO Infinity Member since 2006
Unfortunately they are only available for Experienced users, and they also all seem to be audio effects :(

Probably going to have to not use music videos, and just run a seperate application on the TV output instead to do proper slideshow and video clips.

Hopefully I'll be able to get something sorted soon though - I've started writing an SMS plugin, it would be nice to have a better understanding of the video, and also if I can do anything in the configuration area of the effects panel to allow easier message handling. Would be much nicer than a seperate pop-up window :)
 

Posté Tue 04 Sep 07 @ 5:35 pm
SBDJ wrote :
Unfortunately they are only available for Experienced users, and they also all seem to be audio effects :(


yeah same issue here, i'd like to write some plugin's as well and ran into status limitation.

i got VB6, C++ skills and alot of freetime ;-)

But it seems like the http://www.virtualdj.com/developers/ page is under construction, and it's looking like they dropping the level down :) YaY
 

Posté Wed 05 Sep 07 @ 10:34 pm
SBDJPRO Infinity Member since 2006
I'm making a bit of progress;

I can draw textures without them being overwritten. I've had to do the rendering myself though - my understanding was that OnDraw S_FALSE would make VDJ Render the modified texture. However this doesn't happen, so obviously I'm missing a step with what to do to enable VDJ to render it automatically. Setting it to S_OK and issuing the DrawPrimitiveUP myself successfully renders the scene.

101010101 have you managed to do any video coding yet? Feel free to give me a shout if you want to discuss anything or let me in on anything you've found ;) Video info seems to be rather hard to come by unfortunately :(

Still need to work out redrawing too - redrawing the texture on every OnDraw call will result in huge CPU utilisation - I only really need to redraw dirty areas. Further investigation required!!

Unfortunately I've never used D3D before, but I'm learning. Slowly ;)

Hence my initial request... :p
 

Posté Wed 05 Sep 07 @ 11:26 pm
DJ Cel is awesome at this kind of thing, but hard pressed for time at the moment as far as I can tell. Here's hoping he'll chime in here soon.
 

Posté Thu 06 Sep 07 @ 9:27 am
SBDJPRO Infinity Member since 2006
Hopefully, all tips are gratefully recieved ;)

Like I said in my last message, I've managed to work things out, so have textures rendering now which was my big issue...
 

Posté Thu 06 Sep 07 @ 4:15 pm
djcelPRO InfinityModeratorMember since 2004
Sorry for the delay. I was very busy.

Example 1: Let VDJ draw the video texture on VDJ vertices

 HRESULT __stdcall CPlugin::OnDraw(IDirect3DTexture9 *texture,TVertex *vertices)
{
// Clear the video background and fill it with black color
D3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_RGBA(0,0,0,255), 1.0f, 0 );

return S_FALSE;
}


Example 2: Same thing but with S_OK

HRESULT __stdcall CPlugin::OnDraw(IDirect3DTexture9 *texture,TVertex *vertices)
{
// Clear the video background and fill it with black color
D3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_RGBA(0,0,0,255), 1.0f, 0 );

// Draw the Video texture provided by VirtualDJ
D3DDevice->SetTexture(0,texture);
D3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,(LPVOID)vertices,sizeof(vertices[0]));

return S_OK;
}


Example 3: Draw your own texture on VDJ vertices


IDirect3DTexture9 *NewTexture; // The new texture

[...] Create and fill NewTexture

HRESULT __stdcall CPlugin::OnDraw(IDirect3DTexture9 *texture,TVertex *vertices)
{
// Clear the video background and fill it with black color
D3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_RGBA(0,0,0,255), 1.0f, 0 );

// Draw our own texture
D3DDevice->SetTexture(0,NewTexture);
D3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,(LPVOID)vertices,sizeof(vertices[0]));

return S_OK;
}

[...] Free (= Release) your own texture



Example 4: Draw your own texture on our own vertices



// Our custom FVF, which describes our custom vertex structure
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)

IDirect3DVertexBuffer9 * VertexBuffer;
IDirect3DTexture9 *NewTexture; // The new texture
TVertex *Vertex;

[...] Create and fill NewTexture

// Create a new function in the CPlugin class tocreate our new vertices
HRESULT CPlugin::CreateNewVertices()
{
HRESULT hr;

// Create the vertex buffer.
hr=D3DDevice->CreateVertexBuffer( 4*sizeof(TVertex),D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &VertexBuffer, NULL );
if(FAILED(hr))
{
MessageBox(NULL,"Unable to create the new vertices.",PLUGIN_NAME,MB_OK|MB_ICONERROR);
return S_FALSE;
}

hr=VertexBuffer->Lock( 0, 0, (void**)&Vertex, 0 );
if(FAILED(hr)) return S_FALSE;

Vertex[0].position.x=-1.f;
Vertex[0].position.y=1.f;
Vertex[0].position.z=0.5f;
Vertex[0].color=D3DCOLOR_RGBA(0,0,0,255);
Vertex[0].tu=0.f;
Vertex[0].tv=0.f;

Vertex[1].position.x=1.f;
Vertex[1].position.y=1.f;
Vertex[1].position.z=0.5f;
Vertex[1].color=D3DCOLOR_RGBA(0,0,0,255);
Vertex[1].tu=1.f;
Vertex[1].tv=0.f;

Vertex[2].position.x=-1.f;
Vertex[2].position.y=-1.f;
Vertex[2].position.z=0.5f;
Vertex[2].color=D3DCOLOR_RGBA(0,0,0,255);
Vertex[2].tu=0.f;
Vertex[2].tv=1.f;

Vertex[3].position.x=1.f;
Vertex[3].position.y=-1.f;
Vertex[3].position.z=0.5f;
Vertex[3].color=D3DCOLOR_RGBA(0,0,0,255);
Vertex[3].tu=1.f;
Vertex[3].tv=1.f;

VertexBuffer->Unlock();

return S_OK;
}

HRESULT __stdcall CPlugin::OnDraw(IDirect3DTexture9 *texture,TVertex *vertices)
{
// Clear the video background and fill it with black color
D3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_RGBA(0,0,0,255), 1.0f, 0 );

// Draw our own texture
D3DDevice->SetTexture(0,NewTexture);
D3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,(LPVOID)Vertex,sizeof(Vertex[0]));

return S_OK;
}

[...] Free (= Release) your own texture + free (= Release) your own vertex buffer



D3DPT_TRIANGLESTRIP is better and easier if you want to draw a square (only 4 vertices)

D3DPT_TRIANGLESLIST would need 6 vertices to draw this square

D3DPT_TRIANGLEFAN is more for circle


You can define your own vertices, for example:
typedef struct 
{
D3DVECTOR P;
DWORD diff;
FLOAT tu,tv;
} CUSTOMVERTEX;
 

Posté Sat 08 Sep 07 @ 12:25 am
SBDJPRO Infinity Member since 2006
Thanks fella, I'd pretty much managed to get it sorted anyway. Good idea to stick the examples for easy reference though, thankyou :)
 

Posté Sat 08 Sep 07 @ 6:48 pm
djcelPRO InfinityModeratorMember since 2004
 

Posté Sat 08 Sep 07 @ 10:42 pm
SBDJ wrote :


101010101 have you managed to do any video coding yet? Feel free to give me a shout if you want to discuss anything or let me in on anything you've found ;) Video info seems to be rather hard to come by unfortunately :(

Still need to work out redrawing too - redrawing the texture on every OnDraw call will result in huge CPU utilisation - I only really need to redraw dirty areas. Further investigation required!!

Unfortunately I've never used D3D before, but I'm learning. Slowly ;)

Hence my initial request... :p

yeah i'm still stepping into the video aspect of coding, been editing audio VST plugins though on a limitation through an outside source and feel i'm missing a few key elements, but yeah i'm totally interested in video coding, you can find my msn in my blog, i'm on usually when im bored n got nothing better to do :)
 

Posté Sun 09 Sep 07 @ 6:40 pm
djejPRO InfinityMember since 2004
My head hurts reading this.....ouch. Wow a lot goes into these great plug ins. Keep up the great work.
 

Posté Fri 05 Oct 07 @ 5:59 pm
djcelPRO InfinityModeratorMember since 2004
For information, in video plugins, you have by default:


D3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);

D3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
D3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
D3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );

D3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
D3DDevice->SetRenderState(D3DRS_ALPHAREF, 0);
D3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_ALWAYS);


D3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
D3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
D3DDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT);
D3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
D3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
D3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
D3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE );
D3DDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );

Do not forget to restore these data if you modify them because it affects all the video module of VirtualDJ.
 

Posté Sat 22 Dec 07 @ 12:33 pm
djcelPRO InfinityModeratorMember since 2004
Here is an example of .cpp file for a Video effect on Windows


#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "VdjVideo.h"

//#include <d3d9.h>
//#pragma comment(lib,"d3d9.lib")

// you can also use instead (for D3DX...) :
// #include <d3dx9.h>
// #pragma comment(lib,"d3dx9.lib")

//------------------------------------------------------------------------
class CMyplugin : public IVdjPluginVideoFx
{
public:
HRESULT __stdcall OnLoad();
HRESULT __stdcall OnGetPluginInfo(TVdjPluginInfo *infos);
HRESULT __stdcall OnParameter(int id);
ULONG __stdcall Release();
HRESULT __stdcall OnDXInit();
HRESULT __stdcall OnDXClose() ;
HRESULT __stdcall OnStart();
HRESULT __stdcall OnStop();
HRESULT __stdcall OnDraw(IDirect3DTexture9 *texture,TVertex *vertices);

private:
// Usefull for the example of controls
int SliderValue;
int mode;
char st[128];
};
//--------------------------------------------------------------------------------------------
HRESULT __stdcall DllGetClassObject(const GUID &rclsid,const GUID &riid,void** ppObject)
{
// This is the standard DLL loader for COM object.
// You don't need to change anything in this function.
if(memcmp(&rclsid,&CLSID_VdjPlugin,sizeof(GUID))!=0) return CLASS_E_CLASSNOTAVAILABLE;
if(memcmp(&riid,&IID_IVdjPluginVideoFx,sizeof(GUID))!=0) return CLASS_E_CLASSNOTAVAILABLE;
*ppObject=new CMyplugin();
return NO_ERROR;
}
//---------------------------------------------------------------------------------------------
HRESULT __stdcall CMyplugin::OnLoad()
{
// Examples of controls
DeclareParameter(&SliderValue,VDJPARAM_SLIDER,0,"Slider",1024);
DeclareParameter(&mode,VDJPARAM_SWITCH,1,"Switch button",0);
DeclareParameter(st,VDJPARAM_STRING,2,"Text",sizeof(st));

OnParameter(0);
return S_OK;
}
//---------------------------------------------------------------------------------------------
HRESULT __stdcall CMyplugin::OnGetPluginInfo(TVdjPluginInfo *infos)
{
infos->Author="DJ CEL";
infos->PluginName="Myplugin";
infos->Description="here is your description";
// infos->Bitmap=LoadBitmap(hInstance,MAKEINTRESOURCE(100)); //if you want to add a picture
infos->Flag=0;
return S_OK;
}
//---------------------------------------------------------------------------------------------
ULONG __stdcall CMyplugin::Release()
{
delete this;
return 0;
}
//--------------------------------------------------------------------------------------------
HRESULT __stdcall CMyplugin::OnParameter(int id)
{

return S_OK;
}
//--------------------------------------------------------------------------------------------
HRESULT __stdcall CMyplugin::OnDXInit()
{

return S_OK;
}
//--------------------------------------------------------------------------------------------
HRESULT __stdcall CMyplugin::OnDXClose()
{

return S_OK;
}
//---------------------------------------------------------------------------------------------
HRESULT __stdcall CMyplugin::OnStart()
{
return S_OK;
}
//---------------------------------------------------------------------------------------------
HRESULT __stdcall CMyplugin::OnStop()
{
return S_OK;
}
//---------------------------------------------------------------------------------------------
HRESULT __stdcall CMyplugin::OnDraw(IDirect3DTexture9 *texture,TVertex *vertices)
{
// Clear the video screen
// D3DDevice->Clear(0L, NULL, D3DCLEAR_TARGET, D3DCOLOR_RGBA(0,0,0,255), 1.0f, 0L);

// Write your code here

return S_FALSE;
}
 

Posté Wed 16 Jan 08 @ 11:53 am
djcelPRO InfinityModeratorMember since 2004
Here is an example of .cpp file for a video transition on Windows


#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "VdjVideo.h"

// #include <d3d9.h>
//#pragma comment(lib,"d3d9.lib")

// you can also use instead (for D3DX...) :
// #include <d3dx9.h>
// #pragma comment(lib,"d3dx9.lib")

//------------------------------------------------------------------------
class CMyplugin : public IVdjPluginVideoTransition
{
public:
HRESULT __stdcall OnLoad();
HRESULT __stdcall OnGetPluginInfo(TVdjPluginInfo *infos);
HRESULT __stdcall OnParameter(int id);
ULONG __stdcall Release();
HRESULT __stdcall OnDXInit();
HRESULT __stdcall OnDXClose() ;
HRESULT __stdcall OnStart(int chan);
HRESULT __stdcall OnStop();
HRESULT __stdcall Compose(int crossfader,HRESULT(__stdcall *RenderSurface[2])(),TVertex *vertices[2]);
HRESULT __stdcall OnCrossfaderTimer(int *crossfader);

private:
// Usefull for the example of controls
int SliderValue;
int mode;
char st[128];
};
//--------------------------------------------------------------------------------------------
HRESULT __stdcall DllGetClassObject(const GUID &rclsid,const GUID &riid,void** ppObject)
{
// This is the standard DLL loader for COM object.
// You don't need to change anything in this function.
if(memcmp(&rclsid,&CLSID_VdjPlugin,sizeof(GUID))!=0) return CLASS_E_CLASSNOTAVAILABLE;
if(memcmp(&riid,&IID_IVdjPluginVideoTransition,sizeof(GUID))!=0) return CLASS_E_CLASSNOTAVAILABLE;
*ppObject=new CMyplugin();
return NO_ERROR;
}
//---------------------------------------------------------------------------------------------
HRESULT __stdcall CMyplugin::OnLoad()
{
// Examples of controls
DeclareParameter(&SliderValue,VDJPARAM_SLIDER,0,"Slider",1024);
DeclareParameter(&mode,VDJPARAM_SWITCH,1,"Switch button",0);
DeclareParameter(st,VDJPARAM_STRING,2,"Text",sizeof(st));

OnParameter(0);
return S_OK;
}
//---------------------------------------------------------------------------------------------
HRESULT __stdcall CMyplugin::OnGetPluginInfo(TVdjPluginInfo *infos)
{
infos->Author="DJ CEL";
infos->PluginName="Myplugin";
infos->Description="here is your description";
// infos->Bitmap=LoadBitmap(hInstance,MAKEINTRESOURCE(100)); //if you want to add a picture
infos->Flag=0;
return S_OK;
}
//---------------------------------------------------------------------------------------------
ULONG __stdcall CMyplugin::Release()
{
delete this;
return 0;
}
//--------------------------------------------------------------------------------------------
HRESULT __stdcall CMyplugin::OnParameter(int id)
{

return S_OK;
}
//--------------------------------------------------------------------------------------------
HRESULT __stdcall CMyplugin::OnDXInit()
{

return S_OK;
}
//--------------------------------------------------------------------------------------------
HRESULT __stdcall CMyplugin::OnDXClose()
{

return S_OK;
}
//---------------------------------------------------------------------------------------------
HRESULT __stdcall CMyplugin::OnStart(int chan)
{
return S_OK;
}
//---------------------------------------------------------------------------------------------
HRESULT __stdcall CMyplugin::OnStop()
{
return S_OK;
}
//---------------------------------------------------------------------------------------------
HRESULT __stdcall CMyplugin::Compose(int crossfader,HRESULT(__stdcall *RenderSurface[2])(),TVertex *vertices[2])
{
// Clear the video screen
// D3DDevice->Clear(0L, NULL, D3DCLEAR_TARGET, D3DCOLOR_RGBA(0,0,0,255), 1.0f, 0L);

// Write your code here
// RenderSurface[0]();
// RenderSurface[1]();

return S_OK;
}
//---------------------------------------------------------------------------------------------
HRESULT __stdcall CMyplugin::OnCrossfaderTimer(int *crossfader)
{
return GetInfo("AutoVideoCrossfader",crossfader);
}
 

Posté Wed 16 Jan 08 @ 12:11 pm
1nhfvHome userMember since 2009
Hello to all I || {micha from Israel and I want to receive some help maybe someone here will be able to say me which good software to computerize in an attempt to do || remix thank you very much
 

Posté Sun 01 Feb 09 @ 1:07 pm
SBDJPRO Infinity Member since 2006
This isn't the right part of the forum; try General Discussion.
 

Posté Sun 01 Feb 09 @ 1:44 pm
SBDJ,

You told me that you can make the video "falling cubes" pluging.
I really like that visual effect.
Do you have time to make it?
 

Posté Sun 22 Feb 09 @ 5:47 am
SBDJPRO Infinity Member since 2006
Thats not a simple plugin, but I can add it to my long to-do list!
 

Posté Sun 22 Feb 09 @ 5:58 am
Thanks mate !!!

I'l wait and see.

:-)
 

Posté Sun 22 Feb 09 @ 6:01 am
71%