{"id":2304,"date":"2024-04-13T20:22:58","date_gmt":"2024-04-13T19:22:58","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=2304"},"modified":"2024-04-21T12:48:44","modified_gmt":"2024-04-21T11:48:44","slug":"gpu-shader-sobel-filter-and-video-capture-with-media-foundation-capture-engine-api","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/2304","title":{"rendered":"Demo: GPU shader Sobel filter and video capture with Media Foundation Capture Engine API"},"content":{"rendered":"\n<p>Back to some experiments&#8230;<\/p>\n\n\n\n<p>The current video capture API in Windows is Media Foundation <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/mfcaptureengine\/nn-mfcaptureengine-imfcaptureengine\">Capture Engine API<\/a> (AKA <code>IMFCaptureEngine<\/code> and <code>mfcaptureengine.h<\/code>). Media Foundation is layered: you can work at lower level with video capture Media Sources, but if you don&#8217;t want to go into details you have the Capture Engine.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"503\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2024\/04\/image-800x503.png\" alt=\"\" class=\"wp-image-2305\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2024\/04\/image-800x503.png 800w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2024\/04\/image-320x201.png 320w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2024\/04\/image-768x483.png 768w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2024\/04\/image-1536x965.png 1536w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2024\/04\/image-2048x1287.png 2048w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2024\/04\/image-600x377.png 600w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2024\/04\/image-1040x653.png 1040w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<p>The application continues a good old <code><a href=\"https:\/\/github.com\/microsoft\/Windows-classic-samples\/tree\/a47da3d4551b74bb8cc1f4c7447445ac594afb44\/Samples\/CaptureEngineVideoCapture\">CaptureEngineVideoCapture<\/a><\/code> sample from Windows Classic Samples, and adds an <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/mfcaptureengine\/nf-mfcaptureengine-imfcapturesource-addeffect\">effect <\/a>in form factor of Media Foundation Transform to the engine.<\/p>\n\n\n\n<p>One of the unobvious aspects is that video stream goes with data backed in video memory by default. Hence, the effect would preferrably handle the stream on associated Direct3D 11 device. <\/p>\n\n\n\n<p>The effect here is a HLSL equivalent of <a href=\"https:\/\/www.shadertoy.com\/view\/XssGD7\">Webcam edge glow<\/a> shadertoy, and processes the video from webcamera on GPU, via shader implementing <a href=\"https:\/\/en.wikipedia.org\/wiki\/Sobel_operator\">Sobel operator<\/a>. The data does not leave video memory and continues its travel along capture engine to preview visualization.<\/p>\n\n\n\n<p>The shader code can be looked up at in the executable resources, it is compiled on runtime.<\/p>\n\n\n\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-7eabae3d-0749-4f71-a285-053c59f54776\" href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2024\/04\/Capture-20240413-a887e2ae105d1623b8707cdc971916c5d8a58aeb.zip\">Capture-20240413-a887e2ae105d1623b8707cdc971916c5d8a58aeb<\/a><a href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2024\/04\/Capture-20240413-a887e2ae105d1623b8707cdc971916c5d8a58aeb.zip\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-7eabae3d-0749-4f71-a285-053c59f54776\">Download<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Back to some experiments&#8230; The current video capture API in Windows is Media Foundation Capture Engine API (AKA IMFCaptureEngine and mfcaptureengine.h). Media Foundation is layered: you can work at lower level with video capture Media Sources, but if you don&#8217;t want to go into details you have the Capture Engine. The application continues a good&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/2304\">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":[38,424,486],"class_list":["post-2304","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-c","tag-media-foundation","tag-video"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/2304","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=2304"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/2304\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=2304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=2304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=2304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}