<p>I am using <a href="http://msdn.microsoft.com/en-us/library/aa387410(VS.85).aspx" rel="nofollow noreferrer">Windows Media Format SDK</a> to capture the desktop in real time and save it in a WMV file (actually this is an oversimplification of my project, but this is the relevant part). For encoding, I am using the <a href="http://www.microsoft.com/windows/windowsmedia/forpros/codecs/video.aspx#WindowsMediaVideo9Screen" rel="nofollow noreferrer">Windows Media Video 9 Screen</a> codec because it is very efficient for screen captures and because it is available to practically everybody without the need to install anything, as the codec is included with Windows Media Player 9 runtime (included in Windows XP SP1).</p>

<p>I am making BITMAP screen shots using the GDI functions and feed those BITMAPs to the encoder. As you can guess, taking screen shots with GDI is slow, and I don't get the screen cursor, which I have to add manually to the BITMAPs. The BITMAPs I get initially are DDBs, and I need to convert those to DIBs for the encoder to understand (RGB input), and this takes more time. </p>

<p>Firing a profiler shows that about 50% of the time is spent in WMVCORE.DLL, the encoder. This is to be expected, of course as the encoding is CPU intensive.</p>

<p>The thing is, there is something called <a href="http://www.microsoft.com/windows/windowsmedia/forpros/encoder/default.mspx" rel="nofollow noreferrer">Windows Media Encoder</a> that comes with a SDK, and can do screen capture using the desired codec in a simpler, and more CPU friendly way.</p>

<p>The WME is based on WMF. It's a higher lever library and also has .NET bindings. I can't use it in my project because this brings unwanted dependencies that I have to avoid.</p>

<p>I am asking about the method WME uses for feeding sample data to the WMV encoder. The encoding takes place with WME exactly like it takes place with my application that uses WMF. WME is more efficient than my application because it has a much more efficient way of feeding video data to the encoder. It doesn't rely on slow GDI functions and DDB->DIB conversions. </p>

<p>How is it done?</p>

[{'answer_id': 89253, 'author': 'Redbeard', 'author_id': 14977, 'author_profile': 'https://Stackoverflow.com/users/14977', 'pm_score': 0, 'selected': False, 'text': "<p>It's been ages since I've done any Win32 coding, but AFAIK, WMF as a format is basically a list of GDI commands and their parameters which would explain why it is much more efficient to encode...</p>\n\n<p>You'd probably need to hook into the top level GDI context (just as Remote Desktop does, I guess) and capture the GDI commands as they are called. I seem to remember there being some way of creating a WMF output GDI context which means you may be able to just delegate calls to it in some way. </p>\n\n<p>I'm guessing here, but you may be able to find example code for the above in the TightVNC/QuickVNC for Windows projects as they would have to do something like that to capture changes on screen in an efficient way.</p>\n"}, {'answer_id': 221521, 'author': 'Ian Ozsvald', 'author_id': 18688, 'author_profile': 'https://Stackoverflow.com/users/18688', 'pm_score': 1, 'selected': False, 'text': '<p>The source to CamStudio, a GPL\'d screencasting app that\'s been around for years (commercially and then open-srcd later) might be useful?</p>\n\n<p><a href="http://sourceforge.net/project/showfiles.php?group_id=131922" rel="nofollow noreferrer">http://sourceforge.net/project/showfiles.php?group_id=131922</a></p>\n\n<p>I\'d suggest looking at the guts of VNC clients too, though they\'re probably very simplistic (I think just grabbing screenshots then jpg\'ing the tiles that have changed since the last capture).</p>\n\n<p>You might want to consider not using WMV9 as the encoder for on-the-fly encoding if it is too cpu-heavy?  Maybe use an older, less efficient compressor (like MS RLE) as used by HyperCam and then compress to WMV afterwards?  MS RLE has been a default install since at least Win2000 I believe:\n<a href="http://wiki.multimedia.cx/index.php?title=Microsoft_RLE" rel="nofollow noreferrer">http://wiki.multimedia.cx/index.php?title=Microsoft_RLE</a></p>\n\n<p>CamStudio\'s Lossless codec is GPL (same link as above), that offers pretty good compression (though you\'d need to bundle the dll in your installer) and could be used on the fly, it works well with high compression on all modern systems.</p>\n'}, {'answer_id': 398272, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Have you checked out the <a href="http://www.bbsoftware.co.uk/BBFlashBack/Home.aspx" rel="nofollow noreferrer">BB FlashBack</a> library?</p>\n\n<p>I am on a similar hunt, and I have just started evaluating the BB FlashBack library.</p>\n\n<p>I am not sure about the external dependencies or install footprint. It appears to have a proprietary codec that has to be installed, but the installation of the codec can be handled by the exposed BB FlashBack API.</p>\n\n<p>Beware, there are licensing restrictions (Runtime setting of license keys, ...)</p>\n\n<p>I can send you the CHM from the SDK via e-mail if you want to evaluate the API before committing to a licensed download.</p>\n\n<p>Things I am in the midst of evaluating:\nProper captures of WPF views\nmouse cursor tracking\nSize of stored movie\nHow to display stored movie without proprietary codec (i.e. SWF export)</p>\n\n<p>--Batgar</p>\n'}]
['https://Stackoverflow.com/questions/63563', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7053/']