{"id":2210,"date":"2021-11-20T21:49:21","date_gmt":"2021-11-20T19:49:21","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=2210"},"modified":"2021-11-23T16:49:26","modified_gmt":"2021-11-23T14:49:26","slug":"dxgitakewindowsnapshot-window-recording-w-audio","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/2210","title":{"rendered":"DxgiTakeWindowSnapshot &#038; Window Recording w\/ Audio"},"content":{"rendered":"\n<p>I am sometimes using a rework of earlier <a href=\"https:\/\/alax.info\/blog\/2075\"><code>DxgiTakeSnapshot<\/code><\/a> application for one specific purpose mentioned below. In addition to <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/direct3ddxgi\/desktop-dup-api\">Desktop Duplication API<\/a>, recent version of Windows offer a similar (in sense of acquisition of external video content) API: <code><a href=\"https:\/\/docs.microsoft.com\/en-us\/uwp\/api\/windows.graphics.capture\">Windows.Graphics.Capture<\/a><\/code> (hereinafter &#8220;WGC&#8221;), and the new rework is using this API to capture visual content as a snapshot or, now, as a video stream.<\/p>\n\n\n\n<p>I will skip the technical details and just link Robert Mikhayelyan&#8217;s <a href=\"https:\/\/github.com\/robmikh\/Win32CaptureSample\"><code>Win32CaptureSample<\/code> project on GitHub<\/a>, which is perhaps the best place to ask questions about this new API.  <\/p>\n\n\n\n<p>The today&#8217;s application takes a snapshot of given monitor, window or process windows (each window separately) similar to original <a href=\"https:\/\/alax.info\/blog\/2075\"><code>DxgiTakeSnapshot<\/code><\/a> application, and this might be worth a separate post, but at this time I just wanted to mention an quick hack with -Video command line argument. <\/p>\n\n\n\n<p>The hack uses the API along with taking audio currently played and records the audiovisual stream into MP4 file until you stop it with Control+Break.<\/p>\n\n\n\n<p>For example, this way I recorded video below by recording browser window with YouTube playback. I started the app first to quickly identify <code>HWND<\/code> of interest. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>C:\\&gt;DxgiTakeWindowSnapshot.exe -Process msedge.exe<\/strong>\nDxgiTakeWindowSnapshot.exe 20210717.1-16-g34e6c97 (Release)\n34e6c972dad5568347d44e58ab0338b7daa1dba7\nHEAD -&gt; video, origin\/video\n2021-11-20 21:07:46 +0200\n--\nFound process 023228 \"C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe\"\nFound 2 windows for process 023228\nTrying to capture window 0x0000000000A608E0, Filatov &amp; Karas - ????? ? ?????? (Live @????????? ) - YouTube - Personal - Microsoft??? Edge\nTrying to capture window 0x00000000016D066E, Filatov &amp; Karas - Don???t Be So Shy (RuSongTV - Turkey) - YouTube and 3 more pages - Personal - Microsoft??? Edge\nFound process 013944 \"C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe\"\nFound 0 windows for process 013944\n\n<strong>C:\\&gt;DxgiTakeWindowSnapshot.exe -Window 0x0000000000A608E0 -Video<\/strong>\nDxgiTakeWindowSnapshot.exe 20210717.1-16-g34e6c97 (Release)\n34e6c972dad5568347d44e58ab0338b7daa1dba7\nHEAD -&gt; video, origin\/video\n2021-11-20 21:07:46 +0200\n--\nTrying to capture window 0x0000000000A608E0, Filatov &amp; Karas - ????? ? ?????? (Live @????????? ) - YouTube - Personal - Microsoft??? Edge\nStopping: CTRL_C_EVENT\n<\/pre>\n\n\n\n<p>(see next post on <a href=\"https:\/\/alax.info\/blog\/2217\">why video below is blocked here<\/a>)<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"DxgiTakeWindowSnapshot&#039;s WGC &amp; Loopback Audio Recording\" width=\"1040\" height=\"585\" src=\"https:\/\/www.youtube.com\/embed\/9y4hLD4K8mE?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div><figcaption>Original content: <a href=\"https:\/\/youtu.be\/yOLLgzBDY3g\">Filatov &amp; Karas &#8211; ????? ? ?????? (Live @????????? )<\/a><\/figcaption><\/figure>\n\n\n\n<p>The application is currently hardcoding produced video as 1920&#215;1080@60 with 10 MBps bitrate, and is subject to certain limitations because of quick and hacky implementation:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>as mentioned, 1920&#215;1080@60 with 10 MBps video bitrate (&amp; max documented bitrate for stock AAC audio encoder)<\/li><li>video might be letterboxed to preserve aspect ratio (default behavior of <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/medfound\/video-processor-mft\">Media Foundation XVP<\/a>)<\/li><li>compatible Media Foundation video encoder which is expected to be discoverable as default (hardware encoding is used as designed)<\/li><li>a pretty much regular audio device expected, certain not so usual settings like 5.1 audio as shared format are likely to cause exceptions<\/li><li>the application picks default multimedia audio device for recording (actual code line is <code>auto const Device = DefaultAudioEndpoint(<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/api\/mmdeviceapi\/ne-mmdeviceapi-edataflow\">eRender<\/a>, <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/api\/mmdeviceapi\/ne-mmdeviceapi-erole\">eMultimedia<\/a>);<\/code>)<\/li><\/ul>\n\n\n\n<p>So that one specific purpose the application is good for is <strong>meeting recording<\/strong>: record a window with Google Meet session, Microsoft Teams or alike and you have a convenient copy of content for review or share.<\/p>\n\n\n\n<p>As of now the application is recording only audio playback device, but not the microphone &#8211; I will reach this some time later.<\/p>\n\n\n\n<p>If you want something more convenient, there is also Robert&#8217;s <a href=\"https:\/\/www.microsoft.com\/en-us\/p\/simple-screen-recorder\/9n5mvvbd0tgw#activetab=pivot:overviewtab\">Simple Screen Recorder in Windows Store<\/a>, however this will be video only yet with <a href=\"https:\/\/github.com\/robmikh\/SimpleRecorder\">source code on GitHub<\/a>.<\/p>\n\n\n\n<p><code>DxgiTakeWindowSnapshot<\/code> uses Media Foundation in old-school way: it creates a Microsoft Media Foundation <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/medfound\/media-session\">Media Session<\/a> pipeline with a few custom primitives and some stock ones, esp. video encoder, video processor and audio encoder it takes all this stuff off  to record media&#8230;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Download links<\/h3>\n\n\n\n<p>Binaries:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> 64-bit: <a href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2021\/11\/DxgiTakeWindowSnapshot-20211120-34e6c972dad5568347d44e58ab0338b7daa1dba7.zip\">DxgiTakeWindowSnapshot.exe<\/a>  (in .ZIP archive)<\/li><li> License: This software is free to use<\/li><\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am sometimes using a rework of earlier DxgiTakeSnapshot application for one specific purpose mentioned below. In addition to Desktop Duplication API, recent version of Windows offer a similar (in sense of acquisition of external video content) API: Windows.Graphics.Capture (hereinafter &#8220;WGC&#8221;), and the new rework is using this API to capture visual content as a&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/2210\">Read the full article<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[485,38,624,379,424,132,486,70,623],"class_list":["post-2210","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-audio","tag-c","tag-dxgitakewindowsnapshot","tag-h-264","tag-media-foundation","tag-utility","tag-video","tag-winapi","tag-windows-graphics-capture"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/2210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/comments?post=2210"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/2210\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=2210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=2210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=2210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}