|
Nov
7
Written by:
Jeremiah Morrill
11/7/2008 5:15 AM
I don't have a whole lot of time, even for this post. Been bombarded with work. I still wanted to share my latest concoction. Simply put, I am able to grab the Direct3D shared Surface the Vista DWM uses (undocumented API) to paint all Direct3D based windows. Once I have that, I am able to use it as a "VisualBrush" in WPF or I can copy the Direct3D Surface to system memory for very high frame rate captures.and you can stream it out too.to Silverlight even! This idea is similar in concept to Fraps, but Fraps uses DLL injection and method hooking (I suspect). Here is a video showing a Direct3D sample application (lower left), also rendering to a WPF application (upper left, notice the cliché reflection), then you have it being streamed to a Silverlight MediaElement (wmv format), in real-time. (On a side note, SL streaming service is great compared to the quality of YouTube. Check it out in fullscreen!) Here is a WPF application being streamed to Silverlight. Here is the source for the application. It's very ugly code, but it's only a quick prototype I threw together. I use SlimDX, so if you have any issues using it, make sure to install the latest DX runtimes here. http://jmorrill.hjtcentral.com/Portals/21/blog/DxCapture.zip Note, if you wish to just render the DWM surface to the application, leave the output filename blank and do not select "network stream". If you wish to stream the application video, just check the network stream checkbox and you can open the video in Windows Media Player by opening the url: http://localhost:selectedport/ -Jer
Tags:
20 comment(s) so far...
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
Jer, that is so cool!
Just gave the example a quick test and it works realy good, even with a video window as "source".
Is it possible to have a WPF sufface (canvas) as "source"? Then I could make my own "TV station" mixing video with fx add text in WPF and stream it to a media player.
/Ken
By Ken on
11/10/2008 4:05 AM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
Thanks Ken!
You can not use a specific WPF visual as the "source", only the entire top level window of a DX/WPF application. You could create a WPF application that used one window to display all your "TV Station" visuals and another window for controlling your "TV Station" and only use your one window as the "Source"
-Jer
By Jeremiah Morrill on
11/10/2008 4:38 AM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
If you like it, BTW, please give me a "Kick" on dotnetkicks!
http://www.dotnetkicks.com/wpf/Vista_DWM_Hacking_Capture_and_Stream_D3D_WPF_Windows_Real_Time
By Jeremiah Morrill on
11/10/2008 5:20 AM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
Yes that works fine (even with WindowStyle = WindowStyle.None)
however, I also need sound... I asume that I can add line in or "what U haer" from the windowmixer, to the "CwmvFile", have you tested?
And, do you think it's possible to start/stop rendering to file (so I can create new files) without stoping the streaming. Or maybe I can just have several "CwmvFile" classes on the "DwmCapture" class.
/Ken
By Ken! on
11/10/2008 6:47 AM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
Hi all, I get blank black backgound in the WPF app and also black video stream :( Anyone can help?
By DragoraN on
11/17/2008 3:58 PM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
DragoraN,
You must specificy a window that is Direct3D based, ie video game or WPF application.
By Jeremiah Morrill on
11/17/2008 4:35 PM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
Thank you Jeremiah, it was not clear for me from the post. One other question. I am experiencing major delay in network stream. It is delayed about 5 seconds after i make change to source. In the post I can see that it is matter of miliseconds, how it is possible? Can you advice please?
By DragoraN on
11/17/2008 5:29 PM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
If you watch closely, the video's on this page are also delayed about 5 seconds. This is a side effect of the Windows Media Format SDK and how it automatically buffers video server and client side. The only way to get real time, is to use another streaming method/library. You have access to the uncompressed bitmap in the code, so the video source should not be an issue.
-Jer
By Jeremiah Morrill on
11/17/2008 5:52 PM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
Hi! I have some question about DWM and related feature. My project wanna a feature that all output of screen be stored in a offscreen buffer, a program do some modify of the buffer, for example twist the screen image or make output brighter or darker, then the modified result be sent to the real screen.
It is just something like flip3d in vista. Do you think it is possible to achieve? Please give me some suggestion :)
By Fu Chen on
11/19/2008 12:00 AM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
Hi! I have some question about DWM and related feature. My project wanna a feature that all output of screen be stored in a offscreen buffer, a program do some modify of the buffer, for example twist the screen image or make output brighter or darker, then the modified result be sent to the real screen.
It is just something like flip3d in vista. Do you think it is possible to achieve? Please give me some suggestion :)
By Fu Chen on
11/19/2008 12:05 AM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
this still doesn't seem to work if you minimize the window though. arg, can't find a solution that will take a screen capture of a minmized window... there must be a way.
By matt g on
2/27/2009 12:03 AM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
I don't think you can capture a minimized window...well you probably sorta 'hack it', but minimized windows ignore classic WM_PAINT messages and therefore will not paint when minimized.
By Jeremiah Morrill on
2/27/2009 12:24 AM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
ahh I see. Any pointers on how to 'hack it'?
By matt g on
2/27/2009 1:19 AM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
would it work to send a WM_PAINT message through your own application to the application of interest then take a capture?
By matt g on
2/27/2009 1:21 AM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
Acutallly that wouldn't work. With this example I notice that I get a stream sometimes and sometimes I only get black images. I don't really change anything and it seems sporadic. Any clue what it might be?
By matt g on
2/27/2009 2:09 AM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
Hello Jeremiah,
i am trying to run the application on a Vista 64 bit, but it is giving me error the following error Exception from HRESULT: 0xC00D0BB8 on m_pWMWriter.BeginWriting(); Initialize function.
Any idea how to fix that.
By Shahbour on
3/12/2009 5:21 AM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
Hello
I was trying to load an WPF Applicaiton, i found that it is only working if i am asking it to load a full screen window but if i try to load a normal window it is giving an error HRESULT: 0xC00D0BB8 on m_pWMWriter.BeginWriting(); which i found to be invalid input format .
In the example above Jim was loading a normal window so something wrong is going with my application.
Any Idea -- Shahbour
By Shahbour on
3/16/2009 9:06 AM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
@Shahbour: i am having the same probs here...did you find a solution?
By Matthias on
3/27/2009 4:56 AM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
Hello Matthias,
For i didn't need to save into WMV file to i stopped that then every thing worked great, you can do so easily by removing the name of file to output to. i think it is related to the size or ratio of the window ur are capturing.
BR Shahbour
By Shahbour on
4/10/2009 12:06 AM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
Same error here on: m_pWMWriter.BeginWriting()
But the strange thing is that it worked a few weeks ago, maybe DXlib is updated and it don't work after that?
I realy like to get it working again (Vista SP1, 32bit)
By Ken on
6/2/2009 10:45 AM
|
|
|
|