<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Fooling Around &#187; Video</title>
	<atom:link href="http://alax.info/blog/tag/video/feed" rel="self" type="application/rss+xml" />
	<link>http://alax.info/blog</link>
	<description>Software Production Line</description>
	<lastBuildDate>Tue, 03 Aug 2010 09:48:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MediaTools: Two samples to capture M-JPEG video into JPEG files and to play JPEG files back</title>
		<link>http://alax.info/blog/1127</link>
		<comments>http://alax.info/blog/1127#comments</comments>
		<pubDate>Thu, 13 May 2010 06:15:48 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Media Tools]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[DirectShow]]></category>
		<category><![CDATA[ip camera]]></category>
		<category><![CDATA[JPEG]]></category>
		<category><![CDATA[M-JPEG]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1127</guid>
		<description><![CDATA[I added two new simple samples for the MediaTools DirectShow filters to demonstrate how to capture M-JPEG video feed, esp. from an IP camera, and write the video frames into sequence of JPEG files. The other sample takes a directory on the input and plays the images back as video. If you are working on [...]]]></description>
			<content:encoded><![CDATA[<p>I added two new simple samples for the MediaTools DirectShow filters to demonstrate how to capture M-JPEG video feed, esp. from an IP camera, and write the video frames into sequence of JPEG files. The other sample takes a directory on the input and plays the images back as video. If you are working on certain transformation filter, it is an easy way to make a reference feed and use it for debugging purposes.</p>
<p>The filters behind that empower the sample are described in <a href="http://alax.info/blog/741">another post</a>.</p>
<p><strong>RenderHttpMjpegVideoIntoFiles01</strong> sample takes an URL on the input to generate <a href="http://www.w3schools.com/media/media_mimeref.asp">image/jpeg JPEG</a> or <a href="http://en.wikipedia.org/wiki/Motion_JPEG">multipart/x-mixed-replace M-JPEG</a> stream. For example, it might be <a href="http://demo1.stardotcams.com/nph-mjpeg.cgi">http://demo1.stardotcams.com/nph-mjpeg.cgi</a> feed from a demo <a href="http://www.stardot.com/">StarDot Technologies</a> IP camera.</p>
<p>The application will create a new directory to write files into, and will save each new video frame received into new JPEG file.</p>
<pre>Z:\MediaTools\Samples\RenderHttpMjpegVideoIntoFiles01\Release&gt;RenderHttpMjpegVideoIntoFiles01.exe http://demo1.stardotcams.com/nph-mjpeg.cgi
URL: http://demo1.stardotcams.com/nph-mjpeg.cgi
Writing to directory: Z:\MediaTools\Samples\RenderHttpMjpegVideoIntoFiles01\Release\2010-05-12 22-07-37
Event: nCode EC_CLOCK_CHANGED 0xD, nParameter1 0x00000000, nParameter2 0x00000000
Event: nCode EC_PAUSED 0xE, nResult 0x00000000, nParameter2 0x00000000
[...]
^C</pre>
<p>The application will generate the files and convert media sample time stamps into file time.</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2010/05/13-Image001.png"><img class="alignnone size-medium wp-image-1128" title="RenderHttpMjpegVideoIntoFiles01 Sample Output" src="http://alax.info/blog/wp-content/uploads/2010/05/13-Image001-320x175.png" alt="RenderHttpMjpegVideoIntoFiles01 Sample Output" width="320" height="175" /></a></p>
<p>The DirectShow graph that implements the operation is the following:</p>
<p><img class="alignnone size-full wp-image-1129" title="RenderHttpMjpegVideoIntoFiles01 Filter Graph" src="http://alax.info/blog/wp-content/uploads/2010/05/13-Image002.png" alt="RenderHttpMjpegVideoIntoFiles01 Filter Graph" width="661" height="346" /></p>
<p>The other sample <strong>RenderJpegFiles01</strong> takes a directory path to look for JPEG files, e.g. generated by previous sample, and pushes them into DirectShow graph as a video feed. File times will be converted [back] to media sample times.</p>
<p><span id="more-1127"></span></p>
<pre>Z:\MediaTools\Samples\RenderJpegFiles01\Release&gt;RenderJpegFiles01 "Z:\MediaTools\Samples\RenderHttpMjpegVideoIntoFiles01\Release\2010-05-12 22-07-37"
Directory: Z:\MediaTools\Samples\RenderHttpMjpegVideoIntoFiles01\Release\2010-05-12 22-07-37
Event: nCode EC_CLOCK_CHANGED 0xD, nParameter1 0x00000000, nParameter2 0x00000000
Event: nCode EC_PAUSED 0xE, nResult 0x00000000, nParameter2 0x00000000
Event: nCode EC_VMR_RECONNECTION_FAILED 0x55, nResult 0x80004005, nParameter2 0x00000000
Event: nCode EC_VMR_RENDERDEVICE_SET 0x53, RendererDeviceType 0x2, nParameter2 0x00000000
Event: nCode EC_VIDEO_SIZE_CHANGED 0xA, Extent 384x240, nParameter2 0x00000000
Event: nCode EC_COMPLETE 0x1, nResult 0x00000000, nParameter2 0x00000000
Event: nCode EC_ERRORABORT 0x3, nResult 0x80004005, nParameter2 0x00000000
Detected resolution change, new resolution is 1024x768, recreating filter graph...
Event: nCode EC_VMR_RECONNECTION_FAILED 0x55, nResult 0x80004005, nParameter2 0x00000000
Event: nCode EC_VMR_RENDERDEVICE_SET 0x53, RendererDeviceType 0x2, nParameter2 0x00000000
Event: nCode EC_VIDEO_SIZE_CHANGED 0xA, Extent 384x240, nParameter2 0x00000000
Event: nCode EC_CLOCK_CHANGED 0xD, nParameter1 0x00000000, nParameter2 0x00000000
Event: nCode EC_PAUSED 0xE, nResult 0x00000000, nParameter2 0x00000000</pre>
<p><a href="http://alax.info/blog/wp-content/uploads/2010/05/13-Image003.png"><img class="alignnone size-medium wp-image-1130" title="RenderJpegFiles01 DirectShow Graph and Output" src="http://alax.info/blog/wp-content/uploads/2010/05/13-Image003-312x320.png" alt="RenderJpegFiles01 DirectShow Graph and Output" width="312" height="320" /></a></p>
<p>Download links:</p>
<ul>
<li>RenderHttpMjpegVideoIntoFiles01: <a href="http://www.assembla.com/code/roatl-utilities/subversion/nodes/trunk/MediaTools/Samples/RenderHttpMjpegVideoIntoFiles01">source code</a>, <a href="http://www.assembla.com/code/roatl-utilities/subversion/nodes/trunk/MediaTools/Samples/RenderHttpMjpegVideoIntoFiles01/Release/RenderHttpMjpegVideoIntoFiles01.exe?format=raw">binary</a></li>
<li>RenderJpegFiles01: <a href="http://www.assembla.com/code/roatl-utilities/subversion/nodes/trunk/MediaTools/Samples/RenderJpegFiles01">source code</a>, <a href="http://www.assembla.com/code/roatl-utilities/subversion/nodes/trunk/MediaTools/Samples/RenderJpegFiles01/Release/RenderJpegFiles01.exe?format=raw">binary</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1127/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to use windowless Video Mixing Renderer Filter to show video fullscreen</title>
		<link>http://alax.info/blog/1082</link>
		<comments>http://alax.info/blog/1082#comments</comments>
		<pubDate>Fri, 09 Oct 2009 17:04:27 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[WTL]]></category>
		<category><![CDATA[DirectShow]]></category>
		<category><![CDATA[fullscreen]]></category>
		<category><![CDATA[IVideoWidow]]></category>
		<category><![CDATA[IVMRWindowlessControl]]></category>
		<category><![CDATA[renderer]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[VMR]]></category>
		<category><![CDATA[windowless]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1082</guid>
		<description><![CDATA[The question is being asked from time to time. Everyone knows what is full screen video. Video renderers implement full screen capability since long ago through their IVideoWindow::put_FullScreenMode property, and even Filter Graph Manager exposes its own IVideoWindow interface to forward calls to filter&#8217;s implementation of IVideoWindow interface.
However, for Video Mixing Renderers, version 7 and [...]]]></description>
			<content:encoded><![CDATA[<p>The question is being asked from time to time. Everyone knows what is full screen video. Video renderers implement full screen capability since long ago through their <a href="http://msdn.microsoft.com/en-us/library/dd377320(VS.85).aspx">IVideoWindow::put_FullScreenMode</a> property, and even <a href="http://msdn.microsoft.com/en-us/library/dd375786(VS.85).aspx">Filter Graph Manager</a> exposes its own <a href="http://msdn.microsoft.com/en-us/library/dd377276%28VS.85%29.aspx">IVideoWindow</a> interface to forward calls to filter&#8217;s implementation of <a href="http://msdn.microsoft.com/en-us/library/dd377276%28VS.85%29.aspx">IVideoWindow</a> interface.</p>
<p>However, for Video Mixing Renderers, version <a href="http://msdn.microsoft.com/en-us/library/dd407343(VS.85).aspx">7</a> and <a href="http://msdn.microsoft.com/en-us/library/dd407344%28VS.85%29.aspx">9</a>, the preferred and recommended mode is windowless, where no IVideoWindow interface is available.</p>
<blockquote><p><strong>Note</strong> The <a id="ctl00_MTCS_main_ctl01" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl01',this);" href="http://msdn.microsoft.com/en-us/library/dd390536%28VS.85%29.aspx"><strong>IVMRWindowlessControl</strong></a> or <a id="ctl00_MTCS_main_ctl02" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl02',this);" href="http://msdn.microsoft.com/en-us/library/dd390537%28VS.85%29.aspx"><strong>IVMRWindowlessControl9</strong></a> interface is now preferred over <strong>IVideoWindow</strong>. For more information, see <a id="ctl00_MTCS_main_ctl03" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl03',this);" href="http://msdn.microsoft.com/en-us/library/dd407299%28VS.85%29.aspx">Using Windowless Mode</a>.</p></blockquote>
<p>So in order to implement full screen mode it takes the application to attach Video Mixing Renderer filter to a private frameless window, to its entire client area and expand the window to entire monitor area.</p>
<p>The sample project <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FullScreenWindowlessVmrSample01">FullScreenWindowlessVmrSample01</a> is illustrating this technique.</p>
<p><img class="alignnone size-full wp-image-1083" title="FullScreenWindowlessVmrSample01 Main Dialog" src="http://alax.info/blog/wp-content/uploads/2009/10/09-Image001.png" alt="FullScreenWindowlessVmrSample01 Main Dialog" width="489" height="141" /></p>
<p><span id="more-1082"></span>Main application dialog owns a special window to host renderer, implemented by CRendererDialog class.</p>
<pre>
<pre style="background: #ffffff none repeat scroll 0% 0%; color: #000000;"><span style="color: #800000; font-weight: bold;">class</span> CRendererDialog <span style="color: #800080;">:</span>
    <span style="color: #800000; font-weight: bold;">public</span> CDialogImpl<span style="color: #800080;">&lt;</span>CRendererDialog<span style="color: #800080;">&gt;</span>
<span style="color: #800080;">{</span>
<span style="color: #800000; font-weight: bold;">public</span><span style="color: #e34adc;">:</span>

    <span style="color: #800000; font-weight: bold;">enum</span> <span style="color: #800080;">{</span> IDD <span style="color: #808030;">=</span> IDD_RENDERER <span style="color: #800080;">}</span><span style="color: #800080;">;</span>

BEGIN_MSG_MAP_EX<span style="color: #808030;">(</span>CRendererDialog<span style="color: #808030;">)</span>
    MSG_WM_INITDIALOG<span style="color: #808030;">(</span>OnInitDialog<span style="color: #808030;">)</span>
    MSG_WM_DESTROY<span style="color: #808030;">(</span>OnDestroy<span style="color: #808030;">)</span>
    MSG_WM_ERASEBKGND<span style="color: #808030;">(</span><span style="color: #400000;">OnEraseBkgnd</span><span style="color: #808030;">)</span>
    MSG_WM_PAINT<span style="color: #808030;">(</span>OnPaint<span style="color: #808030;">)</span>
    MSG_WM_DISPLAYCHANGE<span style="color: #808030;">(</span>OnDisplayChange<span style="color: #808030;">)</span>
    MSG_WM_KEYDOWN<span style="color: #808030;">(</span>OnKeyDown<span style="color: #808030;">)</span>
    COMMAND_ID_HANDLER_EX<span style="color: #808030;">(</span>IDCANCEL<span style="color: #808030;">,</span> OnCancel<span style="color: #808030;">)</span>
END_MSG_MAP<span style="color: #808030;">(</span><span style="color: #808030;">)</span>

<span style="color: #800000; font-weight: bold;">private</span><span style="color: #e34adc;">:</span>
    CMainDialog<span style="color: #808030;">&amp;</span> m_Owner<span style="color: #800080;">;</span>
<span style="color: #696969;">//...</span></pre>
</pre>
<p>The dialog template does not have a caption, it has no frame and has its window rectangle equal to client area. As a result, spanning the Video Mixing Renderer to the entire client area and proper positioning of the dialog window is showing video on the entire monitor.</p>
<pre>
<pre style="background: #ffffff none repeat scroll 0% 0%; color: #000000;">ATLVERIFY<span style="color: #808030;">(</span>m_RendererDialog<span style="color: #808030;">.</span>Create<span style="color: #808030;">(</span>m_hWnd<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLVERIFY<span style="color: #808030;">(</span>m_RendererDialog<span style="color: #808030;">.</span><span style="color: #400000;">MoveWindow</span><span style="color: #808030;">(</span>MonitorData<span style="color: #808030;">.</span>m_Position<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
m_RendererDialog<span style="color: #808030;">.</span><span style="color: #400000;">ShowWindow</span><span style="color: #808030;">(</span>SW_SHOWNORMAL<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #696969;">// ...</span>
ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>pVmrWindowlessControl<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>SetVideoClippingWindow<span style="color: #808030;">(</span>m_RendererDialog<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>pVmrWindowlessControl<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>SetVideoPosition<span style="color: #808030;">(</span><span style="color: #7d0045;">NULL</span><span style="color: #808030;">,</span> m_RendererDialog<span style="color: #808030;">.</span>GetVideoPosition<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span></pre>
</pre>
<p>Visual C++ .NET 2008 source code is <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FullScreenWindowlessVmrSample01">available from SVN</a>, release binary <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FullScreenWindowlessVmrSample01/Release/FullScreenWindowlessVmrSample01.exe?format=raw">included</a>. The project is using ATL and <a href="http://wtl.sourceforge.net/">WTL</a> libraries.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1082/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to make a constant frame rate video stream from variable frame rate stream, and rescale it</title>
		<link>http://alax.info/blog/1080</link>
		<comments>http://alax.info/blog/1080#comments</comments>
		<pubDate>Thu, 08 Oct 2009 16:51:15 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[DirectShow]]></category>
		<category><![CDATA[fps]]></category>
		<category><![CDATA[frame rate]]></category>
		<category><![CDATA[resolution]]></category>
		<category><![CDATA[time stamp]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1080</guid>
		<description><![CDATA[From a conversation:
I have a  video stream with variable frame rate, I want to make this in to a constant  frame rate. Do you know of any filters that could help me with this?
Such filter is actually quite easy. You only need to update time stamps of the media samples that are going through. [...]]]></description>
			<content:encoded><![CDATA[<p>From a conversation:</p>
<blockquote><p>I have a  video stream with variable frame rate, I want to make this in to a constant  frame rate. Do you know of any filters that could help me with this?</p></blockquote>
<p>Such filter is actually quite easy. You only need to update time stamps of the media samples that are going through. I am not aware of  an &#8220;out of the box&#8221; ready filter, but you can even do it without special filter: if you build your graph with <a href="http://msdn.microsoft.com/en-us/library/dd377544%28VS.85%29.aspx">Sample Grabber Filter</a> in it in  the place of interest, and initialize it to have a callback for each sample, then in <a href="http://msdn.microsoft.com/en-us/library/dd376987%28VS.85%29.aspx">SampleCB</a> method you will be able to update time stamps using methods of <a href="http://msdn.microsoft.com/en-us/library/dd407001%28VS.85%29.aspx">IMediaSample</a> interface. This is sufficient to redistribute the frames on the timeline, so that they go at constant frame rate.</p>
<blockquote><p>In your opinion what is the best way to scale the video?</p></blockquote>
<p>The best depends on what is the criteria (speed, quality etc). The simplest for me while very efficient &#8211; and I did this a number of times &#8211; is to use a custom filter which inside it uses <a href="http://msdn.microsoft.com/en-us/library/dd145120%28VS.85%29.aspx">StretchBlt</a> <a href="http://msdn.microsoft.com/en-us/library/dd145120%28VS.85%29.aspx" target="_blank"></a> function on a per frame basis to scale input RGB video into output RGB video of a different resolution.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1080/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MediaTools: Fix for Motion JPEG video</title>
		<link>http://alax.info/blog/1073</link>
		<comments>http://alax.info/blog/1073#comments</comments>
		<pubDate>Tue, 06 Oct 2009 19:16:29 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Media Tools]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[JPEG]]></category>
		<category><![CDATA[M-JPEG]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1073</guid>
		<description><![CDATA[A small fix for M-JPEG video streams retrieved by HTTP Stream Source Filter:

Username and password contained in URL are honored for Basic HTTP authentication
Correctly parsed HTTP response headers with quotes, e.g.:
Content-Type: multipart/x-mixed-replace; boundary=&#8220;myboundary&#8220;

Partial Visual C++ .NET 2008 source code is available from SVN, release binary included.
]]></description>
			<content:encoded><![CDATA[<p>A small fix for <a href="http://en.wikipedia.org/wiki/Motion_JPEG">M-JPEG</a> video streams retrieved by <a href="http://alax.info/blog/741">HTTP Stream Source Filter</a>:</p>
<ul>
<li>Username and password contained in URL are honored for <a href="http://en.wikipedia.org/wiki/Basic_access_authentication">Basic HTTP authentication</a></li>
<li>Correctly parsed HTTP response headers with quotes, e.g.:<br />
<em>Content-Type: multipart/x-mixed-replace; boundary=<strong><span style="color: #ff0000;">&#8220;</span></strong>myboundary<strong><span style="color: #ff0000;">&#8220;</span></strong></em></li>
</ul>
<p>Partial Visual C++ .NET 2008 source code is <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/MediaTools/">available from SVN</a>, release binary <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/MediaTools/_Bin/Release Trace">included</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1073/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>DirectShow Related Bugs: MediaLooks MPEG-2 Video Decoder, Haali Media Splitter (AR)</title>
		<link>http://alax.info/blog/1064</link>
		<comments>http://alax.info/blog/1064#comments</comments>
		<pubDate>Sat, 03 Oct 2009 06:50:03 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[decoder]]></category>
		<category><![CDATA[DirectShow]]></category>
		<category><![CDATA[filters]]></category>
		<category><![CDATA[haali]]></category>
		<category><![CDATA[medialooks]]></category>
		<category><![CDATA[message]]></category>
		<category><![CDATA[protection]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1064</guid>
		<description><![CDATA[An attempt to render media file in GraphStudio ended up with an error message:
Protection
A monitor program has been foun drunning in your system. Please unload it from memory and restart your program.
The module which popped up the message chose to not identify itself in a friendly manner, however as nothing goes untraceable it appeared to [...]]]></description>
			<content:encoded><![CDATA[<p>An attempt to render media file in <a href="http://blog.monogram.sk/janos/tools/monogram-graphstudio/">GraphStudio</a> ended up with an error message:</p>
<blockquote><p>Protection<br />
A monitor program has been foun drunning in your system. Please unload it from memory and restart your program.</p></blockquote>
<p>The module which popped up the message chose to not identify itself in a friendly manner, however as nothing goes untraceable it appeared to be <a href="http://www.medialooks.com">MediaLooks</a> MPEG-2 Video Decoder file, Mpeg2DecoderL.dll (version 1.0.3.9). As the message was popped up from a non-GUI thread, there was no way to close the box &#8211; the entire application froze&#8230;</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2009/10/03-Image001.png"><img class="alignnone size-medium wp-image-1065" title="MediaLooks MPEG-2 Video Decoder Error Message" src="http://alax.info/blog/wp-content/uploads/2009/10/03-Image001-320x166.png" alt="MediaLooks MPEG-2 Video Decoder Error Message" width="320" height="166" /></a></p>
<p>The problem does not happen in <a href="http://msdn.microsoft.com/en-us/library/dd390950%28VS.85%29.aspx">GraphEdit</a>, as the decoder is probably handling this case specifically.</p>
<p>The decoder has an deinstallation batch file located in application directory: C:\Program Files\MediaLooks\Mpeg2Decoder\Uninstall.bat. A curious thing, however, is that running this file in attempt to uninstall the decoder shows the same problem: the decoder refuses to be uninstalled due to mystic &#8220;monitor program&#8221; running in the system:</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2009/10/03-Image002.png"><img class="alignnone size-medium wp-image-1066" title="MediaLooks MPEG-2 Video Decoder Deinstallation Failure" src="http://alax.info/blog/wp-content/uploads/2009/10/03-Image002-320x96.png" alt="MediaLooks MPEG-2 Video Decoder Deinstallation Failure" width="320" height="96" /></a></p>
<p>After closing the message box the application still continues deinstallation script and removes the decoder from system.</p>
<p>Another issue for this file (and hopefully for today) is that another filter <a href="http://haali.cs.msu.ru/mkv/">Haali Media Splitter (AR)</a> (splitter.ax, version 1.9.42.1) is crashing the hosting process on being removed from the graph.</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2009/10/03-Image003.png"><img class="alignnone size-medium wp-image-1067" title="Haali Media Splitter Crash" src="http://alax.info/blog/wp-content/uploads/2009/10/03-Image003-320x172.png" alt="Haali Media Splitter Crash" width="320" height="172" /></a> <a href="http://alax.info/blog/wp-content/uploads/2009/10/03-Image004.png"><img class="alignnone size-medium wp-image-1068" title="Haali Media Splitter Crash" src="http://alax.info/blog/wp-content/uploads/2009/10/03-Image004-320x122.png" alt="Haali Media Splitter Crash" width="320" height="122" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1064/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to dynamically change resolution for video preview</title>
		<link>http://alax.info/blog/1061</link>
		<comments>http://alax.info/blog/1061#comments</comments>
		<pubDate>Wed, 30 Sep 2009 16:28:08 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[bridge]]></category>
		<category><![CDATA[capture]]></category>
		<category><![CDATA[DirectShow]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[preview]]></category>
		<category><![CDATA[question]]></category>
		<category><![CDATA[resolution]]></category>
		<category><![CDATA[split]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1061</guid>
		<description><![CDATA[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 like [...]]]></description>
			<content:encoded><![CDATA[<p>From a conversation:</p>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1061/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to overlay a bitmap on top of video with Video Mixing Renderer (VMR-9)</title>
		<link>http://alax.info/blog/1044</link>
		<comments>http://alax.info/blog/1044#comments</comments>
		<pubDate>Mon, 21 Sep 2009 17:01:25 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[DirectShow]]></category>
		<category><![CDATA[overlay]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[VMR]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1044</guid>
		<description><![CDATA[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(&#38;AlphaBitmap, sizeof AlphaBitmap);
AlphaBitmap.dwFlags = VMR9AlphaBitmap_hDC;
AlphaBitmap.hdc = [...]]]></description>
			<content:encoded><![CDATA[<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>
<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>
<pre>VMR9AlphaBitmap AlphaBitmap<span style="color: #800080;">;</span>
<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>
AlphaBitmap<span style="color: #808030;">.</span>dwFlags <span style="color: #808030;">=</span> VMR9AlphaBitmap_hDC<span style="color: #800080;">;</span>
AlphaBitmap<span style="color: #808030;">.</span>hdc <span style="color: #808030;">=</span> Dc<span style="color: #800080;">;</span>
AlphaBitmap<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>
AlphaBitmap<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>
AlphaBitmap<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>
AlphaBitmap<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>
AlphaBitmap<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>
AlphaBitmap<span style="color: #808030;">.</span>fAlpha <span style="color: #808030;">=</span> <span style="color: #008000;">0.75</span><span style="color: #800080;">;</span>
<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>
ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>nSetAlphaBitmapResult<span style="color: #808030;">)</span><span style="color: #800080;">;</span></pre>
<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>
<p><a href="http://alax.info/blog/wp-content/uploads/2009/09/21-image002.png"><img class="alignnone size-medium wp-image-1045" title="IVMRMixerBitmap9 Usage Sample" src="http://alax.info/blog/wp-content/uploads/2009/09/21-image002-320x272.png" alt="IVMRMixerBitmap9 Usage Sample" width="320" height="272" /></a></p>
<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>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1044/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Media Codec List</title>
		<link>http://alax.info/blog/1025</link>
		<comments>http://alax.info/blog/1025#comments</comments>
		<pubDate>Fri, 28 Aug 2009 16:58:47 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Audio]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[WTL]]></category>
		<category><![CDATA[codec]]></category>
		<category><![CDATA[utility]]></category>
		<category><![CDATA[windows media]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1025</guid>
		<description><![CDATA[Windows Media Codec List utility uses IWMCodecInfo interface (see also IWMCodecInfo2, IWMCodecInfo3) lists installed Windows Media Codecs and their formats and presents the findings in a convenient way. The utility gives a quick idea what a programmer would obtain through IWMCodecInfo2/IWMCodecInfo3 interfaces and what well known format structures (WM_MEDIA_TYPE, AM_MEDIA_TYPE, WAVEFORMATEX, VIDEOINFOHEADER) correspond to particular [...]]]></description>
			<content:encoded><![CDATA[<p>Windows Media Codec List utility uses <a href="http://msdn.microsoft.com/en-us/library/dd743313%28VS.85%29.aspx">IWMCodecInfo</a> interface (see also <a href="http://msdn.microsoft.com/en-us/library/dd743314(VS.85).aspx">IWMCodecInfo2</a>, <a href="http://msdn.microsoft.com/en-us/library/dd743317(VS.85).aspx">IWMCodecInfo3</a>) lists installed <a href="http://www.microsoft.com/windows/windowsmedia/default.mspx">Windows Media</a> Codecs and their formats and presents the findings in a convenient way. The utility gives a quick idea what a programmer would obtain through <a href="http://msdn.microsoft.com/en-us/library/dd743314(VS.85).aspx">IWMCodecInfo2</a>/<a href="http://msdn.microsoft.com/en-us/library/dd743317(VS.85).aspx">IWMCodecInfo3</a> interfaces and what well known format structures (<a href="http://msdn.microsoft.com/en-us/library/dd757963%28VS.85%29.aspx">WM_MEDIA_TYPE</a>, <a href="http://msdn.microsoft.com/en-us/library/dd373477%28VS.85%29.aspx">AM_MEDIA_TYPE</a>, <a href="http://msdn.microsoft.com/en-us/library/dd757720%28VS.85%29.aspx">WAVEFORMATEX</a>, <a href="http://msdn.microsoft.com/en-us/library/dd407325%28VS.85%29.aspx">VIDEOINFOHEADER</a>) correspond to particular format.</p>
<p>For a description of Windows Media video and audio codecs, check article <a href="http://www.microsoft.com/windows/windowsmedia/howto/articles/codecs.aspx">Encoding Audio and Video with Windows Media Codecs</a>.</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2009/08/28-image001.png"><img class="size-medium wp-image-1024 alignnone" title="Windows Media Codec List Screenshot" src="http://alax.info/blog/wp-content/uploads/2009/08/28-image001-320x171.png" alt="Windows Media Codec List Screenshot" width="320" height="171" /></a></p>
<p>Copy button copies discovered information into clipboard in comma-separated values (CSV) format (e.g. suitable fo rMicrosoft Excel). Submit button posts the same information to this website for&#8230; possibly further aggregation.</p>
<p>Some quick facts immediately visualized by the utility:</p>
<ul>
<li>for a video codec there is exactly one generic codec format listed</li>
<li>video codec FOUCCs are: WM Video &#8211; WMV1, WMV2, WMV3; WM Video Screen &#8211; MSS1, MSS2; WM Video Image &#8211; WMVP, WVP2; WM Video Advanced Profile &#8211; WVC1</li>
<li>for audio codecs there are complete codec formats enumerated, with names/descriptions suitable for GUI</li>
<li>audio codecs enumerate different formats in response to enumeration settings (e.g. request for VBR formats)</li>
<li>WM Audio Lossless only lists formats for single pass VBR mode</li>
<li>audio format tags (wFormatTag) are: WM Audio including Professional and Lossless &#8211; 0&#215;0161, 0&#215;0162, 0&#215;0163; WM Audio Voice &#8211; 0&#215;000A; ACELP.net &#8211; 0&#215;0130</li>
</ul>
<p>Partial Visual C++ .NET 2008 source code is <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/WindowsMediaCodecList">available from SVN</a>, release binary <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/WindowsMediaCodecList/Release/WindowsMediaCodecList.exe?format=raw">included</a>.</p>
<p><span id="more-1025"></span>See also:</p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/VC-1">VC-1 on Wikipedia</a>:</li>
<li>
<blockquote><p><strong>WMV3</strong></p>
<p>Simple and Main Profiles of VC-1 remained completely faithful to the existing WMV3 implementation, making WMV3 bitstreams fully VC-1 compliant. The WMV3 codec was designed to primarily support progressive encoding for computer displays. An interlaced encoding mode was implemented, but quickly became deprecated when Microsoft started implementing WMV Advanced Profile. Whereas WMV3 progressive encoding was implemented in the YUV 4:2:0 color space, the deprecated interlaced mode was implemented in the less common YUV 4:1:1 color space.</p>
<p>The Windows Media Video 9 (WMV3) codec implements the Simple and Main modes of the VC-1 codec standard, providing high-quality video for streaming and downloading. &#8220;It provides support for a wide range of bit rates, from high-definition content at one-half to one-third the bit rate of MPEG-2, to low-bit-rate Internet video delivered over a dial-up modem. This codec also supports professional-quality downloadable video with two-pass and variable bit rate (VBR) encoding. Windows Media Video 9 is already supported by a wide variety of players and devices.&#8221;[citation needed]</p>
<p>A number of high definition movies and videos have been released commercially in a format dubbed WMV HD. These titles are encoded with WMV3 Main Profile @ High Level (MP@HL).</p>
<p>[...]</p>
<p><strong>WVC1</strong></p>
<p>WVC1, also known as Windows Media Video 9 Advanced Profile, implements a more recent and fully compliant Advanced Profile of the VC-1 codec standard. It offers support for interlaced content and is transport independent. With the previous version of the Windows Media Video 9 Series codec, users could deliver progressive content at data rates as low as one-third that of the MPEG-2 codec and still get equivalent or comparable quality to MPEG-2. The Windows Media Video 9 Advanced Profile codec also offers this same improvement in encoding efficiency with interlaced contents. A decoder for WVC1 is included in Windows Media Player 11, which is bundled with Windows Vista and is <a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=1d224714-e238-4e45-8668-5166114010ca">available as a download for Windows XP</a>.</p></blockquote>
</li>
<li><a href="http://en.wikipedia.org/wiki/Windows_Media_Audio">Windows Media Audio on Wikipedia</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1025/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MediaTools: How to manually configure filters to render M-JPEG video stream from an IP camera</title>
		<link>http://alax.info/blog/1006</link>
		<comments>http://alax.info/blog/1006#comments</comments>
		<pubDate>Wed, 05 Aug 2009 06:48:46 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Media Tools]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[camera]]></category>
		<category><![CDATA[DirectShow]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[JPEG]]></category>
		<category><![CDATA[M-JPEG]]></category>
		<category><![CDATA[mediatools]]></category>
		<category><![CDATA[sample]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1006</guid>
		<description><![CDATA[Media Tools DirectShow Filters can be used to acquire, parse and decoder M-JPEG encoded video stream from an IP camera or a video server, however for a quick start it is necessary to properly register filters on system and create a DirectShow graph.
To register the filters, it is necessary to download DLLs from repository. While [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://alax.info/blog/category/utilities/media-tools">Media Tools</a> DirectShow Filters can be used to acquire, parse and decoder M-JPEG encoded video stream from an IP camera or a video server, however for a quick start it is necessary to properly register filters on system and create a DirectShow graph.</p>
<p>To register the filters, it is necessary to download DLLs from <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/MediaTools/_Bin">repository</a>. While Acquisition.dll does not require special prerequisites installed, CodingI.dll is using <a href="http://software.intel.com/en-us/intel-ipp/">Intel Integrated Performance Primitives</a> (IPP) version 6.0.0 internally and requires its [at least] redistributables installed before DLLs are being registered using regsvr32.</p>
<p>Intel went further with new releases of IPP, which are incompatible with the version used to build CodingI.dll, so it is version 6.0.0 (in downloads on  Intel website: version 6.0 build 0) has to be installed. Note that Intel DLLs from <em>C:\Program Files\Intel\IPP\6.0.0.044\ia32\bin</em> (version 6.0.0.062 is known to be also compatible) need to be on system search path, or copied to <em>C:\Windows\system32</em> directory.</p>
<p>Once Intel IPP is prepared, it is required to register CodingI.dll using regsvr32. This registers filters and they are available in GraphEdit and for applications. It is important that on the way of constructing graph which renders video using standard video renderers it is required to specify correct resolution for video, or otherwise graph might fail to start with a message &#8220;The graph could not change state&#8221;, caused by video renderer failure to dynamically change to different (effective) resolution.</p>
<p>To create rendering graph, add Alax.Info HTTP Stream Source Filter from the filter list and provide camera URL in properties, e.g. <a href="http://cam15001.miemasu.net/nphMotionJPEG?Kind=1">http://cam15001.miemasu.net/nphMotionJPEG?Kind=1</a></p>
<p><a href="http://alax.info/blog/wp-content/uploads/2009/08/03-image001.png"><img class="alignnone size-medium wp-image-1007" title="Adding Alax.Info HTTP Stream Source Filter" src="http://alax.info/blog/wp-content/uploads/2009/08/03-image001-320x151.png" alt="Adding Alax.Info HTTP Stream Source Filter" width="320" height="151" /></a></p>
<p><span id="more-1006"></span>Add more filters and provide proper resolution for video:</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2009/08/03-image002.png"><img class="alignnone size-medium wp-image-1008" title="Alax.Info JPEG Frame Decoder Filter" src="http://alax.info/blog/wp-content/uploads/2009/08/03-image002-320x151.png" alt="Alax.Info JPEG Frame Decoder Filter" width="320" height="151" /></a></p>
<p>Complete graph construction with resolution set up:</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2009/08/03-image003.png"><img class="alignnone size-medium wp-image-1009" title="Render Alax.Info JPEG Decoder Filter output pin" src="http://alax.info/blog/wp-content/uploads/2009/08/03-image003-320x151.png" alt="Render Alax.Info JPEG Decoder Filter output pin" width="320" height="151" /></a></p>
<p>Being run, the graph shows video:</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2009/08/03-image004.png"><img class="alignnone size-medium wp-image-1010" title="Video from cam15001.miemasu.net camera through Alax.Info DirectShow filters" src="http://alax.info/blog/wp-content/uploads/2009/08/03-image004-320x151.png" alt="Video from cam15001.miemasu.net camera through Alax.Info DirectShow filters" width="320" height="151" /></a></p>
<p>Dynamic handling of resolution selection, configuration and change is also illustrated in sample application <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/MediaTools/Samples/RenderHttpMjpegVideo01">RenderHttpMjpegVideo01</a>.</p>
<p>NOTE: The constructed graph .GRF file is <a href="http://alax.info/blog/wp-content/uploads/2009/08/cam15001miemasunet.grf">available for download</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1006/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XviD video encoder and window messages from a worker thread</title>
		<link>http://alax.info/blog/1000</link>
		<comments>http://alax.info/blog/1000#comments</comments>
		<pubDate>Fri, 31 Jul 2009 07:17:07 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Seriously]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[compression]]></category>
		<category><![CDATA[deadlock]]></category>
		<category><![CDATA[encoder]]></category>
		<category><![CDATA[message]]></category>
		<category><![CDATA[MsgWaitForMultipleObjects]]></category>
		<category><![CDATA[PostMessage]]></category>
		<category><![CDATA[SendMessage]]></category>
		<category><![CDATA[synchronization]]></category>
		<category><![CDATA[windowing]]></category>
		<category><![CDATA[XviD]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1000</guid>
		<description><![CDATA[While encoding video, Xvid Video Encoder provides an optional status window displaying information on encoding progress.

Since streaming typically takes place in a worker thread, with possibly no windows at all, and no message pump, the window is to be created on GUI thread and the encoder needs to synchronize progress updates with the window.
Such synchronization [...]]]></description>
			<content:encoded><![CDATA[<p>While encoding video, <a href="http://www.xvid.org/">Xvid Video Encoder</a> provides an optional status window displaying information on encoding progress.</p>
<p><img class="alignnone size-full wp-image-1001" title="Xvid Encoder Status Window" src="http://alax.info/blog/wp-content/uploads/2009/07/31-image001.png" alt="Xvid Encoder Status Window" width="494" height="385" /></p>
<p>Since streaming typically takes place in a worker thread, with possibly no windows at all, and no message pump, the window is to be created on GUI thread and the encoder needs to synchronize progress updates with the window.</p>
<p>Such synchronization is a typical point where a deadlock can occur. Carelessly a window message may be sent in a blocking way so that worker thread is waiting while the message is processed on the window thread. If this sending happens at the moment of GUI thread trying to stop worker thread, a deadlock takes place. This problem often comes up when message sending takes place indirectly, e.g. being wrapped by an API call, such as <a href="http://msdn.microsoft.com/en-us/library/ms633546%28VS.85%29.aspx">SetWindowText</a>, or as it can be seen below <a href="http://msdn.microsoft.com/en-us/library/bb761879%28VS.85%29.aspx">IsDlgButtonChecked</a>.</p>
<p>In order to avoid deadlocks one should never <a href="http://msdn.microsoft.com/en-us/library/ms644950%28VS.85%29.aspx">SendMessage</a> from a worker thread. Instead there should be a <a href="http://msdn.microsoft.com/en-us/library/ms644944%28VS.85%29.aspx">PostMessage</a> with possibly a wait function which waits for either synchronization event (set by window) or worker thread termination request:</p>
<pre><span style="color: #800080;">{</span>
  CLock Lock<span style="color: #808030;">(</span>m_CriticalSection<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
  m_sText <span style="color: #808030;">=</span> sText<span style="color: #800080;">;</span>
  m_SynchronizationEvent<span style="color: #808030;">.</span>Reset<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #800080;">}</span>
<span style="color: #400000;">PostMessage</span><span style="color: #808030;">(</span><span style="color: #808030;">.</span><span style="color: #808030;">.</span><span style="color: #808030;">.</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #603000;">HANDLE</span> phObjects<span style="color: #808030;">[</span><span style="color: #808030;">]</span> <span style="color: #808030;">=</span> <span style="color: #800080;">{</span> ThreadTerminationEvent<span style="color: #808030;">,</span> m_SynchronizationEvent <span style="color: #800080;">}</span><span style="color: #800080;">;</span>
<span style="color: #800000; font-weight: bold;">const</span> <span style="color: #603000;">DWORD</span> nWaitResult <span style="color: #808030;">=</span>  <span style="color: #400000;">WaitForMultipleObjects</span><span style="color: #808030;">(</span><span style="color: #808030;">.</span><span style="color: #808030;">.</span><span style="color: #808030;">.</span><span style="color: #808030;">,</span> phObjects<span style="color: #808030;">,</span> <span style="color: #808030;">.</span><span style="color: #808030;">.</span><span style="color: #808030;">.</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #800000; font-weight: bold;">if</span><span style="color: #808030;">(</span>nWaitResult <span style="color: #808030;">=</span><span style="color: #808030;">=</span> WAIT_OBJECT_0 <span style="color: #808030;">+</span> <span style="color: #008c00;">1</span> <span style="color: #808030;">)</span> <span style="color: #696969;">// m_SynchronizationEvent</span>
<span style="color: #800080;">{</span>
  CLock Lock<span style="color: #808030;">(</span>m_CriticalSection<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
  <span style="color: #696969;">// ...</span>
<span style="color: #800080;">}</span></pre>
<p>Back to Xvid encoder: trying to abort encoding process, the application deadlocks. Thread checking shows worker thread state:</p>
<p><img class="alignnone size-full wp-image-1002" title="Xvid Video Encoder Deadlocked Thread Call Stack" src="http://alax.info/blog/wp-content/uploads/2009/07/31-image002.png" alt="Xvid Video Encoder Deadlocked Thread Call Stack" width="517" height="322" /></p>
<p>That is, a described deadlock in action.</p>
<p>While it is already made this way letting deadlock occur, is there any workaround to avoid locking? Yes, there is. Stopping encoding, GUI thread should keep pumping messages while waiting for worker thread termination. Before closing worker thread handle, one needs to signal the thread to terminate and wait using thread handle with <a href="http://msdn.microsoft.com/en-us/library/ms684242%28VS.85%29.aspx">MsgWaitForMultipleObjects</a>, so that messages possibly sent while terminating the thread are dispatched to target windows.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1000/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
