Author Topic: How to render Video to DirectX9 Screen?  (Read 6598 times)

0 Members and 1 Guest are viewing this topic.

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
How to render Video to DirectX9 Screen?
« on: January 22, 2008 »
I am using DirectShowMedia to play videos in a window which seems to work fine. When having a DirectX9 screen (800x600 pixels for example) and wanting to display a video on the DirectX9 Screen, whats the best way for this?

I thought about something like creating and using a temporary Texture where i can draw the actual video-image with DShowMedia->GetCurrentImage() to display the video on the DirectX9 screen. I am not sure if this is a good solution, because of following problems and thoughts:

a) What size must be the temporary texture to render the video on? 512x512 or something like 800x600 which is not a good solution afaik.

b) What if the videosize is smaller or bigger as 800x600, have i resize the grabbed image or video before drawing it on the texture?

c) When using for example a 512x512 texture to draw the video on and resize the video-texture to 800x600 for showing on screen, the quality may suxx a bit...

I would be very very happy for any good tip and nice/friendly solution to display the video on a DirectX9 screen (as background). Thanks in advance!
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: How to render Video to DirectX9 Screen?
« Reply #1 on: January 22, 2008 »
found this one on web but seems to be a bad (slow) solution...!?

Quote
bytheway: i did some GetTickCount-ing => GetCurrentImage of IBasicViceo takes 175 msecs to complete :eek: :eek: :eek:

http://vjforums.com/archive/index.php?t-8304.html

- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: How to render Video to DirectX9 Screen?
« Reply #2 on: January 22, 2008 »
I'm sure that Jim wrote something to do this before.. It converted a video to ascii I believe.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: How to render Video to DirectX9 Screen?
« Reply #3 on: January 22, 2008 »
ah very nice to know.... still looking forward...i am sure someone here can and may help me :) thanks  a lot
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: How to render Video to DirectX9 Screen?
« Reply #4 on: January 22, 2008 »
The best/fastest way is to use DirectShow with a Custom Allocator attached.  What that means is that the video frames are decoded directly into Direct3D textures that you can use in a 3D scene.  Usually the textures are the next size up in power-of-2 of the video, so 800x600 would be delivered into a 1024x1024 texture.  There are samples for this in the SDKs (DirectX+PlatformSDK) and I can give you a sample.
In my ASCII renderer I used the standard AVI handling code from Windows.  Basically there you can Open and AVI file, Create a handle to one of the Streams in the AVI file, then call GetNextSample to get the next frame delivered.  You then have to roll-your-own rendering.  The only real disadvantage with this method is it can't use all the video codecs on the system, there's some limitation.

Jim
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: How to render Video to DirectX9 Screen?
« Reply #5 on: January 23, 2008 »
The best/fastest way is to use DirectShow with a Custom Allocator attached.  What that means is that the video frames are decoded directly into Direct3D textures that you can use in a 3D scene.  Usually the textures are the next size up in power-of-2 of the video, so 800x600 would be delivered into a 1024x1024 texture.  There are samples for this in the SDKs (DirectX+PlatformSDK) and I can give you a sample.

Hello Jim! Thanks for the reply! I dont really know what you mean with "Custum Allocator"? (own alloc mem or other thing?) Ok, i dont really like to render the movies to 1024x1024 textures because not all graphic cards support this afaik (even older may have problems)!? And what, if a video may the size > 1024 with ? :P *questions over questions, i know*

If you have sample code from SDK it would be nice if you can send me as zip, because atm i dont have installed this things on my hd. Thanks in advance. Hope i will get it work with a look to the PSDK examples. thx my friend! :-)
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: How to render Video to DirectX9 Screen?
« Reply #6 on: January 23, 2008 »
CustomAllocator is a DirectShow object.  Either you can let DirectShow render directly to a Window using VMR9 (VideoMixingRenderer9) or you can get it to ask YOU for the memory to decode in to.  It's way more flexible to get the image in a texture rather than letting dshow render it for you.  If the video is > 1024 wide then you need to use a 2048 wide texture.  If so, then you're dealing with HD video anyway, and any PC with a card that can't handle that couldn't decode the video anyway!  Any card from the last 7 years can do 1024x1024 sizes - you need to know your audience, who I would guess are mostly people with graphics cards under 2 years old which can handle textures 4 or 8k wide.

You won't be able to build anything DirectShowy at all without both an up-to-date DirectX SDK and Platform SDK, and all the samples are in there.

I've attached some tiny bits of code that might be some use, to get an idea of what you're in to - no chance of it building like it stands though, I've just chopped them out of another project I was working on.

rmp.cpp:StartGraph is the bit where a directshow rendering graph is built.  A graph is just a collection of filters, like 'source', 'splitter', 'video decoder', 'audio decoder', 'video renderer', 'audio renderer' which are all linked together to make a player.
In allocator.cpp (which is almost straight from the samples) you get to see what it means to write an allocator.
InitializeDevice is where the graph asks you to allocate some textures
PresentImage is where the graph delivers a frame of data.

Jim
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: How to render Video to DirectX9 Screen?
« Reply #7 on: January 23, 2008 »
hello jim...
i am able to let DirectShow render directly to a window (own/parent window) using CLSID_VideoMixingRenderer9. Yes i agree with you and getting the image in a texture instead letting dhow render it for me, is exactly what i am looking for.

You are saying when the video would be >1024 width i have to use 2048 which is clear so far. I am not sure but i thought about DShow->put_Width() and DShow->put_Height() to resize the original video before getting the image on a 1024x1024 sized texture. I am not sure if this could work to resize all videos to fit on 1024 width sized texture instead using > 1024 width sized textures.

Quote
You won't be able to build anything DirectShowy at all without both an up-to-date DirectX SDK and Platform SDK, and all the samples are in there.

Yes i think you are right. I am using MSDN and generall www for searches and getting infos how the API may work.

I will take a look to this "allocator" thing and your source/zip to get my code work as i need... Thanks for the zip!!! Btw, as "graph" i am using atm following:   CLSID_OverlayMixer   CLSID_VideoRenderer    CLSID_VideoRenderer   CLSID_AudioRender

Again i have to thank you! THX !! :-)
 
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: How to render Video to DirectX9 Screen?
« Reply #8 on: January 24, 2008 »
I think you'd have more luck inserting a 'resize' filter in the graph before the renderer (be it a VMR9 or a custom allocator).  Once the graph is running and you have a chance to call set_Width/Height it'll be too late, the graph will have been created and the allocator already set up, and I'm not sure those functions affect the delivered frames, I think they affect how it's drawn.  I think.  No real harm in trying it. :)

Jim
Challenge Trophies Won: