{"id":1061,"date":"2009-09-30T18:28:08","date_gmt":"2009-09-30T16:28:08","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=1061"},"modified":"2009-09-30T18:28:40","modified_gmt":"2009-09-30T16:28:40","slug":"how-to-dynamically-change-resolution-for-video-preview","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/1061","title":{"rendered":"How to dynamically change resolution for video preview"},"content":{"rendered":"<p>From a conversation:<\/p>\n<blockquote><p><span id=\":1t8\" dir=\"ltr\">Q: I am using Web camera with DirectShow. <\/span>Camera has only capture pin, so I am looking for the best way to switch resolution on the pin while graph is running. I would like to keep preview with smaller image size and when i would like to capture an image i would like to switch to full resolution. I have to use sample grabber callback since i need access to single image to process them. Is there a way to do that without stopping and starting a graph? This works but very slow between captures.<\/p><\/blockquote>\n<p><span id=\":1sb\" dir=\"ltr\">Is it possible to just reconnect the sample grabber only with new media changes and then resume the graph? Currently i just kill the graph and start it again, but it takes few seconds to do so, so I am looking the way to reduce that time.<\/span><\/p>\n<p><span id=\":1rj\" dir=\"ltr\">There is no way to switch resolution on the running graph. There is a technique to dynamically start\/stop individual filters and re-negotiate resolutions (media types), but it does not work for the majority of filters. <\/span><span id=\":1rl\" dir=\"ltr\">Additionally to that <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dd377544%28VS.85%29.aspx\">Sample Grabber <\/a><\/span><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dd377544%28VS.85%29.aspx\"><span id=\":1rl\" dir=\"ltr\">Filter<\/span><\/a><span id=\":1rl\" dir=\"ltr\"><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dd377544%28VS.85%29.aspx\"><\/a> cannot change resolution too, as it passes data through.<\/span><\/p>\n<p><span id=\":1u4\" dir=\"ltr\">If you only have to use switched resolution for preview, you can use <a href=\"http:\/\/www.gdcl.co.uk\/gjd.htm\">Geraint&#8217;s<\/a> <a href=\"http:\/\/www.gdcl.co.uk\/gmfbridge\/index.htm\">GMFBridge Toolkit<\/a> to join two graphs, and a filter that changes resolution. Combining all that you will have a running capture graph that [also] renders video to a bridge sink. <\/span>In the other graph you have another bridge sink that receives video from first graph and then you resize video to the resolution of interest already in the second graph. You can stop and reconfigure only second graph to update resolution and have first graph running and capturing. This is the best you can do, or just stop your single graph and change resolution this simple way.<\/p>\n<p>So a solution, which is used by many, and I can recommend it too, is to use <span id=\":1u4\" dir=\"ltr\"><a href=\"http:\/\/www.gdcl.co.uk\/gmfbridge\/index.htm\">GMFBridge<\/a><\/span> bridging. Additionally, <span id=\":1tv\" dir=\"ltr\">you can find questions and answers on it on <a href=\"http:\/\/social.msdn.microsoft.com\/forums\/en-US\/windowsdirectshowdevelopment\/threads\/?filter=unread\">MSDN DirectShow Development Forum<\/a> (search for &#8220;bridge&#8221; there). W<\/span><span id=\":1tv\" dir=\"ltr\">ith a certain effort you can duplicate this with your own code but this is more or less ready to use solution and<\/span>, again, the key advantage you have that you have two graphs which you can top independently.<\/p>\n<blockquote><p><span id=\":1tc\" dir=\"ltr\">Would it be possible to use smart tee as a splitter on the capture pin, and then use two sample grabbers on capture and preview, one with smaller resolution and the other one with higher one?<\/span><\/p><\/blockquote>\n<p><span id=\":1tt\" dir=\"ltr\">With a <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dd377612%28VS.85%29.aspx\">Smart Tee Filter<\/a> you will still have 1 graph, so no individual resolution changes without stopping the graph. Additionally to that, Smart Tee Filter will deliver same frame on its output pins, so they will have to have one resolution and no resizing takes place inside.<\/span><\/p>\n<blockquote><p><span dir=\"ltr\">Also, <\/span><span id=\":1sg\" dir=\"ltr\">is it possible to run 2 graphs in the same time? Same device, 2 graphs, 2 sample grabbers.<\/span><\/p><\/blockquote>\n<p><span id=\":1u8\" dir=\"ltr\">Most likely no, for only one reason: you won&#8217;t be able to have two running filters for the same device, as source filter will exclusively lock the device.<\/span><span dir=\"ltr\"> <\/span> <span id=\":1tf\" dir=\"ltr\">So capture filter will be a single filter. You can use <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dd390336%28VS.85%29.aspx\">Infinite Tee Pin Filter<\/a> to split stream between 2+ processing lines. And you can use the same bridge to pass data into another graph for further processing.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>From a conversation: Q: I am using Web camera with DirectShow. Camera has only capture pin, so I am looking for the best way to switch resolution on the pin while graph is running. I would like to keep preview with smaller image size and when i would like to capture an image i would&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/1061\">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":[12,10],"tags":[262,162,78,119,260,259,246,261,486],"class_list":["post-1061","post","type-post","status-publish","format-standard","hentry","category-technology","category-video","tag-bridge","tag-capture","tag-directshow","tag-filter","tag-preview","tag-question","tag-resolution","tag-split","tag-video"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1061","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=1061"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1061\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=1061"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=1061"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=1061"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}