{"id":1044,"date":"2009-09-21T19:01:25","date_gmt":"2009-09-21T17:01:25","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=1044"},"modified":"2009-09-21T19:16:05","modified_gmt":"2009-09-21T17:16:05","slug":"how-to-overlay-a-bitmap-on-top-of-video-with-video-mixing-renderer-vmr-9","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/1044","title":{"rendered":"How to overlay a bitmap on top of video with Video Mixing Renderer (VMR-9)"},"content":{"rendered":"<p>A 100-lines code snippet which illustrates how a bitmap is overlaid over displayed video with <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dd407344%28VS.85%29.aspx\">Video Mixing Renderer 9 Filter<\/a> using <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dd390449%28VS.85%29.aspx\">IVMRMixerBitmap9<\/a> interface. A video clip is played (default is Windows clock.avi, but you can replace it with your longer one to see overlay is really in a loop).<\/p>\n<p><a href=\"http:\/\/code.assembla.com\/roatl-utilities\/subversion\/nodes\/trunk\/VmrMixerBitmapSample01\/VmrMixerBitmapSample01.cpp#ln49\">http:\/\/code.assembla.com\/&#8230;\/VmrMixerBitmapSample01\/&#8230;<\/a><\/p>\n<pre>VMR9AlphaBitmap AlphaBitmap<span style=\"color: #800080;\">;<\/span>\r\n<span style=\"color: #400000;\">ZeroMemory<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">&amp;<\/span>AlphaBitmap<span style=\"color: #808030;\">,<\/span> <span style=\"color: #800000; font-weight: bold;\">sizeof<\/span> AlphaBitmap<span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\nAlphaBitmap<span style=\"color: #808030;\">.<\/span>dwFlags <span style=\"color: #808030;\">=<\/span> VMR9AlphaBitmap_hDC<span style=\"color: #800080;\">;<\/span>\r\nAlphaBitmap<span style=\"color: #808030;\">.<\/span>hdc <span style=\"color: #808030;\">=<\/span> Dc<span style=\"color: #800080;\">;<\/span>\r\nAlphaBitmap<span style=\"color: #808030;\">.<\/span>rSrc <span style=\"color: #808030;\">=<\/span> <span style=\"color: #603000;\">CRect<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #008c00;\">0<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #008c00;\">0<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #008c00;\">32<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #008c00;\">32<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\nAlphaBitmap<span style=\"color: #808030;\">.<\/span>rDest<span style=\"color: #808030;\">.<\/span>left <span style=\"color: #808030;\">=<\/span> <span style=\"color: #808030;\">(<\/span><span style=\"color: #603000;\">FLOAT<\/span><span style=\"color: #808030;\">)<\/span> <span style=\"color: #008000;\">0.75<\/span><span style=\"color: #800080;\">;<\/span>\r\nAlphaBitmap<span style=\"color: #808030;\">.<\/span>rDest<span style=\"color: #808030;\">.<\/span>top <span style=\"color: #808030;\">=<\/span> <span style=\"color: #808030;\">(<\/span><span style=\"color: #603000;\">FLOAT<\/span><span style=\"color: #808030;\">)<\/span> <span style=\"color: #008000;\">0.75<\/span><span style=\"color: #800080;\">;<\/span>\r\nAlphaBitmap<span style=\"color: #808030;\">.<\/span>rDest<span style=\"color: #808030;\">.<\/span>right <span style=\"color: #808030;\">=<\/span> <span style=\"color: #808030;\">(<\/span><span style=\"color: #603000;\">FLOAT<\/span><span style=\"color: #808030;\">)<\/span> <span style=\"color: #008000;\">0.95<\/span><span style=\"color: #800080;\">;<\/span>\r\nAlphaBitmap<span style=\"color: #808030;\">.<\/span>rDest<span style=\"color: #808030;\">.<\/span>bottom <span style=\"color: #808030;\">=<\/span> <span style=\"color: #808030;\">(<\/span><span style=\"color: #603000;\">FLOAT<\/span><span style=\"color: #808030;\">)<\/span> <span style=\"color: #008000;\">0.95<\/span><span style=\"color: #800080;\">;<\/span>\r\nAlphaBitmap<span style=\"color: #808030;\">.<\/span>fAlpha <span style=\"color: #808030;\">=<\/span> <span style=\"color: #008000;\">0.75<\/span><span style=\"color: #800080;\">;<\/span>\r\n<span style=\"color: #800000; font-weight: bold;\">const<\/span> HRESULT nSetAlphaBitmapResult <span style=\"color: #808030;\">=<\/span> pVmrMixerBitmap<span style=\"color: #808030;\">-<\/span><span style=\"color: #808030;\">&gt;<\/span>SetAlphaBitmap<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">&amp;<\/span>AlphaBitmap<span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\nATLENSURE_SUCCEEDED<span style=\"color: #808030;\">(<\/span>nSetAlphaBitmapResult<span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span><\/pre>\n<p>With a low FPS clip like clock.avi it is clear that the overlaid image is only updated with the next &#8220;main&#8221; video frame.<\/p>\n<p><a href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2009\/09\/21-image002.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1045\" title=\"IVMRMixerBitmap9 Usage Sample\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2009\/09\/21-image002-320x272.png\" alt=\"IVMRMixerBitmap9 Usage Sample\" width=\"320\" height=\"272\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2009\/09\/21-image002-320x272.png 320w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2009\/09\/21-image002.png 408w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><\/a><\/p>\n<p>Visual C++ .NET 2008 source code is <a href=\"http:\/\/code.assembla.com\/roatl-utilities\/subversion\/nodes\/trunk\/VmrMixerBitmapSample01\/\">available from SVN<\/a>, release binary <a href=\"http:\/\/code.assembla.com\/roatl-utilities\/subversion\/nodes\/trunk\/VmrMixerBitmapSample01\/Release\/VmrMixerBitmapSample01.exe?format=raw\">included<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A 100-lines code snippet which illustrates how a bitmap is overlaid over displayed video with Video Mixing Renderer 9 Filter using IVMRMixerBitmap9 interface. A video clip is played (default is Windows clock.avi, but you can replace it with your longer one to see overlay is really in a loop). http:\/\/code.assembla.com\/&#8230;\/VmrMixerBitmapSample01\/&#8230; VMR9AlphaBitmap AlphaBitmap; ZeroMemory(&amp;AlphaBitmap, sizeof AlphaBitmap);&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/1044\">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":[11,13,12,10],"tags":[78,257,137,488,486,111],"class_list":["post-1044","post","type-post","status-publish","format-standard","hentry","category-atl","category-source","category-technology","category-video","tag-directshow","tag-overlay","tag-sample","tag-source","tag-video","tag-vmr"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1044","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=1044"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1044\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=1044"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=1044"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=1044"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}