|
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:
32 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
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
Hi Jer, how/where did you get the function signatures for:
[PreserveSig] [DllImport("dwmapi.dll", EntryPoint = "#101")] public static extern int UpdateWindowShared(IntPtr hWnd, int one, int two, int three, IntPtr hMonitor, IntPtr unknown);
[PreserveSig] [DllImport("dwmapi.dll", EntryPoint = "#100")] public static extern int GetSharedSurface(IntPtr hWnd, Int64 adapterLuid, uint one, uint two, [In, Out]ref uint pD3DFormat, [Out]out IntPtr pSharedHandle, UInt64 unknown);
dwmapi.dll has a lot more exports in windows 7 and I am guessing that GetSharedSurface's signature may have changed, which is what is causing to return a borked pointer in windows 7.
By Justin on
7/25/2009 6:54 AM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
Hi, could this be used to capture the whole screen? I haven't found any screen recording application which is "fast enough" when running Aero and this look like as it could be fast enough :-)
By Jaroslav Smid on
9/2/2009 1:42 PM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
Can I use this code to capture the desktop ? If yes how ? I tried with GetDesktopWindow but it doesn't seems to work.
By Guillaume on
9/9/2009 1:29 PM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
Hello , I try to run this program in microsfot window XP professional. It run withour any error but when i debugg this program and try to strat the window capturing. It show error "could not find window blobs" and could not works the options of " Blobs" and "output.wmv". Please any one can tell me that how can i correct these error and suggest me that i run 3D game in my PC and want to display on tv.
By riasat on
11/11/2009 4:56 AM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
this is something i have been very interested in lately. thanks.
By Louis-Vuitton-Handbag on
1/5/2010 10:41 PM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
Has anyone gotten this to work on Windows 7 (or any other solutions to the same problem)? When I try to run the sample project on one of my windows I get a null pointer error at this line:
Texture texture = Texture.FromPointer(pTexture);
Looks like the CreateTexture() API is failing.
Thanks
By JDW on
3/2/2010 10:32 AM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
Hi Jer, I'm also interested in the previous comment by another Justin about determining the function signatures for those undocumented API exports in dwmapi.dll on Windows 7.
I'm no dis/assembler guru by any means, and the best I could determine (assuming that the entry point number didn't change from #100) is that GetSharedSurface now has 8 parameters (mov eax,[ebp+20h]) and that i believe it is a [ref] parameter on Windows 7.
Cheers, J
By Justin S on
3/6/2010 4:38 PM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
Correct - I think it is 9 parameters - again my assembler skills are next to none!
By Justin S on
3/6/2010 4:41 PM
|
|
ed hardy
ED Hardy Hoodies ED Hardy Hoodies Ed Hardy Swimwear Ed Hardy Swimwear ed hardy tops ed hardy tops ed hardy shoes ed hardy shoes ed hardy t shirt ed hardy t shirt ed hardy shirts ed hardy shirts christian audigier christian audigier ed hardy kids ed hardy kids Ed Hardy Sunglasses Ed Hardy Sunglasses ED Hardy belts ED Hardy belts ed hardy Bags ed hardy Bags ed hardy purse ed hardy purse ed hardy mens ed hardy mens ed hardy womens d hardy womens ed hardy mens shirts ed hardy mens shirts ed hardy mens tops ed hardy mens tops ed hardy mens hoodies d hardy mens hoodies ed hardy mens swim trunks ed hardy mens swim trunks ed hardy mens shoes ed hardy mens shoes ed hardy womens swimwear ed hardy womens swimwear ed hardy womens t shirt ed hardy womens t shirt ed hardy womens tops ed hardy womens tops ed hardy womens pants ed hardy womens pants ed hardy womens hoodies ed hardy womens hoodies ed hardy womens shoes ed hardy womens shoes ed hardy womens clothing ed hardy womens clothing
By ed hardy on
3/15/2010 9:34 PM
|
cheap nike shox
There are wide variety of Nike Shox for both men and women's selection.The Nike Shox Sale are best selling nowadays.Get your own Cheap Nike Shox now.It's definitely time for you to buy womens nike shox and wens nike shox, Wearing them will keep you in a perfect condition.
By nike shox on
3/16/2010 10:35 PM
|
Re: Vista DWM Hacking – Capture and Stream D3D/WPF Windows Real-Time
Hi Jer,
Really Great Example. I could Capture WPF application using provided DxCapture sample only after enabling Aero Theme in Vista, before that Shared Window Handle remained ZERO.
I was able to stream video and could get in Media Player by specifying http:localhost:myport. Now my question is, Can I also get the sound with this video stream? I did not received any video from it. If WDM is not capable to provide Audio, can you provide/suggest the link to add audio with this Stream?
Thanks is advance
By SumitMCA on
9/5/2009 3:28 AM
|
|
|
|