<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Media Foundation Team Blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/mf/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/mf/feed.xml</link>
    <description />
    <lastBuildDate>Tue, 16 Apr 2019 05:18:25 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Using MFTrace to Trace Your Own Code</title>
      <link>https://docs.microsoft.com/archive/blogs/mf/using-mftrace-to-trace-your-own-code</link>
      <pubDate>Thu, 20 Jan 2011 14:31:36 GMT</pubDate>
      <dc:creator><![CDATA[mfblog]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mf/2011/01/20/using-mftrace-to-trace-your-own-code/</guid>
      <description><![CDATA[Now that you know how to trace Media Foundation and analyze those traces to figure out what Media...]]></description>
      <content:encoded><![CDATA[<p><font size="2" face="Segoe UI">Now that you know how to </font><a href="https://blogs.msdn.com/b/mf/archive/2010/08/11/using-mftrace-to-trace-media-foundation.aspx"><font size="2" face="Segoe UI">trace Media Foundation</font></a><font size="2" face="Segoe UI"> and </font><a href="https://blogs.msdn.com/b/mf/archive/2010/09/09/analyzing-media-foundation-traces.aspx"><font size="2" face="Segoe UI">analyze those traces</font></a><font size="2" face="Segoe UI"> to </font><a href="https://blogs.msdn.com/b/mf/archive/2010/10/28/automating-trace-analysis.aspx"><font size="2" face="Segoe UI">figure out what Media Foundation is doing</font></a><font size="2" face="Segoe UI">, the next step is to figure out what your own code is doing. That means adding traces for </font><a href="https://msdn.microsoft.com/en-us/library/ff685116(VS.85).aspx"><font size="2" face="Segoe UI">MFTrace</font></a><font size="2" face="Segoe UI"> to your code.</font></p>  <p><font size="2" face="Segoe UI">The simplest way to add traces is to use the </font><a href="https://msdn.microsoft.com/en-us/library/aa363362%28VS.85%29.aspx"><font size="2" face="Segoe UI">OutputDebugString</font></a><font size="2" face="Segoe UI"> function. </font><a href="https://msdn.microsoft.com/en-us/library/aa363362%28VS.85%29.aspx"><font size="2" face="Segoe UI">OutputDebugString</font></a><font size="2" face="Segoe UI"> takes a single string as input:</font></p>  <pre class="csharpcode"><span class="kwrd">void</span> WINAPI OutputDebugString(
  __in_opt  LPCTSTR lpOutputString
);</pre>


<p><font size="2" face="Segoe UI">Usually this function sends this string to a debugger. But when MFTrace traces a process, it hooks this function and adds the string to its log.</font></p>

<p><font size="2" face="Segoe UI">To make the OutputDebugString look more like printf, we can write a small wrapper which formats strings:</font></p>

<pre class="csharpcode"><font color="#0000ff">#include</font> &lt;windows.h&gt;
<font color="#0000ff">#include</font> &lt;strsafe.h&gt;

<span class="kwrd"><font color="#0000ff">void</font></span> CDECL Trace(PCSTR pszFormat, ...)
{
    CHAR szTrace[1024];

    va_list args;
    va_start(args, pszFormat);
    (<span class="kwrd"><font color="#0000ff">void</font></span>) StringCchVPrintfA(szTrace, ARRAYSIZE(szTrace), pszFormat, args);
    va_end(args);

    OutputDebugStringA(szTrace);
}

<font face="Segoe UI">Now we can use this wrapper just like printf:</font></pre>

<pre class="csharpcode">INT wmain(INT <span class="rem">/*argc*/</span>, PCWSTR <span class="rem">/*argv*/</span>[])
{
    Trace(<span class="str"><font color="#ff0000">&quot;</font><font color="#ff0000">MyTrace&gt; Hello, world! Here is a pseudo-random number: %i&quot;</font></span>, rand());
}</pre>


<p><font size="2" face="Segoe UI">The traces are displayed both in the </font><a href="https://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express"><font size="2" face="Segoe UI">Visual Studio 2010</font></a><font size="2" face="Segoe UI"> debugger and in the MFTrace logs.</font></p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/5432.image_5A8BA67A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/5432.image_5F00_5A8BA67A.png"><font size="2" face="Segoe UI"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/7181.image_thumb_7CB38C33.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/7181.image_5F00_thumb_5F00_7CB38C33.png" width="477" height="174" /></font></a></p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/3465.image_1C6265FC.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/3465.image_5F00_1C6265FC.png"><font size="2" face="Segoe UI"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/1234.image_thumb_3C113FC4.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/1234.image_5F00_thumb_5F00_3C113FC4.png" width="477" height="182" /></font></a></p>

<p><font size="2" face="Segoe UI">However, there are two drawbacks to the Trace function shown here:</font></p>

<ul>
  <li><font size="2" face="Segoe UI">String formatting is executed all of the time, regardless of whether the code is being traced. This affects performance. </font></li>

  <li><font size="2" face="Segoe UI">The format strings are stored inside the binaries. If you add a lot of traces (which is often needed in asynchronous programming), it fattens the binaries. Therefore, with this kind of tracing code, it is a good idea to use conditional compilation with <font color="#0000ff">#ifdef</font> _DEBUG. </font></li>
</ul>

<p><font size="2" face="Segoe UI">The performance issue can be addressed by using EventWriteString instead of OutputDebugString.</font></p>

<h3><font size="2" face="Segoe UI"><font style="font-weight: bold">Tracing using EventWriteString</font></font></h3>

<p><font size="2" face="Segoe UI">The </font><a href="https://msdn.microsoft.com/en-us/library/aa363750%28VS.85%29.aspx"><font size="2" face="Segoe UI">EventWriteString</font></a><font size="2" face="Segoe UI"> function is similar to OutputDebugString. In addition to the trace string, this function takes a level, a keyword, and a handle:</font></p>

<pre class="csharpcode">ULONG EventWriteString(
  __in  REGHANDLE RegHandle,
  __in  UCHAR Level,
  __in  ULONGLONG Keyword,
  __in  PCWSTR String
);</pre>


<p><font size="2" face="Segoe UI">The handle is initialized by calling EventRegister, and must be freed by calling EventUnregister. This makes EventWriteString slightly more complicated than OutputDebugString, but overall it is still fairly simple to use. </font></p>

<p><font size="2" face="Segoe UI">One interesting feature of the EventRegister function is that it takes a callback function of type </font><a href="https://msdn.microsoft.com/en-us/library/aa363707(VS.85).aspx"><font size="2" face="Segoe UI">PENABLECALLBACK</font></a><font size="2" face="Segoe UI">. The callback function is called to let your code know whether it is being traced, and at which level and keyword. </font></p>

<p><font size="2" face="Segoe UI">Levels and keywords are used to filter out traces at runtime. Levels define the importance of each trace, and keywords define which part of the code each trace belongs to. For the sake of simplicity, we will ignore keywords. </font></p>

<p><font size="2" face="Segoe UI">A few standard levels are defined in evntrace.h: </font></p>

<p><font size="2" face="Segoe UI"></font></p>

<pre class="csharpcode"><span class="preproc"><font color="#0000ff">#define</font></span> TRACE_LEVEL_CRITICAL    1   <span class="rem">// Abnormal exit or termination</span>
<span class="preproc"><font color="#0000ff">#define</font></span> TRACE_LEVEL_ERROR       2   <span class="rem">// Severe errors that need logging</span>
<span class="preproc"><font color="#0000ff">#define</font></span> TRACE_LEVEL_WARNING     3   <span class="rem">// Warnings such as allocation failure</span>
<font face="Verdana"><span class="preproc"><font color="#0000ff">#define</font></span> TRACE_LEVEL_INFORMATION 4   <span class="rem">// Includes non-error cases (e.g., Entry-Exit)</span></font>
<span class="preproc"><font color="#0000ff">#define</font></span> TRACE_LEVEL_VERBOSE     5   <span class="rem">// Detailed traces from intermediate steps</span></pre>


<p><font size="2" face="Segoe UI">Using this function, we can implement tracing with very little impact on performance when the code is not being traced.</font></p>

<pre class="csharpcode"><font color="#0000ff">#include</font> &lt;windows.h&gt;
<font color="#0000ff">#include</font> &lt;wmistr.h&gt;
<font color="#0000ff">#include</font> &lt;evntprov.h&gt;
<font color="#0000ff">#include</font> &lt;evntrace.h&gt;
<font color="#0000ff">#include</font> &lt;strsafe.h&gt;

REGHANDLE g_ETWHandle = NULL;
BOOL g_bEnabled = FALSE;
UCHAR g_nLevel = 0;

<span class="kwrd"><font color="#0000ff">void</font></span> NTAPI EnableCallback(
    LPCGUID <span class="rem"><font color="#008000">/*SourceId*/</font></span>,
    ULONG IsEnabled,
    UCHAR Level,
    ULONGLONG <span class="rem"><font color="#008000">/*MatchAnyKeyword*/</font></span>,
    ULONGLONG <span class="rem"><font color="#008000">/*MatchAllKeywords*/</font></span>,
    PEVENT_FILTER_DESCRIPTOR <span class="rem"><font color="#008000">/*FilterData*/</font></span>,
    PVOID <span class="rem"><font color="#008000">/*CallbackContext*/</font></span>
)
{
    <span class="kwrd"><font color="#0000ff">switch</font></span> (IsEnabled) 
    {  
        <span class="kwrd"><font color="#0000ff">case</font></span> EVENT_CONTROL_CODE_ENABLE_PROVIDER:  
            g_bEnabled = TRUE;
            g_nLevel = Level;
            <span class="kwrd"><font color="#0000ff">break</font></span>;

        <span class="kwrd"><font color="#0000ff">case</font></span> EVENT_CONTROL_CODE_DISABLE_PROVIDER:  
            g_bEnabled = FALSE;
            g_nLevel = 0;
            <span class="kwrd"><font color="#0000ff">break</font></span>;
    }
}

<span class="kwrd"><font color="#0000ff">void</font></span> TraceInitialize()
{
    <span class="rem"><font color="#008000">// Provider ID: {BAADC0DE-0D5E-42EC-A8EF-56F7DC7F7C82}</font></span>
    <span class="rem"><font color="#008000">// TODO: Generate a new unique provider ID. Do not reuse this GUID.</font></span>
    <font size="1"><font face="Verdana"><span class="kwrd"><font color="#0000ff">static</font></span> <span class="kwrd"><font color="#0000ff">const</font></span> GUID guidTrace = {0xbaadc0de, 0xd5e, 0x42ec, {0xa8, 0xef, 0x56, 0xf7, 0xdc, 0x7f, 0x7c, 0x82}};</font></font>
    (<span class="kwrd"><font color="#0000ff">void</font></span>) EventRegister(&amp;guidTrace, EnableCallback, NULL, &amp;g_ETWHandle);
}

<span class="kwrd"><font color="#0000ff">void</font></span> TraceUninitialize()
{
    <span class="kwrd"><font color="#0000ff">if</font></span> (g_ETWHandle)
    {
        (<span class="kwrd"><font color="#0000ff">void</font></span>) EventUnregister(g_ETWHandle);
        g_ETWHandle = NULL;
        g_bEnabled = FALSE;
     g_nLevel = 0;
    }
}

<span class="kwrd"><font color="#0000ff">void</font></span> CDECL TraceFormat(UCHAR nLevel, PCWSTR pszFormat,  ...)
{
    <span class="kwrd"><font color="#0000ff">if</font></span> ((0 == g_nLevel) || (nLevel &lt;= g_nLevel))
    {
        WCHAR szTrace[1024];

        va_list args;
        va_start(args, pszFormat);
        (<span class="kwrd"><font color="#0000ff">void</font></span>) StringCchVPrintfW(szTrace, ARRAYSIZE(szTrace), pszFormat, args);
        va_end(args);

        (<span class="kwrd"><font color="#0000ff">void</font></span>) EventWriteString(g_ETWHandle, nLevel, 0, szTrace);
    }
}

<font face="Verdana"><font size="1"><span class="preproc"><font color="#0000ff">#define</font></span> Trace(level, format, ...) <span class="kwrd"><font color="#0000ff">if</font></span> (g_bEnabled) TraceFormat(level, format, __VA_ARGS__);</font></font>

Adding traces to your code then looks like
INT wmain(INT <span class="rem">/*argc*/</span>, PCWSTR <span class="rem">/*argv*/</span>[])
{
    TraceInitialize();

    Trace(TRACE_LEVEL_INFORMATION, L<span class="str"><font color="#ff0000">&quot;MyTrace&gt; Hello, world!&quot;</font></span>);
    Trace(TRACE_LEVEL_ERROR, L<span class="str"><font color="#ff0000">&quot;MyTrace&gt; Something bad happened: %i&quot;</font></span>, 42);
    
    TraceUninitialize();

    <span class="kwrd"><font color="#0000ff">return</font></span> 0;
}</pre>


<p><font size="2" face="Segoe UI">This code is minimalist on purpose and could easily be expanded by adding other useful information, such as __FUNCTION__, the ‘this’ pointer, function scope (enter/exit), the returned HRESULT, or a trace header that is better than “MyTrace&gt;” to make it easier to filter the traces. </font></p>

<p><font size="2" face="Segoe UI">For MFTrace to log the traces, it needs know which Provider ID (the GUID in TraceInitialize) to trace and which level and keyword to use. This is done by creating a small XML configuration file:</font></p>

<pre class="csharpcode"><font color="#ff0000"><font color="#0000ff">&lt;?</font>xml version=</font><span class="str"><font color="#0000ff"><font color="#000000">'</font>1.0</font><font color="#000000">'</font></span> <font color="#ff0000">encoding</font><font color="#0000ff">=</font><span class="str"><font color="#0000ff"><font color="#0000ff"><font color="#000000">'</font>utf</font>-8</font><font color="#000000">'</font></span><font color="#0000ff">?&gt;
</font><font color="#ff0000"><font color="#0000ff">&lt;</font>providers<font color="#0000ff">&gt;</font>
    <font color="#0000ff">&lt;</font>provider level</font><font color="#0000ff">=</font><span class="str"><font color="#0000ff"><font color="#000000">&quot;</font>5</font><font color="#000000">&quot;</font></span> <font color="#ff0000">ID=</font><span class="str"><font color="#0000ff"><font color="#000000">&quot;</font>BAADC0DE-0D5E-42EC-A8EF-56F7DC7F7C82</font><font color="#000000">&quot;</font></span> <font color="#0000ff">&gt;</font>
        <font color="#ff0000"><font color="#0000ff">&lt;</font>keyword ID</font><font color="#0000ff">=</font><span class="str"><font color="#0000ff"><font color="#000000">&quot;</font>0xFFFFFFFF</font><font color="#000000">&quot;</font></span><font color="#ff0000"><font color="#0000ff">/&gt;</font>
</font>    <font color="#ff0000"><font color="#0000ff">&lt;/</font>provider<font color="#0000ff">&gt;</font> 
<font color="#0000ff">&lt;/</font>providers</font><font color="#0000ff">&gt;</font></pre>


<p><font size="2" face="Segoe UI">Then add ‘-c config.xml’ to the command line of MFTrace (assuming the file is named config.xml).</font></p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/5432.image_54A0DD14.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/5432.image_5F00_54A0DD14.png"><font size="2" face="Segoe UI"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/4477.image_thumb_42581652.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/4477.image_5F00_thumb_5F00_42581652.png" width="477" height="182" /></font></a></p>

<p><font size="2" face="Segoe UI">The configuration file is documented on </font><a href="https://msdn.microsoft.com/en-us/library/ff685118(v=VS.85).aspx"><font size="2" face="Segoe UI">MSDN</font></a><font size="2" face="Segoe UI">.</font></p>

<p><font size="2" face="Segoe UI">If you are writing a DLL instead of an EXE, TraceInitialize and TraceUninitialize should be called inside </font><a href="https://msdn.microsoft.com/en-us/library/ms682583(VS.85).aspx"><font size="2" face="Segoe UI">DllMain</font></a><font size="2" face="Segoe UI"> during DLL_PROCESS_ATTACH and DLL_PROCESS_DETACH respectively. It is usually a </font><a href="https://www.microsoft.com/whdc/driver/kernel/DLL_bestprac.mspx"><font size="2" face="Segoe UI">bad</font></a><font size="2" face="Segoe UI"> </font><a href="https://blogs.msdn.com/b/oldnewthing/archive/2004/01/27/63401.aspx"><font size="2" face="Segoe UI">idea</font></a><font size="2" face="Segoe UI"> </font><a href="https://blogs.msdn.com/b/oldnewthing/archive/2004/01/28/63880.aspx"><font size="2" face="Segoe UI">to</font></a><font size="2" face="Segoe UI"> </font><a href="https://blogs.msdn.com/b/oldnewthing/archive/2010/01/22/9951750.aspx"><font size="2" face="Segoe UI">do</font></a><font size="2" face="Segoe UI"> </font><a href="https://blogs.msdn.com/b/oleglv/archive/2003/10/28/56142.aspx"><font size="2" face="Segoe UI">anything</font></a><font size="2" face="Segoe UI"> </font><a href="https://blogs.msdn.com/b/oleglv/archive/2003/10/24/56141.aspx"><font size="2" face="Segoe UI">significant</font></a><font size="2" face="Segoe UI"> in DllMain, but EventRegister and EventUnregister are designed to be safe to call there.</font></p>

<p><font size="2" face="Segoe UI">Although tracing using EventWriteString is more efficient than OutputDebugString, Windows offer even more efficient APIs to do tracing: ETW and WPP. However, they are also more complex to set up.</font></p>

<h3><font size="2" face="Segoe UI"><font style="font-weight: bold">Tracing using ETW/WPP</font></font></h3>

<p><a href="https://msdn.microsoft.com/en-us/library/bb968803(v=VS.85).aspx"><font size="2" face="Segoe UI">ETW</font></a><font size="2" face="Segoe UI"> and </font><a href="https://msdn.microsoft.com/en-us/library/ff556204.aspx"><font size="2" face="Segoe UI">WPP</font></a><font size="2" face="Segoe UI"> optimize tracing one step further. They reduce the performance impact of tracing when tracing is enabled. Instead of formatting the trace messages inside the process being traced, they format them inside the process listening for traces. This way, tracing does not disturb the traced process as much.</font></p>

<p><font size="2" face="Segoe UI">WPP also reduces the size of binaries by storing format strings in PDB/TMF symbol files, rather than inside the binaries themselves. This provides a form of obfuscation, because traces can be logged without symbol files but are very difficult or even impossible to analyze without those symbol files. For that reason among others, WPP is better suited for internal traces which are not meant to be used by customers.</font></p>

<p><font size="2" face="Segoe UI">ETW on the other hand is better suited for traces which need to be public. Our </font><a href="https://blogs.msdn.com/b/mf/archive/2010/05/20/using-event-viewer-to-trace-media-foundation.aspx"><font size="2" face="Segoe UI">first blog</font></a><font size="2" face="Segoe UI"> post on MF tracing showed how to capture ETW traces using the OS Event Viewer. ETW defines traces using </font><a href="https://msdn.microsoft.com/en-us/library/dd996930(VS.85).aspx"><font size="2" face="Segoe UI">manifests</font></a><font size="2" face="Segoe UI">, and supports localization of the format strings.</font></p>

<p><font size="2" face="Segoe UI">Covering those two tracing systems would require several more blogs due to their complexity, so for more information please refer to MSDN.</font></p>

<p><font size="2" face="Segoe UI">That’s it for this series of blogs on tracing Media Foundation. Do not hesitate to post comments here, or questions on the </font><a href="https://social.msdn.microsoft.com/Forums/en/mediafoundationdevelopment/threads"><font size="2" face="Segoe UI">Media Foundation forum</font></a><font size="2" face="Segoe UI">.</font></p>]]></content:encoded>
    </item>
    <item>
      <title>Automating Trace Analysis</title>
      <link>https://docs.microsoft.com/archive/blogs/mf/automating-trace-analysis</link>
      <pubDate>Wed, 27 Oct 2010 17:26:46 GMT</pubDate>
      <dc:creator><![CDATA[mfblog]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mf/2010/10/27/automating-trace-analysis/</guid>
      <description><![CDATA[In our last post, we discussed how to examine Media Foundation traces manually, using...]]></description>
      <content:encoded><![CDATA[<p><font size="2" face="Segoe UI">In our </font><a href="https://blogs.msdn.com/b/mf/archive/2010/09/09/analyzing-media-foundation-traces.aspx"><font size="2" face="Segoe UI">last post</font></a><font size="2" face="Segoe UI">, we discussed how to examine Media Foundation traces manually, using TextAnalysisTool.NET. This time, we present a few scripts to automate the process and identify problems more quickly. </font><font size="2" face="Segoe UI">&#160;</font></p>  <h4><font size="2" face="Segoe UI"><font style="font-weight: bold">Getting Started</font></font></h4>  <p><font size="2" face="Segoe UI">First, install </font><a href="https://www.perl.org/get.html"><font size="2" face="Segoe UI">Perl</font></a><font size="2" face="Segoe UI">, </font><a href="https://www.graphviz.org/Download_windows.php"><font size="2" face="Segoe UI">GraphViz</font></a><font size="2" face="Segoe UI">, and </font><a href="https://sourceforge.net/projects/gnuplot/files/"><font size="2" face="Segoe UI">Gnuplot</font></a><font size="2" face="Segoe UI">. Then open a command prompt and add Gnuplot to your path. For example: </font></p>  <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><font size="2" face="Segoe UI">set PATH=%PATH%;C:\Program Files\gnuplot\binary</font></pre>
<!--crlf--></!--crlf--></div>
</div>

<p><font size="2" face="Segoe UI">The exact path to Gnuplot on your machine might differ. The installers for Perl and GraphViz automatically add the path, so those two applications should already be in your path.</font></p>

<p><font size="2" face="Segoe UI">Next, download the following Perl scripts from </font><a href="https://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=mfblog&amp;DownloadId=14213"><font size="2" face="Segoe UI">MSDN Code Gallery</font></a><font size="2" face="Segoe UI">:</font></p>

<ul>
  <li><font size="2" face="Segoe UI">ParseTopologies.cmd </font></li>

  <li><font size="2" face="Segoe UI">ParseTimestamps.cmd </font></li>

  <li><font size="2" face="Segoe UI">ParseDirectShowGraphs.cmd </font></li>
</ul>

<p><font size="2" face="Segoe UI">The scripts in the download package have a .txt file extension. Rename them to have a .cmd extension. </font></p>

<p><font size="2" face="Segoe UI">In the following, we assume that a log file was captured using MFTrace and saved to .\mf.log. If you need a refresher on MFTrace, please refer to our </font><a href="https://blogs.msdn.com/b/mf/"><font size="2" face="Segoe UI">previous posts</font></a><font size="2" face="Segoe UI"> and to </font><a href="https://msdn.microsoft.com/en-us/library/ff685370%28v=VS.85%29.aspx"><font size="2" face="Segoe UI">MSDN</font></a><font size="2" face="Segoe UI">.</font></p>

<h3><font size="2" face="Segoe UI"><font style="font-weight: bold">Drawing Topologies</font></font></h3>

<p><font size="2" face="Segoe UI">Recall that Media Foundation takes various pipeline components (sources, decoders, sinks) and assembles them into a <i>topology</i>. It is hard to visualize a topology just by reading a trace log. A picture of a topology would be much easier to understand. That’s exactly what our first script does: It searches the log for traces that describe the topology, saves these in a format that GraphViz understands, and runs GraphViz to create an image.</font></p>

<p><font size="2" face="Segoe UI">Running the script is straightforward:</font></p>

<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><font size="2" face="Segoe UI">ParseTopologies.cmd mf.log</font></pre>
<!--crlf--></!--crlf--></div>
</div>

<p><font size="2" face="Segoe UI">The script creates several images which represent the topology at different stages of topology resolution. The first topology is the input to the Media Session, and often looks like this:</font></p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/7140.image_7487E8A9.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/7140.image_5F00_7487E8A9.png"><font size="2" face="Segoe UI"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/4314.image_thumb_003D2FDC.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/4314.image_5F00_thumb_5F00_003D2FDC.png" width="504" height="415" /></font></a></p>

<p><font size="2" face="Segoe UI">Each node represents a component of the topology. Media types shared by two connected components are displayed along the line of the connection.</font></p>

<p><font size="2" face="Segoe UI">The node colors have the following meaning:</font></p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/8130.image_31C89D71.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/8130.image_5F00_31C89D71.png"><font size="2" face="Segoe UI"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/6560.image_thumb_7F64C9F1.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/6560.image_5F00_thumb_5F00_7F64C9F1.png" width="628" height="54" /></font></a></p>

<p><font size="2" face="Segoe UI">Activation objects are like placeholders that have been inserted into the topology in place of the components themselves. As the topology gets resolved, the actual components are instantiated and gradually replace the activation objects:</font></p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/0268.image_65FCC6B7.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/0268.image_5F00_65FCC6B7.png"><font size="2" face="Segoe UI"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/2248.image_thumb_13BA69B0.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/2248.image_5F00_thumb_5F00_13BA69B0.png" width="504" height="771" /></font></a></p>

<p><font size="2" face="Segoe UI">This topology represents the “ready” state. It contains two branches: </font></p>

<ul>
  <li><font size="2" face="Segoe UI">A video branch, shown on the right. This branch is fairly straightforward. It contains just a source node, a decoder, and a sink node. </font></li>

  <li><font size="2" face="Segoe UI">An audio branch, shown on the left. This branch is a bit more complicated. It contains a source node, a decoder, several effects, a tee, another effect, and finally two sink nodes. </font></li>
</ul>

<p><font size="2" face="Segoe UI"><font style="font-weight: bold">Plotting Sample Time Stamps</font></font></p>

<p><font size="2" face="Segoe UI">Just like topologies, time stamps are much simpler to analyze with some visual aid. This is what the second script creates, with the help of Gnuplot.</font></p>

<p><font size="2" face="Segoe UI">Again, running the script is straightforward:</font></p>

<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><font size="2" face="Segoe UI">ParseTopologies.cmd mf.log [-absolute]</font></pre>
<!--crlf--></!--crlf--></div>
</div>

<p><font size="2" face="Segoe UI">By default, time stamps are plotted as the difference between the time stamp and wall-clock time. If you want to plot time stamps as a function of wall-clock time, add the “-absolute” command-line option.</font></p>

<p><font size="2" face="Segoe UI">For playback scenarios, the difference is usually more interesting, as it results in flat graphs when samples flow smoothly (i.e. real time). The “-absolute” option is geared toward transcoding scenarios, where you want the samples flow as fast as possible. </font></p>

<p><font size="2" face="Segoe UI">The script plots one graph per component. The time stamps from input samples are plotted in green, and the time stamps from output samples are plotted in blue. The gap between the two gives an idea of the latency of the component. However, tracing adds some latency to the measurements, so the gap should be viewed as an upper bound on the latency.</font></p>

<p><font size="2" face="Segoe UI">Here is an example of what you do <i>not</i> want to see in a playback scenario: two major glitches in an otherwise smooth playback. </font></p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/6457.image_70A9F83F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/6457.image_5F00_70A9F83F.png"><font size="2" face="Segoe UI"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/8512.image_thumb_4E05B9C4.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/8512.image_5F00_thumb_5F00_4E05B9C4.png" width="354" height="360" /></font></a></p>

<p><font size="2" face="Segoe UI">The script also prints a few statistics at the command prompt about the components in the topology. This can be useful to quickly determine whether some components were not generating samples as they should have.</font></p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/0675.image_133E10EE.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/0675.image_5F00_133E10EE.png"><font size="2" face="Segoe UI"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/4370.image_thumb_5E215BF0.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/4370.image_5F00_thumb_5F00_5E215BF0.png" width="478" height="235" /></font></a></p>

<h3><font size="2" face="Segoe UI">Drawing DirectShow graphs</font></h3>

<p><font size="2" face="Segoe UI">Because MFTrace also captures some DirectShow traces, it is also possible to draw DirectShow graphs. Here is the graph for playing a WTV file.</font></p>

<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><font size="2" face="Segoe UI">ParseDirectShowGraphs.cmd mf.log</font></pre>
<!--crlf--></!--crlf--></div>
</div>
<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/1323.image_24321904.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/1323.image_5F00_24321904.png"><font size="2" face="Segoe UI"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/3225.image_thumb_23C5E60F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/3225.image_5F00_thumb_5F00_23C5E60F.png" width="504" height="327" /></font></a><font size="2" face="Segoe UI"> </font>

<p><font size="2" face="Segoe UI">As you can see, WTV playback can be quite involved.</font></p>

<p><font size="2" face="Segoe UI">That’s all for now. Next time, we will see how to add custom traces from components or applications to the MFTrace logs. In the meantime, do not hesitate to post comments here, or questions on the </font><a href="https://social.msdn.microsoft.com/Forums/en/mediafoundationdevelopment/threads"><font size="2" face="Segoe UI">Media Foundation forum</font></a><font size="2" face="Segoe UI">.</font></p>]]></content:encoded>
    </item>
    <item>
      <title>Analyzing Media Foundation traces</title>
      <link>https://docs.microsoft.com/archive/blogs/mf/analyzing-media-foundation-traces</link>
      <pubDate>Thu, 09 Sep 2010 09:55:43 GMT</pubDate>
      <dc:creator><![CDATA[mfblog]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mf/2010/09/09/analyzing-media-foundation-traces/</guid>
      <description><![CDATA[As we mentioned in our previous blog post, log files generated by MFTrace quickly become huge, and...]]></description>
      <content:encoded><![CDATA[<p><font size="2" face="Segoe UI">As we mentioned in our </font><a href="https://blogs.msdn.com/b/mf/archive/2010/08/11/using-mftrace-to-trace-media-foundation.aspx"><font size="2" face="Segoe UI">previous blog post</font></a><font size="2" face="Segoe UI">, log files generated by MFTrace quickly become huge, and it can be difficult to sort out interesting traces from background noise. This blog post will share a few tips to help analyze those log files.</font></p>  <h2><font size="2" face="Segoe UI"><font style="font-weight: "><strong>TextAnalysisTool.NET</strong></font></font></h2>  <p><font size="2" face="Segoe UI">One (free) tool that we often use is </font><a href="https://blogs.msdn.com/b/delay/archive/2007/06/21/powerful-log-file-analysis-for-everyone-releasing-textanalysistool-net.aspx"><font size="2" face="Segoe UI">TextAnalysilTool.NET</font></a><font size="2" face="Segoe UI">. The tool itself is rather minimalist: It just loads log files and lets you enter string patterns to filter out or highlight traces. However, it is very effective at focusing on what matters. Installing TextAnalysisTool.NET is straightforward—just download and uncompress the </font><a href="https://cesso.org/Samples/TextAnalysisTool.NET/TextAnalysisTool.NET.zip"><font size="2" face="Segoe UI">zip file</font></a><font size="2" face="Segoe UI">.</font></p>  <p><font size="2" face="Segoe UI">Starting where we left off in the previous post, let’s collect another trace from Windows Media Player. Open an elevated command prompt, add the SDK to your path (see the </font><a href="https://blogs.msdn.com/b/mf/archive/2010/08/11/using-mftrace-to-trace-media-foundation.aspx"><font size="2" face="Segoe UI">previous post</font></a><font size="2" face="Segoe UI">), and run Windows Media Player under MFTrace:</font></p>  <blockquote>   <p><font face="Segoe UI"><font size="2"><i>MFTrace.exe -o mf.log &quot;%PROGRAMFILES%\Windows Media Player\wmplayer.exe&quot;</i> &quot;%PUBLIC%\Videos\Sample Videos\Wildlife.wmv&quot;</font></font></p> </blockquote>  <p><font size="2" face="Segoe UI">Let the video play for a few seconds. Then close Windows Media Player. At this point, you should have a log file named “mf.log” in the current directory. Open this file with TextAnalysisTool.NET as follows:</font></p>  <blockquote>   <p><i><font size="2" face="Segoe UI">TextAnalysisTool.NET.exe mf.log</font></i></p> </blockquote>  <p><font size="2" face="Segoe UI">TextAnalysisTool.NET will show two views. The traces appear in the top view. The bottom view contains string patterns that filter or highlight the traces.</font></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/3857.image_0DCB8DA8.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/3857.image_5F00_0DCB8DA8.png"><font size="2" face="Segoe UI"></font></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/1374.image_14126436.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/1374.image_5F00_14126436.png"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/7140.image_thumb_69149422.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/7140.image_5F00_thumb_5F00_69149422.png" width="628" height="280" /></a></p>  <p><font size="2" face="Segoe UI">To filter out traces, select <b>Add new filter</b> from the <b>Filter</b> menu, or type CTRL+N. In the <b>Add Filter</b> dialog, enter a string pattern and choose a highlight color:</font></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/7853.image7_56CBCD60.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/7853.image7_5F00_56CBCD60.png"><font size="2" face="Segoe UI"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/7041.image7_thumb_767AA728.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/7041.image7_5F00_thumb_5F00_767AA728.png" width="427" height="149" /></font></a></p>  <p><font size="2" face="Segoe UI">You can also select whether the string is case-sensitive or uses a regular expression. When you click <b>OK</b>, traces that do not match the pattern will appear grayed out. To completely hide those traces, select <b>Show only filtered lines</b> from the <b>View</b> menu, or type CTRL+H.</font></p>  <p><font size="2" face="Segoe UI">This should be enough to get you started. For more details on how to use TextAnalysis, see the help file “TextAnalysisTool.NET.txt,” which is contained in the zip file.</font></p>  <h2><font size="2" face="Segoe UI"><font style="font-weight: bold">Tips and tricks to analyze traces</font></font></h2>  <p><font size="2" face="Segoe UI">One of the first filters to use on a trace is the string “fail”. Traces that contain this string are likely to indicate problems. For example, the following trace shows where a codec rejected a proposed media type:</font></p>  <blockquote>   <p><i><font size="2" face="Segoe UI">00120 3992,B28 23:14:38.80074 CMFTransformDetours::SetInputType @00672C90 <b>Failed MT</b>: MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_SUBTYPE=MFVideoFormat_WMV3;MF_MT_FRAME_SIZE=3092376453600 (720,480);MF_MT_USER_DATA=4f d1 1a 01 ;MF_MT_AVG_BITRATE=1895000;MF_MT_FRAME_RATE=128849018881001 (30000,1001);MF_MT_PIXEL_ASPECT_RATIO=34359738377 (8,9);MF_MT_INTERLACE_MODE=2</font></i></p> </blockquote>  <p><font size="2" face="Segoe UI">Note that some failures may be benign. For example, the following trace just means that the codec needs another sample before it can produce some output:</font></p>  <blockquote>   <p><i><font face="Segoe UI"><font size="2">00489 6072,10E4 16:23:07.47317 CMFTransformDetours::ProcessOutput @0357ED34 failed hr=0xC00D6D72 <b>MF_E_TRANSFORM_NEED_MORE_INPUT</b></font></font></i></p> </blockquote>  <p><font size="2" face="Segoe UI">This error code is expected during normal streaming, unless <i>all</i> the calls to <b>ProcessOutput</b> return this error code. For example, this can happen if the H.264 decoder does not find a valid start code within the H.264 bitstream. </font></p>  <p><font size="2" face="Segoe UI">The log file can also tell you whether the topology was successfully resolved and how the pipeline components got connected (or not). To figure this out, filter traces that contain the string “TopologyHelpers”:</font></p>  <blockquote style="font-style: italic"><font size="2" face="Segoe UI">00248 6072,DC0 16:23:07.21976 CTopologyHelpers::Trace @02F21080 &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; ready topology      <br />00249 6072,DC0 16:23:07.22002 CTopologyHelpers::TraceNode @ Node 0 @02EFC0D0 ID:17B800000007, 0 inputs, 1 outputs, type 1, {528E8D22-311F-4B88-BCE8-22A2374E8CFC}=1;MF_TOPONODE_SOURCE=@02EDBE48; (…)       <br />00250 6072,DC0 16:23:07.22008 CTopologyHelpers::TraceObject @ Source @02EDBE48 {00000000-0000-0000-0000-000000000000} (C:\Windows\system32\MF.dll), MFMEDIASOURCE_CHARACTERISTICS=0x00000006       <br />00251 6072,DC0 16:23:07.22018 CTopologyHelpers::TraceStream @ Output stream 0, connected to node @02EFC170 stream 0, MT: MF_MT_MAJOR_TYPE=MEDIATYPE_Audio; (…)       <br />00252 6072,DC0 16:23:07.22040 CTopologyHelpers::TraceNode @ Node 1 @02EFC030 ID:17B800000009, 1 inputs, 0 outputs, type 0, (…)       <br />00253 6072,DC0 16:23:07.22044 CTopologyHelpers::TraceObject @ Sink @02F1DF58 {D23E6476-B104-4707-81CB-E1CA19A07016} (C:\Windows\system32\MF.dll), (null)       <br />00254 6072,DC0 16:23:07.22053 CTopologyHelpers::TraceStream @ Input stream 0, connected to node @02F19DA8 stream 0, MT: MF_MT_MAJOR_TYPE=MEDIATYPE_Audio;(…)       <br />(…)       <br />00293 6072,DC0 16:23:07.22528 CTopologyHelpers::Trace @02F21080 MF_TOPOLOGY_RESOLUTION_STATUS = 0       <br />00294 6072,DC0 16:23:07.22529 CTopologyHelpers::Trace @02F21080 &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; ready topology       <br /></font></blockquote>  <p><font size="2" face="Segoe UI">If everything went well, as is the case here, the resolution status is zero. The rest of the selected traces give details about each of the components in the topology and how they are connected to one another. Among other things, this information includes the media type of the connection.</font></p>  <p><font size="2" face="Segoe UI">Another useful filter is the object address, which allows you to focus on the lifetime of one object in particular. For instance, the following traces were selected by filtering with “0357ED34”. They show the first few calls on a Windows Media Player effect. </font></p>  <blockquote>   <p><font face="Segoe UI"><font size="2"><i>00149 6072,DC0 16:23:06.91749 CMFTransformDetours::<b>SetInputType</b> @0357ED34 Succeeded MT: MF_MT_MAJOR_TYPE=MEDIATYPE_Audio;(…)</i>           <br /><i>00151 6072,DC0 16:23:06.91919 CMFTransformDetours::<b>SetOutputType</b> @0357ED34 Succeeded MT: MF_MT_MAJOR_TYPE=MEDIATYPE_Audio; (…)</i>           <br /><i>00194 6072,DC0 16:23:07.18577 CTopologyHelpers::TraceObject @ MFT @0357ED34 {777D0CFF-0375-43B9-8532-FB04A4903593} (C:\Windows\System32\<b>wmpeffects.dll</b>), &lt;NULL&gt;</i>           <br /><i>00230 6072,DC0 16:23:07.19396 CMFTransformDetours::ProcessMessage @0357ED34 Message type=0x10000000 <b>MFT_MESSAGE_NOTIFY_BEGIN_STREAMING</b>, param=00000000</i>           <br /><i>00473 6072,9B0 16:23:07.40790 CMFTransformDetours::ProcessMessage @0357ED34 Message type=0x10000003 <b>MFT_MESSAGE_NOTIFY_START_OF_STREAM</b>, param=00000000</i>           <br /><i>00489 6072,10E4 16:23:07.47317 CMFTransformDetours::<b>ProcessOutput</b> @0357ED34 failed hr=0xC00D6D72 <b>MF_E_TRANSFORM_NEED_MORE_INPUT</b></i>           <br /><i>00508 6072,10E4 16:23:07.59281 CMFTransformDetours::<b>ProcessInput</b> @0357ED34 Stream ID 0, Sample @083C8720, Time 0ms, Duration 46ms, Buffers 1, Size 16384B, MFSampleExtension_CleanPoint=1;MFSampleExtension_Discontinuity=1;MFSampleExtension_SampleKeyID=1;MFSampleExtension_Token=@00000000</i>           <br /><i>00509 6072,10E4 16:23:07.59628 CMFTransformDetours::<b>ProcessOutput</b> @0357ED34 Stream ID 0, Sample @083C8810, Time 0ms, Duration 46ms, Buffers 1, Size 16384B, MFSampleExtension_CleanPoint=0</i>           <br /></font></font></p> </blockquote>  <p><font size="2" face="Segoe UI">In this sequence of calls, Windows Media Player sets the media types on the effect, notifies the effect that streaming is about to start, and processes one sample.</font></p>  <p><font size="2" face="Segoe UI">That’s all for now, but more examples are shown on the </font><a href="https://msdn.microsoft.com/en-us/library/ff685370%28v=VS.85%29.aspx"><font size="2" face="Segoe UI">MSDN page</font></a><font size="2" face="Segoe UI"> dedicated to MFTrace. In the next post, we will share a few Perl scripts that automate trace analysis and use the power of GraphViz and GNUPlot to create graphical representations of topologies.</font></p>]]></content:encoded>
    </item>
    <item>
      <title>Using MFTrace to Trace Media Foundation</title>
      <link>https://docs.microsoft.com/archive/blogs/mf/using-mftrace-to-trace-media-foundation</link>
      <pubDate>Wed, 11 Aug 2010 11:15:05 GMT</pubDate>
      <dc:creator><![CDATA[mfblog]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mf/2010/08/11/using-mftrace-to-trace-media-foundation/</guid>
      <description><![CDATA[We are continuing our series on Media Foundation and its tracing by introducing a new tool available...]]></description>
      <content:encoded><![CDATA[<p><font size="2" face="Segoe UI">We are continuing our series on Media Foundation and its tracing by introducing a new tool available in the latest </font><a href="https://go.microsoft.com/fwlink/?LinkID=129787"><font size="2" face="Segoe UI">Windows SDK</font></a><font size="2" face="Segoe UI">: MFTrace. This tool is similar to Event Viewer: Both tools collect traces which give some insight into what Media Foundation and its components are doing. However, MFTrace is much more powerful, and collects way more information, than Event viewer.</font></p>  <p><font size="2" face="Segoe UI">After installing the SDK, MFTrace is available in two flavors:</font></p>  <p><font size="2" face="Segoe UI">- 32b in %PROGRAMFILES%\Microsoft SDKs\Windows\v7.1\Bin</font></p>  <p><font size="2" face="Segoe UI">- 64b in %PROGRAMFILES%\Microsoft SDKs\Windows\v7.1\Bin\x64</font></p>  <p><font size="2" face="Segoe UI">The tool itself is made of three binaries (MFTrace.exe, MFDetours.dll, detoured.dll) and an optional configuration file (mftrace.xml). From the name of the binaries, it should not come as a surprise that the tool relies heavily on the </font><a href="https://research.microsoft.com/en-us/projects/detours/"><font size="2" face="Segoe UI">Detours</font></a><font size="2" face="Segoe UI"> library to inject itself into the target process and intercept function calls. </font></p>  <p><font size="2" face="Segoe UI">The traces usually follow the pattern of a process and thread ID, followed by a timestamp, the name of the function called, and some function parameters:</font></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/3286.image_70FC578C.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/3286.image_5F00_70FC578C.png"><font size="2" face="Segoe UI"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/0385.image_thumb_1298805E.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/0385.image_5F00_thumb_5F00_1298805E.png" width="628" height="194" /></font></a></p>  <p><font size="2" face="Segoe UI">In some cases, MFTrace goes one step further and does some deep inspection of the function parameters to gather more details—for instance, displaying entire topologies.</font></p>  <p><strong><font size="2" face="Segoe UI">Collecting your first trace</font></strong></p>  <p><font size="2" face="Segoe UI">As a first practice, let’s use our favorite guinea pig: Notepad. MFTrace can indeed target any application, not just those based on Media Foundation. As a matter of fact, MFTrace also intercepts some functions from COM, DirectShow, and DirectX.</font></p>  <p><font size="2" face="Segoe UI">First, open an elevated command prompt:</font></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/5672.image_2E3D0C54.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/5672.image_5F00_2E3D0C54.png"><font size="2" face="Segoe UI"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/3603.image_thumb_5FC879E9.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/3603.image_5F00_thumb_5F00_5FC879E9.png" width="301" height="374" /></font></a></p>  <p><font size="2" face="Segoe UI">Then add the SDK to your path, if you haven’t already done so:</font></p>  <blockquote>   <p><i><font size="2" face="Segoe UI">set PATH=%PATH%;“%PROGRAMFILES%\Microsoft SDKs\Windows\v7.1\Bin”</font></i></p> </blockquote>  <blockquote>   <p><font size="2" face="Segoe UI">(add ‘x64’ at the end if using the 64b version of MFTrace)</font></p> </blockquote>  <p><font size="2" face="Segoe UI">Now run Notepad under MFTrace:</font></p>  <blockquote>   <p><i><font size="2" face="Segoe UI">MFTrace.exe notepad.exe</font></i></p> </blockquote>  <p><font size="2" face="Segoe UI">MFTrace will start printing a few traces at the command prompt. To make things a little more interesting, try opening some file in Notepad. Right away you will see a large number of calls to </font><a href="https://msdn.microsoft.com/en-us/library/ms686615%28VS.85%29.aspx"><font size="2" face="Segoe UI">CoCreateInstance</font></a><font size="2" face="Segoe UI">:</font></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/0871.image_187323F7.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/0871.image_5F00_187323F7.png"><font size="2" face="Segoe UI"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/5658.image_thumb_1806F102.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/5658.image_5F00_thumb_5F00_1806F102.png" width="478" height="269" /></font></a></p>  <p><font size="2" face="Segoe UI">To end tracing, just close Notepad or hit CTRL+C.</font></p>  <div style="border-bottom: black 1px solid; border-left: black 1px solid; padding-bottom: 2%; padding-left: 2%; padding-right: 2%; margin-left: auto; border-top: black 1px solid; margin-right: auto; border-right: black 1px solid; padding-top: 2%"><font face="Segoe UI"><font size="2"><b><font color="#ff0000">Note: 32-bit processes on 64-bit Windows</font></b> </font></font>    <p><font size="2" face="Segoe UI">If you are using a 32-bit version of Windows, you can skip this warning. Otherwise, please read on. MFTrace comes in two flavors: 32-bit and 64-bit. Each version can only trace processes of the same kind, so if you want to trace a 32-bit process you need to use 32-bit MFTrace; and if you want to trace a 64-bit process, you need to use 64-bit MFTrace. Where it gets tricky is that some processes (such as Windows Media Player) run by default as 32-bit processes on 64-bit Windows.</font></p>    <p><font size="2" face="Segoe UI">One way to tell whether a process is 32- or 64-bit is to look at its path: </font></p>    <ul>     <li><font size="2" face="Segoe UI">32-bit processes can be found under %PROGRAMFILES(X86)% </font></li>      <li><font size="2" face="Segoe UI">64-bit processes can be found under %PROGRAMFILES% </font></li>   </ul>    <p><font size="2" face="Segoe UI">Usually these environment variable resolve to “c:\program files (x86)” for 32-bit, and “c:\program files” for 64-bit.</font></p>    <p><font size="2" face="Segoe UI">Another way is to open the Task Manager (CTRL+SHIFT+ESC) and look for ‘*32’ at the end of process names.</font></p>    <p><font size="2" face="Segoe UI"></font></p>   <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/0407.image_0CADB6F8.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/0407.image_5F00_0CADB6F8.png"><font size="2" face="Segoe UI"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/11/metablogapi/1300.image_thumb_79F8BD40.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-11-metablogapi/1300.image_5F00_thumb_5F00_79F8BD40.png" width="443" height="346" /></font></a><font size="2" face="Segoe UI"> </font></div>  <p><strong><font size="2" face="Segoe UI"></font></strong></p>  <p><strong><font size="2" face="Segoe UI">Collecting your first useful trace</font></strong></p>  <p><font size="2" face="Segoe UI">Printing traces at the command prompt is nice, but too slow to handle the amount of traces that are generated by media applications. Instead, traces can be redirected to a file using the ‘-o’ command-line parameter.</font></p>  <p><font size="2" face="Segoe UI">Besides starting a new process, MFTrace can also attach to an existing process via the ‘-a’ command-line parameter. This parameter accepts either a process name or a process ID. One word of caution: MFTrace is only able to intercept function calls on objects which have been created after MFTrace attached itself. So if you start playing a video in Windows Media Player and then attach MFTrace to it, MFTrace will miss most of the action.</font></p>  <p><font size="2" face="Segoe UI">Armed with that knowledge, we can now start tracing something a bit more interesting: Windows Media Player. Open Windows Media Player and attach MFTrace with this command line:</font></p>  <blockquote>   <p><i><font size="2" face="Segoe UI">mftrace.exe -a wmplayer.exe -o mf.log</font></i></p> </blockquote>  <p><font size="2" face="Segoe UI">Then open a media file in Windows Media Player (for example, &quot;%PUBLIC%\Videos\Sample Videos\Wildlife.wmv&quot;), let it play for a few seconds, exit MFTrace (CTRL+C), and open mf.log in your favorite text editor. You will have a detailed record of what Media Foundation and its components have been doing in the background to play the file.</font></p>  <p><font size="2" face="Segoe UI">Logs tend to contain a huge amount of data, which can be quite overwhelming at first. In the next installments of this blog series, we will try to make sense of them. We will also see how to add traces from your own components and applications, to get a fuller picture of what is going on.</font></p>  <p><font size="2" face="Segoe UI">In the meantime, for more help see ‘mftrace.exe -?’, the </font><a href="https://go.microsoft.com/fwlink/?LinkId=183164"><font size="2" face="Segoe UI">MSDN page</font></a><font size="2" face="Segoe UI"> dedicated to MFTrace, or post questions on the </font><a href="https://social.msdn.microsoft.com/Forums/en/mediafoundationdevelopment/threads"><font size="2" face="Segoe UI">Media Foundation forum</font></a><font size="2" face="Segoe UI">.</font></p>]]></content:encoded>
    </item>
    <item>
      <title>Using Event Viewer to Trace Media Foundation</title>
      <link>https://docs.microsoft.com/archive/blogs/mf/using-event-viewer-to-trace-media-foundation</link>
      <pubDate>Thu, 20 May 2010 02:34:00 GMT</pubDate>
      <dc:creator><![CDATA[mfblog]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mf/2010/05/20/using-event-viewer-to-trace-media-foundation/</guid>
      <description><![CDATA[It is an unfortunate fact of life that sometimes things do not work as expected. Luckily, when bad...]]></description>
      <content:encoded><![CDATA[<p><font size="3" face="Calibri">It is an unfortunate fact of life that sometimes things do not work as expected. Luckily, when bad things happen, the Event Viewer is there to help narrow down the issue and figure out the root cause of the problem. </font></p>  <p><font size="3" face="Calibri">Without these traces, finding when and why a failure happened in Media Foundation can be very tricky, because:</font></p>  <ul>   <li><font size="3" face="Calibri">Media Foundation is asynchronous.</font> </li>    <li><font size="3" face="Calibri">Many components come into play when processing media data (the pipeline, codecs, sources, sinks, etc.).</font> </li>    <li><font size="3" face="Calibri">Some applications, such as Windows Media Player, use fallback mechanisms to be able to play as many files as possible.</font> </li> </ul>  <p><font size="3" face="Calibri">This means that errors may get reported a long time after the failure actually took place, and the component that reports the error might not be related to the component that actually caused the failure.</font></p>  <h4><font size="4" face="Calibri"><strong>Enabling Media Foundation traces in Event Viewer</strong></font></h4>  <p><font size="3" face="Calibri">Event Viewer can be found by typing ‘event’ in the search box of the <b>Start</b> menu:</font></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/UsingEventViewertoTraceMediaFoundation_AEF1/image_2.png" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/UsingEventViewertoTraceMediaFoundation_AEF1/image_2.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" class="wlDisabledImage" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/UsingEventViewertoTraceMediaFoundation_AEF1/image_thumb.png" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/UsingEventViewertoTraceMediaFoundation_AEF1/image_thumb.png" width="320" height="275" /></a></p>  <p><font size="3" face="Calibri">To log Media Foundation traces, the verbosity of Event Viewer must be increased from its default. To do so, go to the <b>View</b> menu and select <b>Show Analytic and Debug Logs</b>:</font></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/UsingEventViewertoTraceMediaFoundation_AEF1/image_4.png" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/UsingEventViewertoTraceMediaFoundation_AEF1/image_4.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" class="wlDisabledImage" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/UsingEventViewertoTraceMediaFoundation_AEF1/image_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/UsingEventViewertoTraceMediaFoundation_AEF1/image_thumb_1.png" width="287" height="93" /></a></p>  <br />  <p><font size="3" face="Calibri">The Media Foundation logs can be found in the left pane of Event Viewer, under Event Viewer (Local) &gt; Applications and Services Logs &gt; Microsoft &gt; Windows. They are grouped into five categories:</font></p>  <ul>   <li><font size="3" face="Calibri">MediaFoundation</font> </li>    <li><font size="3" face="Calibri">MediaFoundation-MFReadWrite (</font><a href="https://msdn.microsoft.com/en-us/library/dd389281(v=VS.85).aspx"><font size="3" face="Calibri">Source Reader</font></a><font size="3" face="Calibri">, </font><a href="https://msdn.microsoft.com/en-us/library/dd374642(VS.85).aspx"><font size="3" face="Calibri">Sink Writer</font></a><font size="3" face="Calibri">)</font> </li>    <li><font size="3" face="Calibri">MediaFoundation-Performance</font> </li>    <li><font size="3" face="Calibri">MediaFoundation-Platform</font> </li>    <li><font size="3" face="Calibri">MediaFoundation-PlayAPI (</font><a href="https://msdn.microsoft.com/en-us/library/dd318791(v=VS.85).aspx"><font size="3" face="Calibri">MFPlay</font></a><font size="3" face="Calibri"> API)</font> </li> </ul>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/UsingEventViewertoTraceMediaFoundation_AEF1/image_6.png" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/UsingEventViewertoTraceMediaFoundation_AEF1/image_6.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" class="wlDisabledImage" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/UsingEventViewertoTraceMediaFoundation_AEF1/image_thumb_2.png" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/UsingEventViewertoTraceMediaFoundation_AEF1/image_thumb_2.png" width="320" height="304" /></a></p>  <br />  <p><font size="3" face="Calibri">Clicking on a log will show some options on the right pane of Event Viewer related to this log. Two of them are particularly useful: <b>Enable Log</b> starts collecting traces, and <b>Refresh</b> forces Event Viewer to display the traces received so far.</font></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/UsingEventViewertoTraceMediaFoundation_AEF1/image_8.png" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/UsingEventViewertoTraceMediaFoundation_AEF1/image_8.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" class="wlDisabledImage" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/UsingEventViewertoTraceMediaFoundation_AEF1/image_thumb_3.png" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/UsingEventViewertoTraceMediaFoundation_AEF1/image_thumb_3.png" width="280" height="290" /></a></p>  <br />  <h4><font size="4" face="Calibri"><strong>Analyzing traces</strong></font></h4>  <p><font size="3" face="Calibri">After traces have been collected, the next step is to figure out which ones are of interest and how to interpret them. As a starting point, the following FAQ lists some questions that can be answered by looking at the logs, and which traces to look for.</font></p>  <h4><font face="Calibri"><font size="4"><strong>Which API did Windows Media Player use for playback?</strong></font> </font></h4>  <p><font size="3" face="Calibri">Windows Media Player relies either on </font><a href="https://msdn.microsoft.com/en-us/library/ms697062%28v=VS.85%29.aspx"><font size="3" face="Calibri">Media Foundation</font></a><font size="3" face="Calibri">, </font><a href="https://msdn.microsoft.com/en-us/library/dd375454%28VS.85%29.aspx"><font size="3" face="Calibri">DirectShow</font></a><font size="3" face="Calibri">, or the </font><a href="https://msdn.microsoft.com/en-us/library/dd757738%28v=VS.85%29.aspx"><font size="3" face="Calibri">Format SDK</font></a><font size="3" face="Calibri">, depending on the type of content being processed. To figure out which API was used, view the log named ‘MediaFoundation-Platform &gt; Media Foundation Platform,’ and look for:</font></p>  <blockquote>   <p><i>Windows Media Player Playback URL=C:\Users\Public\Videos\Sample Videos\Wildlife.wmv Graph Type=3 hr=0x0</i></p> </blockquote>  <p><font size="3" face="Calibri">The graph type can be:</font></p>  <ol>   <li><font size="3" face="Calibri">Media Foundation was run inside a secure </font><a href="https://msdn.microsoft.com/en-us/library/aa376846%28v=VS.85%29.aspx"><font size="3" face="Calibri">Protected-Media-Path</font></a><font size="3" face="Calibri"> process (usually for DRM content).</font> </li>    <li><font size="3" face="Calibri">Media Foundation was run inside a non-secure Protected-Media-Path process. This type of graph is used for increased reliability. If a component crashes, it does not crash the main process.</font> </li>    <li><font size="3" face="Calibri">Media Foundation was run inside the main process.</font> </li>    <li><font size="3" face="Calibri">The Format SDK was used.</font> </li>    <li><font size="3" face="Calibri">DirectShow was used.</font> </li> </ol>  <p><font size="4" face="Calibri"><strong>Was Media Foundation started or shut down?</strong></font></p>  <p>In log named ‘MediaFoundation-Platform &gt; Media Foundation Platform,’ look for:</p>  <blockquote>   <p><i><font size="3" face="Calibri">MFStartup returned 0x0</font></i></p>    <p><i><font size="3" face="Calibri">Start MFShutdown</font></i></p>    <p><i><font size="3" face="Calibri">End MFShutdown - return code 0x0</font></i></p> </blockquote>  <h4><font size="4" face="Calibri"><strong>Could the content be opened?</strong></font></h4>  <p>In the log named ‘MediaFoundation-Platform &gt; Media Foundation Platform,’ look for events similar to the following:</p>  <blockquote>   <p><i>Source Resolver Context(0x7318128) Resolve C:\Users\user1\Videos\Video1.45.wmv flags 0x21</i></p>    <p><i>Source Resolver Context(0x7318128) Trying Scheme Handler &quot;File Scheme Handler&quot;</i></p>    <p><i>Source Resolver Context(0x7318128) Trying Byte Scheme Handler CLSID(&quot;ASF Byte Stream Handler&quot;)</i></p>    <p><i>Source Resolver Context(0x7318128) SchemeHandler Result 0x0</i></p>    <p><i>Source Resolver Context(0x7318128) Byte stream Handler Result 0x0</i></p>    <p><i>Source Resolver Context(0x7318128) Resolving </i><i>file:///C:/Users/user1/Videos/Video1.wmv returned 0x0</i></p> </blockquote>  <h4><font size="4" face="Calibri"><strong>Were transforms found to decode/encode the content?</strong></font></h4>  <p><font size="3" face="Calibri">In the log named ‘MediaFoundation-Platform &gt; Media Foundation Platform,’ look for events similar to the following:</font></p>  <blockquote>   <p><i><font size="3" face="Calibri">MFTEnumEx flags 0x57, category {d6c02d4b-6833-45b4-971a-05a4b04bab91} for input type ({73646976-0000-0010-8000-00aa00389b71},{33564d57-0000-0010-8000-00aa00389b71}), output type ({00000000-0000-0000-0000-000000000000},{00000000-0000-0000-0000-000000000000})</font></i></p>    <p><i><font size="3" face="Calibri">Found matching software MFT &quot;WMVideo Decoder DMO&quot;</font></i></p>    <p><i><font size="3" face="Calibri">MFTEnumEx returned code 0x0, found 0 local MFTs, 0 hardware MFTs and 1 MFT CLSIDs</font></i></p> </blockquote>  <h4><font size="4" face="Calibri">Did the topology resolution succeed?</font></h4>  <p><font size="3" face="Calibri">In the log named ‘MediaFoundation &gt; Media Foundation Pipeline,’ look for:</font></p>  <blockquote>   <p><i><font size="3" face="Calibri">IMFTopoLoader::Load start</font></i></p> </blockquote>  <p><font size="3" face="Calibri">This event will be followed by </font></p>  <blockquote>   <p><i><font size="3" face="Calibri">IMFTopoLoader::Load returned 0x0</font></i></p> </blockquote>  <p><font size="3" face="Calibri">in case of success, or</font></p>  <blockquote>   <p><i><font size="3" face="Calibri">IMFTopoLoader::Load returned 0xc00d5212</font></i></p> </blockquote>  <p><font size="3" face="Calibri">in case of failure. (The exact error code may vary.)</font></p>  <h4><font face="Calibri"><strong>Did the Media Session start?</strong></font></h4>  <p><font size="3" face="Calibri">In the log named ‘MediaFoundation-Performance &gt; Media Foundation Performance,’ look for:</font></p>  <blockquote>   <p><i><font size="3" face="Calibri">Media Session Begin Start Tag=MsBp Object=0x88cec88 Parameter=0x0</font></i></p> </blockquote>  <h4><font size="4" face="Calibri"><strong>Did transforms process data?</strong></font></h4>  <p><font size="3" face="Calibri">In the log named ‘MediaFoundation-Performance &gt; Media Foundation Performance,’ look for events similar to the following:</font></p>  <blockquote>   <p><i><font size="3" face="Calibri">ProcessInput Tag=AfMs Object=0x62ddec0 Object Category=9 Sample=0x8686e28 Buffer Size=65536 Sample Time=0 Processing Time=149</font></i></p>    <p><i><font size="3" face="Calibri">ProcessOutput Tag=AfMs Object=0x62ddec0 Object Category=9 Sample=0x70efdd0 Buffer Size=62335 Sample Time=330000 Processing Time=17</font></i></p> </blockquote>  <p><font size="3" face="Calibri">That’s it. Do you find this article useful? Do you have questions on tracing your Media Foundation code? Please leave a comment.</font></p>]]></content:encoded>
    </item>
    <item>
      <title>MFDub</title>
      <link>https://docs.microsoft.com/archive/blogs/mf/mfdub</link>
      <pubDate>Fri, 12 Mar 2010 11:34:00 GMT</pubDate>
      <dc:creator><![CDATA[mfblog]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mf/2010/03/12/mfdub/</guid>
      <description><![CDATA[SummaryMFDub is a simple linear video editor built on Media Foundation, modeled after the free video...]]></description>
      <content:encoded><![CDATA[<H3><FONT size=3>Summary</FONT></H3><FONT size=2>MFDub is a simple linear video editor built on Media Foundation, modeled after the free video editor VirtualDub. MFDub can open any file format that can be resolved by the MF </FONT><A href="https://msdn.microsoft.com/en-us/library/ms700827(VS.85).aspx" mce_href="https://msdn.microsoft.com/en-us/library/ms700827(VS.85).aspx"><FONT size=2>source resolver</FONT></A><FONT size=2>, display frames of video from the file, apply a series of video or audio effects implemented as MF </FONT><A href="https://msdn.microsoft.com/en-us/library/ms703138(VS.85).aspx" mce_href="https://msdn.microsoft.com/en-us/library/ms703138(VS.85).aspx"><FONT size=2>transforms</FONT></A><FONT size=2>, and then save the file with effects applied to the ASF (WMV, WMA) file format or the MPEG4 file format. For example, one might open up a WMV file with blurry video using MFDub, apply the unsharp mask transform to create a video with a sharper image, and then save the output video to an MPEG4 file. </FONT>
<H3><FONT size=2>Technologies Demonstrated</FONT></H3><FONT size=2>MFDub combines many different MF components together to create a useful application. Some of the components used include: </FONT>
<UL>
<LI></FONT><A href="https://msdn.microsoft.com/en-us/library/dd374655(VS.85).aspx" mce_href="https://msdn.microsoft.com/en-us/library/dd374655(VS.85).aspx"><FONT size=2>IMFSourceReader</FONT></A><FONT size=2> – used to obtain raw video frames for display when the user is examining the video, and to read frames when MFDub is writing a new output file. </FONT></LI>
<LI></FONT><A href="https://msdn.microsoft.com/en-us/library/ms705662(VS.85).aspx" mce_href="https://msdn.microsoft.com/en-us/library/ms705662(VS.85).aspx"><FONT size=2>IMFMediaSession</FONT></A><FONT size=2> – used to play the video normally so the user can preview what the video will actually look like in a media player. </FONT></LI>
<LI></FONT><A href="https://msdn.microsoft.com/en-us/library/dd374642(VS.85).aspx" mce_href="https://msdn.microsoft.com/en-us/library/dd374642(VS.85).aspx"><FONT size=2>IMFSinkWriter</FONT></A><FONT size=2> – used to write the output file when the user is done editing. </FONT></LI>
<LI><A href="https://msdn.microsoft.com/en-us/library/ms696260(VS.85).aspx" mce_href="https://msdn.microsoft.com/en-us/library/ms696260(VS.85).aspx"><FONT size=2>IMFTransform</FONT></A><FONT size=2> – video and audio effects are implemented as MF transforms. MFDub communicates with transforms directly to process video effects. </FONT></LI></UL>
<H3><FONT size=3>Setup</FONT></H3>
<P><FONT size=2>MFVE.exe is the main application. Just double click the MFVE.exe file to run it. MFVEUTIL.dll contains the video and audio effects that make MFVE.exe useful. MFDub would be pretty boring without any effects! Make sure to register MFVEUTIL.dll before using MFDub, by opening up an elevated command prompt window, navigating to the directory containing MFDub, and entering the command ‘regsvr32 MFVEUTIL.dll’. You can create an elevated command prompt window by going to the Start Menu, selecting All Programs, selecting Accessories, right clicking on ‘Command Prompt’ and selecting ‘Run as Administrator’.</FONT></P>
<H2><FONT size=3>How to Use MF Dub</FONT></H2>
<P><FONT size=2>When you start MFDub, the only thing you can do at first is open a file. Click on the Open button on the toolbar, and find a video file to work with. By default, MF supports .asf, .wmv, .mp4, .m4v, and some .avi files. MFDub should then look something like this:</FONT></P>
<P><FONT size=3></FONT></P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/MFDub_10215/mfdub1_2.jpg" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFDub_10215/mfdub1_2.jpg" mce_href="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFDub_10215/mfdub1_2.jpg"><FONT size=3></FONT></A><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/MFDub_10215/mfdub1_2.jpg" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFDub_10215/mfdub1_2.jpg" mce_href="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFDub_10215/mfdub1_2.jpg"><IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: block; FLOAT: none; MARGIN-LEFT: auto; BORDER-TOP: 0px; MARGIN-RIGHT: auto; BORDER-RIGHT: 0px" title="Openning and previewing a video file" border=0 alt="Openning and previewing a video file" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/MFDub_10215/mfdub1_thumb.jpg" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFDub_10215/mfdub1_thumb.jpg" width=374 height=226 mce_src="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFDub_10215/mfdub1_thumb.jpg"></A></A></A><FONT size=3> </FONT></P>
<P><FONT size=3></FONT></P>
<P><FONT size=2>Now let’s apply some video effects. Once you click the ‘Video MFTs’ button, a dialog box is displayed with a list of transforms. (You did register MFVEUTIL.dll as noted under setup, right?) You can click on the name of each transform to get a short description about what it does. I am going to go with the edge finder since it applies an obvious effect to the video:</FONT></P>
<P><FONT size=3></FONT></P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/MFDub_10215/image_4.png" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFDub_10215/image_4.png" mce_href="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFDub_10215/image_4.png"><FONT size=3></A></FONT>&nbsp;</P>
<P><FONT size=3></FONT></P>
<P><FONT size=2>Notice how the box labeled ‘edge finder’ has appeared in my list of transforms. If you do not like the effect, you can click and drag the box outside the transform list and drop it – MFDub will get rid of the transform. You can also add more than one transform at a time, if you like. Using the ‘unsharp mask’ transform with a gamma value of 3 really sharpens up the edges. You can switch the order of the transforms by clicking and dragging the transform box to where you would like it to be in the transform list. The order of the transforms can greatly affect the output video.</FONT></P>
<P><FONT size=2>Since I really like transforms, I am just going to apply them all except for the resize and crop transform. Since I applied an audio transform, I used the play button to play the preview of the edited video to hear that I set the volume compression level to a reasonable value. Here’s what MFDub looks like right before I save the video:</FONT></P>
<P><FONT size=3></FONT></P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/MFDub_10215/image_6.png" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFDub_10215/image_6.png" mce_href="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFDub_10215/image_6.png"><FONT size=3></A></FONT>&nbsp;</P>
<P><FONT size=3></FONT></P>
<P><FONT size=2>I do not know exactly what I would do with such an output video. Maybe I could sell it as piece of cubist art. Anyway, the final step is to save the output video to a file. Click the save dialog and enter a file name for the output video. MFDub will automatically determine the file format for the output video based upon the extension. For example, a .wmv file will be an ASF format file, and an .mp4 file will be an MPEG4 format file. Since my input file was a .wmv, I will make the output file a .mp4 for a change. Once you click save, you will be informed of the encoding progress at the bottom of the window. Once encoding is complete, you can play back your video in any media player that supports the file format you selected. Here is my output video playing back in Windows Media Player:</FONT></P>
<P><FONT size=3></FONT></P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/MFDub_10215/MFDub7_2.jpg" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFDub_10215/MFDub7_2.jpg" mce_href="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFDub_10215/MFDub7_2.jpg"><IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: block; FLOAT: none; MARGIN-LEFT: auto; BORDER-TOP: 0px; MARGIN-RIGHT: auto; BORDER-RIGHT: 0px" title=MFDub7 border=0 alt=MFDub7 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/MFDub_10215/MFDub7_thumb.jpg" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFDub_10215/MFDub7_thumb.jpg" width=244 height=195 mce_src="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFDub_10215/MFDub7_thumb.jpg"></A> </P>
<H3><FONT size=3></FONT></H3>
<H3><FONT size=3>Design Choices</FONT></H3>
<P><FONT size=2>MFDub brings a bunch of different MF components for different purposes. Part of the core functionality of MFDub is the ability to display individual video frames as the user seeks around the video using the track bar control. The source reader provides a simple and lightweight way for grabbing video frames from a media file. Then these video frames can be processed manually through a series of transforms. The media session does not easily allow for grabbing individual frames at a time, and also does not easily allow insertion and removal for transforms.</FONT></P>
<P><FONT size=2>Playing the video presents a different set of problems. The source reader does not handle things like audio/video synchronization, and any rendering has to be done manually. The media session handles playing video very well, and hides many of the complexities of playback from the application. This made it a good choice for handling the preview playback.</FONT></P>
<P><FONT size=2>For writing the output video, MFDub uses the sink writer. The sink writer presents an easy way to write raw video frames to a file. The transcode API provides a more configurable way of writing a new output file, but since MFDub already had the manual transform processing and did not require the extra customizability, the sink writer was used instead.</FONT></P>
<H3><FONT size=3>Interesting Code</FONT></H3>
<UL>
<LI><FONT size=2>Transformapplier.cpp shows how an application can use an IMFTransform independently of any other MF components to process audio and video data. </FONT></LI>
<LI><FONT size=2>Mediatranscoder.cpp combines the source reader and the sink writer into a component that can be used to transcode an input file into an output file. </FONT></LI>
<LI><FONT size=2>Topologybuilder.cpp demonstrates how an application might build a topology for use in the MF media session. </FONT></LI>
<LI><FONT size=2>Sampleprovider.cpp uses the source reader to create a simple component for reading video frames.</FONT> </LI></UL>
<P><FONT size=2>In the dll directory, you can find the source code to all of the transforms that come with MFDub by default. MFDub uses a set of base classes for transforms to implement all of the common functionality, leaving just the data processing to be implemented for the actual transform object.</FONT></P>
<H3><FONT size=3>Limitations</FONT></H3>
<P><FONT size=2>Dragging the tracker around to seek around the video can be slow. MFDub uses a rather naïve implementation for grabbing samples from the source file. With some cleverness and creativity, the performance of ‘scrubbing’ the video using the tracker could be improved.</FONT></P>
<P><FONT size=2>MFDub only has several transforms. Without more transforms, it is not terribly useful for video editing. Thankfully, the base classes make it pretty easy to create your own transforms!</FONT></P>
<P><B><FONT size=3>Downloading the Sample</FONT></B></P>
<P><FONT size=2>You can download MFDub from </FONT><A href="https://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=mfblog&amp;DownloadId=9371" mce_href="https://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=mfblog&amp;DownloadId=9371"><FONT size=2>https://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=mfblog&amp;DownloadId=9371</FONT></A><FONT size=2>. </FONT></P>
<P><FONT size=2>Follow the instructions at </FONT><A href="https://code.msdn.microsoft.com/mfblog" mce_href="https://code.msdn.microsoft.com/mfblog"><FONT size=2>https://code.msdn.microsoft.com/mfblog</FONT></A><FONT size=2> for tips and instructions to build the sample.</FONT></P>
<P><FONT size=2></FONT></P>
<P><FONT size=2></FONT></P>
<OL><FONT size=2></FONT></OL>
<P><I><FONT size=2>This posting is provided "AS IS" with no warranties and confers no rights.</FONT></I></P>]]></content:encoded>
    </item>
    <item>
      <title>MFManagedEncode</title>
      <link>https://docs.microsoft.com/archive/blogs/mf/mfmanagedencode</link>
      <pubDate>Thu, 18 Feb 2010 14:43:00 GMT</pubDate>
      <dc:creator><![CDATA[mfblog]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mf/2010/02/18/mfmanagedencode/</guid>
      <description><![CDATA[MFManagedEncode.exe
This is a managed tool written in C# and XAML that converts files from one...]]></description>
      <content:encoded><![CDATA[<P><B>MFManagedEncode.exe</B></P>
<P>This is a managed tool written in C# and <A href="https://msdn.microsoft.com/en-us/library/ms752059.aspx" mce_href="https://msdn.microsoft.com/en-us/library/ms752059.aspx">XAML</A> that converts files from one media format to another. The source code is provided to use as a reference on how to interop with <A href="https://msdn.microsoft.com/en-us/library/dd389281.aspx" mce_href="https://msdn.microsoft.com/en-us/library/dd389281.aspx">source reader</A>, <A href="https://msdn.microsoft.com/en-us/library/dd374642.aspx" mce_href="https://msdn.microsoft.com/en-us/library/dd374642.aspx">sink writer</A> and the <A href="https://msdn.microsoft.com/en-us/library/dd317903.aspx" mce_href="https://msdn.microsoft.com/en-us/library/dd317903.aspx">transcode API</A> from a managed environment.</P>
<P>The sample previews media files using WPF’s <A href="https://msdn.microsoft.com/en-us/library/system.windows.controls.mediaelement.aspx" mce_href="https://msdn.microsoft.com/en-us/library/system.windows.controls.mediaelement.aspx">MediaElement</A> object and a custom control that can be used to trim the output media. </P>
<P>Supported output formats:</P>
<UL>
<LI>Windows Media (WMV with WMA)</LI>
<LI>MPEG-4 (H.264 with AAC)</LI></UL>
<P><B>Technique</B></P>
<P>The tool converts media files using the basic functionality of new APIs introduced with Windows 7. Two different metho<A title=_GoBack name=_GoBack></A>ds are implemented by the tool:</P>
<UL>
<LI>Configure the media session using the high level transcode API.</LI>
<LI>Use source reader and sink writer.</LI></UL>
<P>Since Media Foundation is built on <A href="https://www.microsoft.com/com/default.mspx" mce_href="https://www.microsoft.com/com/default.mspx">COM</A> the required interfaces and unmanaged calls were ported to C# using <A href="https://msdn.microsoft.com/en-us/library/sd10k43k.aspx" mce_href="https://msdn.microsoft.com/en-us/library/sd10k43k.aspx">.NET interoperability</A> capabilities.</P>
<P>The transcode API provides the following benefits:</P>
<UL>
<LI>The media session controls the operation. Therefore, there is no need to manipulate the samples manually.</LI>
<LI>Media samples are not brought to the managed environment which improves speed and memory usage.</LI></UL>
<P>Source reader and sink writer provide the following benefits:</P>
<UL>
<LI>Media sample attributes can be edited individually which gives more control to the developer.</LI>
<LI>The media sample raw data can be acquired from the <A href="https://msdn.microsoft.com/en-us/library/ms696261.aspx" mce_href="https://msdn.microsoft.com/en-us/library/ms696261.aspx">buffers</A> and used for other purposes (for example it is easy to copy the data from a video sample to a <A href="https://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx" mce_href="https://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx">System.Drawing.Bitmap</A> object).</LI></UL>
<P><B>Usage</B></P>
<P>When the application is executed the main window will show up (Figure 1).</P>
<CENTER><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/MFManagedEncode_CE2B/clip_image002_2.jpg" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFManagedEncode_CE2B/clip_image002_2.jpg" mce_href="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFManagedEncode_CE2B/clip_image002_2.jpg"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image002 border=0 alt=clip_image002 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/MFManagedEncode_CE2B/clip_image002_2.jpg" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFManagedEncode_CE2B/clip_image002_2.jpg" width=359 height=313></A> <BR>Figure 1</CENTER>
<OL>
<LI>&nbsp;Select the media file you want to convert by clicking the “Browse…” button to the right of the “Source” text box. When you do this the source location will be automatically chosen as the output folder.</LI>
<LI>&nbsp;Change the output folder by clicking the “Browse…” button to the right of the “Output folder” text box.</LI>
<LI>&nbsp;Start playback by clicking on the media frame.</LI>
<LI>&nbsp;Seek to different positions by moving the arrow located below the time bar.</LI>
<LI>&nbsp;Convert only a selected portion of the media by moving the blue controls in the time bar to adjust the start and end times.</LI>
<LI>&nbsp;Select the output media format from the “Format” dropdown list.</LI>
<LI>&nbsp;Select the output video size from the “Video size” dropdown list.</LI>
<LI>&nbsp;Bring up options for changing the audio codec, video codec, audio bit rate or video bit rate by clicking on “Advanced options” at the bottom-left corner of the window.</LI>
<LI>&nbsp;Start the transcode operation by clicking continue. The progress window will show up and the conversion will begin (Figure 2).</LI></OL>
<CENTER><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/MFManagedEncode_CE2B/clip_image004_2.jpg" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFManagedEncode_CE2B/clip_image004_2.jpg" mce_href="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFManagedEncode_CE2B/clip_image004_2.jpg"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image004 border=0 alt=clip_image004 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/MFManagedEncode_CE2B/clip_image004_2.jpg" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFManagedEncode_CE2B/clip_image004_2.jpg" width=307 height=162 mce_src="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFManagedEncode_CE2B/clip_image004_2.jpg"></A> <BR>Figure 2</CENTER>
<P>&nbsp;&nbsp; 10. The conversion window (Figure 2) will be automatically closed when the conversion is complete.</P>
<P><B>Limitations</B></P>
<P>The sample is made using WPF so Visual Studio 2008 or later is required. If you don’t have Visual Studio 2008 the sample can be compiled using Visual C# 2008 Express Edition which can be <A href="https://www.microsoft.com/express/Downloads/" mce_href="https://www.microsoft.com/express/Downloads/">downloaded for free from the Microsoft Website</A>.</P>
<P>Only the COM interface methods used by the tool have been tested; marshaling of unused methods could be wrong or missing the correct enumerations or object definitions.</P>
<P><B>Project Structure</B></P>
<P><EM>\MFManagedEncode.csproj</EM></P>
<BLOCKQUOTE>
<P>The main C# project generated by Visual Studio. It contains information about the platforms, configurations and project&nbsp; features.</P></BLOCKQUOTE>
<P><EM>\MediaFoundation\Interop\Classes.cs</EM></P>
<BLOCKQUOTE>
<P>Definitions of the COM classes needed.</P></BLOCKQUOTE>
<P><EM>\MediaFoundation\Interop\Constants.cs</EM></P>
<BLOCKQUOTE>
<P>Media Foundation constants needed.</P></BLOCKQUOTE>
<P><EM>\MediaFoundation\Interop\Enums.cs</EM></P>
<BLOCKQUOTE>
<P>Media Foundation enumerations needed.</P></BLOCKQUOTE>
<P><EM>\MediaFoundation\Interop\Interfaces.cs</EM></P>
<BLOCKQUOTE>
<P>Definition of the Media Foundation COM interfaces needed to perform the format conversion.</P></BLOCKQUOTE>
<P><EM>\MediaFoundation\Interop\Structures.cs</EM></P>
<BLOCKQUOTE>
<P>Structures that help interoperating with Media Foundation COM objects.</P></BLOCKQUOTE>
<P><EM>\MediaFoundation\Interfaces\ISimpleEncode.cs</EM></P>
<BLOCKQUOTE>
<P>C# interface used by the encoding classes.</P></BLOCKQUOTE>
<P><EM>\MediaFoundation\Classes\SimpleFastEncode.cs</EM></P>
<BLOCKQUOTE>
<P>C# class that inherits ISimpleEncode and encodes content using the Windows 7 transcode API.</P></BLOCKQUOTE>
<P><EM>\MediaFoundation\Classes\SimpleSinklWriterEncode.cs</EM></P>
<BLOCKQUOTE>
<P>C# class that inherits ISimpleEncode and encodes content using source reader and sink writer.</P></BLOCKQUOTE>
<P><EM>\MediaFoundation\Classes\EncapsulatedSample.cs</EM></P>
<BLOCKQUOTE>
<P>C# class that keeps track of the unmanaged memory used by samples and simplifies garbage collection.</P></BLOCKQUOTE>
<P><EM>\MediaFoundation\Common\Classes.cs</EM></P>
<BLOCKQUOTE>
<P>Support classes used by the tool.</P></BLOCKQUOTE>
<P><EM>\MediaFoundation\Common\Helper.cs</EM></P>
<BLOCKQUOTE>
<P>Exports the required Media Foundation functions from mfplat.dll and mf.dll.</P></BLOCKQUOTE>
<P><EM>\App.xaml</EM></P>
<BLOCKQUOTE>
<P>Holds the attributes that control the startup behavior. </P></BLOCKQUOTE>
<P><EM>\App.xaml.cs</EM></P>
<BLOCKQUOTE>
<P>Interaction logic for App.xaml.</P></BLOCKQUOTE>
<P><EM>\GUI\Controls\VideoTrimmer.xaml</EM></P>
<BLOCKQUOTE>
<P>Graphic design and animations of the user control used to trim media content.</P></BLOCKQUOTE>
<P><EM>\GUI\Controls\VideoTrimmer.xaml.cs</EM></P>
<BLOCKQUOTE>
<P>Interaction logic for VideoTrimmer.xaml which handles user input and events such as resizing.</P></BLOCKQUOTE>
<P><EM>\GUI\Windows\MainWindow.xaml</EM></P>
<BLOCKQUOTE>
<P>The main application window used to load media files and set the conversion parameters.</P></BLOCKQUOTE>
<P><EM>\GUI\Windows\MainWindow.xaml.cs</EM></P>
<BLOCKQUOTE>
<P>Interaction logic for MainWindow.xaml.</P></BLOCKQUOTE>
<P><EM>\GUI\Windows\ProgressWindow.xaml</EM></P>
<BLOCKQUOTE>
<P>The window that is shown during format conversion and displays the progress and estimated remaining time.</P></BLOCKQUOTE>
<P><EM>\GUI\Windows\ProgressWindow.xaml.cs</EM></P>
<BLOCKQUOTE>
<P align=left>Interaction logic for ProgressWindow.xaml.</P></BLOCKQUOTE>
<P><B>Downloading the Sample</B></P>
<P>You can download MFManagedEncode from <A href="https://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=mfblog&amp;DownloadId=9174" mce_href="https://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=mfblog&amp;DownloadId=9174">https://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=mfblog&amp;DownloadId=9174</A></P>
<P>Follow the instruction at <A href="https://code.msdn.microsoft.com/mfblog" mce_href="https://code.msdn.microsoft.com/mfblog">https://code.msdn.microsoft.com/mfblog</A> for tips and instructions to build the sample.</P>
<P><I>This posting is provided "AS IS" with no warranties and confers no rights.</I></P>]]></content:encoded>
    </item>
    <item>
      <title>MFMediaPropDump</title>
      <link>https://docs.microsoft.com/archive/blogs/mf/mfmediapropdump</link>
      <pubDate>Mon, 11 Jan 2010 17:57:57 GMT</pubDate>
      <dc:creator><![CDATA[mfblog]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mf/2010/01/11/mfmediapropdump/</guid>
      <description><![CDATA[This is a command line tool showcasing the Windows 7 Media Foundation APIs to read media source...]]></description>
      <content:encoded><![CDATA[<p></p>  <p><font size="3" face="Calibri"></font></p>  <p><font size="2" face="cal">This is a command line tool showcasing the Windows 7 Media Foundation APIs to read media source attributes and metadata. It also shows how to leverage the Windows Media Format SDK to read DRM properties. The source code can be useful for learning about Media Foundation. The built executable can be useful for dumping media file properties for debugging, or simply to get information about a media file, such as the frame size, frame rate, bit rate, or sample rate.</font></p>  <p><font size="2" face="cal">This sample can display properties for any media file format that is supported by Media Foundation.</font></p>  <p><font size="2" face="cal">Media Foundation does not currently have support for reading DRM properties, so the legacy Format SDK is used for that reason in the sample. Using Format SDK is otherwise discouraged, as it supports only Windows Media file formats and has some other key disadvantages. Media Foundation supports a much wider set of media file formats.</font></p>  <p><font size="2" face="cal">Here’s a sample screenshot of MFMediaPropDump:</font></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/MFMediaPropDump_E977/clip_image002%5B1%5D.jpg" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFMediaPropDump_E977/clip_image002%5B1%5D.jpg"></a><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/MFMediaPropDump_E977/clip_image002%5B1%5D.jpg" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFMediaPropDump_E977/clip_image002%5B1%5D.jpg"><font size="2" face="cal"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="clip_image002[1]" border="0" alt="clip_image002[1]" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/MFMediaPropDump_E977/clip_image002%5B1%5D_thumb.jpg" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFMediaPropDump_E977/clip_image002%5B1%5D_thumb.jpg" width="628" height="816" /></font></a></a></p>  <p align="center"><font size="2" face="cal">Figure 1. Dumping media properties of a WMV file using MFMediaPropDump</font></p>  <p><b><font size="2" face="cal">Techniques:</font></b></p>  <p><font size="2" face="cal">Media files contain numerous properties that apply to the file as a whole. Some properties specify the parameters with which the file was encoded (media source attributes), some contain descriptive information (metadata), and some contain information on usage restrictions (DRM properties).</font></p>  <p><font size="2" face="cal">Although metadata contains descriptive information for the media content, it might also contain information about the file encoding. Sometimes it’s faster to access file-encoding information through metadata than through media source attributes.</font></p>  <p><font size="2" face="cal">DRM properties are available only for a Windows Media DRM protected file and reside in the DRM license.</font></p>  <p><font size="2" face="cal">Examples of encoding parameters are encoding algorithm (media subtype), video frame size, video frame rate, audio bit rate, and audio sample rate. Encoding parameters are read using MF attributes.</font></p>  <p><font size="2" face="cal">Examples of metadata are title, artist, composer, genre, and movie director. There are two ways to read metadata: by using Media Foundation with the IMFMetadata interface (Media Foundation metadata), and by using the Windows Shell IPropertyStore interface (shell metadata). Media Foundation metadata and shell metadata complement each other. Shell metadata pertains not only to media files but to a much wider range of files on the system and the set of properties even for media files is richer than Media Foundation metadata. Media Foundation metadata on the other hand pertains only to media files and has support for per-stream metadata in a media file that shell metadata doesn’t have. </font></p>  <p><font size="2" face="cal">Examples of DRM properties are the number of allowed playbacks and the number of synchronizations to portable devices.</font></p>  <p><i><font size="2" face="cal">How to read media source attributes:</font></i></p>  <ul>   <li><font size="2" face="cal">Create a media source (IMFMediaSource) from the media content URL. </font></li>    <li><font size="2" face="cal">Get the presentation descriptor (IMFPresentationDescriptor) from the media source. </font>      <ul>       <li><font size="2" face="cal">Read presentation descriptor attributes (IMFAttributes). </font></li>     </ul>   </li>    <li><font size="2" face="cal">Get the stream descriptor (IMFStreamDescriptor) for each stream in presentation descriptor. </font>      <ul>       <li><font size="2" face="cal">Read stream descriptor attributes (IMFAttributes). </font></li>     </ul>   </li>    <li><font size="2" face="cal">Get the media type (IMFMediaType) for each stream descriptor. </font>      <ul>       <li><font size="2" face="cal">Read media type attributes (IMFAttributes). </font></li>     </ul>   </li> </ul>  <p><i><font size="2" face="cal">How to read metadata:</font></i></p>  <ul>   <li><font size="2" face="cal">Create the media source (IMFMediaSource) from the media content URL. </font></li>    <li><font size="2" face="cal">To read Media Foundation metadata, use the IMFGetService interface to get the IMFMetadata interface from the media source. Use the IMFMetadata interface to read the metadata. </font></li>    <li><font size="2" face="cal">To read shell metadata, use IMFGetService to get the IPropertyStore interface from the media source. Use the IPropertyStore interface to read the metadata. </font></li> </ul>  <p><i><font size="2" face="cal">How to read DRM properties:</font></i></p>  <ul>   <li><font size="2" face="cal">Create the Format SDK metadata editor (IWMMetadataEditor) from the media content path. </font></li>    <li><font size="2" face="cal">Get the DRM editor (IWMDRMEditor) from the metadata editor. </font></li>    <li><font size="2" face="cal">Query the DRM editor for every DRM property. </font></li> </ul>  <p><font size="2" face="cal">To read more about presentation descriptors and stream descriptors: </font><a href="https://msdn.microsoft.com/en-us/library/ms698961(VS.85).aspx"><font size="2" face="cal">https://msdn.microsoft.com/en-us/library/ms698961(VS.85).aspx</font></a></p>  <p><font size="2" face="cal">To read more about media types: </font><a href="https://msdn.microsoft.com/en-us/library/bb530109(VS.85).aspx"><font size="2" face="cal">https://msdn.microsoft.com/en-us/library/bb530109(VS.85).aspx</font></a></p>  <p><font size="2" face="cal">To read more about media attributes: </font><a href="https://msdn.microsoft.com/en-us/library/dd206754(VS.85).aspx"><font size="2" face="cal">https://msdn.microsoft.com/en-us/library/dd206754(VS.85).aspx</font></a></p>  <p><font size="2" face="cal">To read more about media properties: </font><a href="https://msdn.microsoft.com/en-us/library/dd206755(VS.85).aspx"><font size="2" face="cal">https://msdn.microsoft.com/en-us/library/dd206755(VS.85).aspx</font></a></p>  <p><font size="2" face="cal">To read more about metadata: </font><a href="https://msdn.microsoft.com/en-us/library/aa368930(VS.85).aspx"><font size="2" face="cal">https://msdn.microsoft.com/en-us/library/aa368930(VS.85).aspx</font></a></p>  <p><font size="2" face="cal">To read more about reading DRM properties: </font><a href="https://msdn.microsoft.com/en-us/library/dd743976(VS.85).aspx"><font size="2" face="cal">https://msdn.microsoft.com/en-us/library/dd743976(VS.85).aspx</font></a></p>  <p><b><font size="2" face="cal">Project Structure: </font></b></p> <dl><dt><font size="2"><font face="cal"><i>MediaPropDump.vcproj</i> </font></font></dt><dd><font size="2" face="cal">The main project file for VC++ projects generated using an Application Wizard. It contains information about the version of Visual C++ that generated the file, and information about the platforms, configurations, and project features selected with the Application Wizard. </font></dd><dt><font size="2"><font face="cal"><i>wmain.cpp</i> </font></font></dt><dd><font size="2" face="cal">Contains the application entry point, command line parsing, and error reporting. </font></dd><dt><font size="2"><font face="cal"><i>MediaPropDump.cpp</i> </font></font></dt><dd><font size="2" face="cal">Contains routines to display media type, metadata, and DRM properties. </font></dd><dt><font size="2"><font face="cal"><i>SourceResolver.cpp</i> </font></font></dt><dd><font size="2" face="cal">Contains a function that creates an IMFMediaSource instance from a from file path, by using the IMFSourceResolver interface. </font></dd><dt><font size="2"><font face="cal"><i>MediaTypeDump.cpp</i> </font></font></dt><dd><font size="2" face="cal">Displays media attributes from the presentation descriptor, stream descriptors, and media types exposed by a media source. </font></dd><dt><font size="2"><font face="cal"><i>MetadataDump.cpp</i> </font></font></dt><dd><font size="2" face="cal">Displays both Media Foundation metadata and shell metadata. </font></dd><dt><font size="2"><font face="cal"><i>DRMDump.cpp</i> </font></font></dt><dd><font size="2" face="cal">Displays DRM properties by using Format SDK. </font></dd><dt><font size="2"><font face="cal"><i>Helper.cpp</i> </font></font></dt><dd><font size="2" face="cal">Contains helper routines for output formatting. </font></dd></dl>  <p><b><font size="2" face="cal">Usage:</font></b></p>  <p><font size="2" face="cal">MFMediaPropDump.exe [-?] -f file</font></p> <dl><dt><font size="2"><font face="cal"><i>-?</i> </font></font></dt><dd><font size="2" face="cal">Display usage information. </font></dd><dt><font size="2"><font face="cal"><i>-f file</i> </font></font></dt><dd><font size="2" face="cal">This is the path to a file with any media format supported by Media Foundation. List of supported media formats: </font><a href="https://msdn.microsoft.com/en-us/library/dd757927(VS.85).aspx"><font size="2" face="cal">https://msdn.microsoft.com/en-us/library/dd757927(VS.85).aspx</font></a><font size="2" face="cal"> </font></dd></dl>  <p><b><font size="2" face="cal">Examples:</font></b></p> <dl><dt><font size="2" face="cal">Dump WMV file properties: </font></dt><dd><font size="2" face="cal">MFMediaPropDump.exe -f input.wmv </font></dd><dt><font size="2" face="cal">Dump MPEG-4 file properties: </font></dt><dd><font size="2" face="cal">MFMediaPropDump.exe -f input.mp4 </font></dd><dt><font size="2" face="cal">Dump MP3 file properties: </font></dt><dd><font size="2" face="cal">MFMediaPropDump.exe -f input.mp3 </font></dd><dt><font size="2" face="cal">Dump AVI file properties: </font></dt><dd><font size="2" face="cal">MFMediaPropDump.exe -f input.avi </font></dd></dl>  <p><b><font size="2" face="cal">Limitations:</font></b></p>  <ol>   <li><font size="2" face="cal">For DRM properties in a file, the DRM license should be acquired first. This can be done simply by playing the file in Windows Media Player, which will trigger license acquisition (either silent or non-silent, which prompts the user to acquire the license). Once the license is acquired, you can use MFMediaPropDump to display DRM properties in the file. </font></li>    <li><font size="2" face="cal">The tool fails if the file format is not supported by Media Foundation. </font></li>    <li><font size="2" face="cal">For ASF files with multi-language Media Foundation metadata the tool currently dumps only the default language metadata. </font></li> </ol>  <p><b><font size="2" face="cal">Downloading the Sample</font></b></p>  <p><font size="2" face="cal">You can download MFMediaPropDump from </font><a href="https://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=mfblog&amp;DownloadId=8757"><font size="2" face="cal">https://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=mfblog&amp;DownloadId=8757</font></a><font size="2" face="cal">. </font></p>  <p><font size="2" face="cal">Follow the instructions at </font><a href="https://code.msdn.microsoft.com/mfblog"><font size="2" face="cal">https://code.msdn.microsoft.com/mfblog</font></a><font size="2" face="cal"> for tips and instructions to build the sample.</font></p>  <p><font size="2" face="cal"></font></p>  <p><font size="2" face="cal"></font></p>  <ol><font size="2" face="cal"></font></ol>  <p><i><font size="2" face="cal">This posting is provided &quot;AS IS&quot; with no warranties and confers no rights.</font></i></p>]]></content:encoded>
    </item>
    <item>
      <title>MFCopy</title>
      <link>https://docs.microsoft.com/archive/blogs/mf/mfcopy</link>
      <pubDate>Wed, 16 Dec 2009 12:07:25 GMT</pubDate>
      <dc:creator><![CDATA[mfblog]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mf/2009/12/16/mfcopy/</guid>
      <description><![CDATA[MFCopy.exe - This is a command line tool showcasing the Windows 7 Media Foundation source reader and...]]></description>
      <content:encoded><![CDATA[<p><font size="2" face="cali">MFCopy.exe - This is a command line tool showcasing the Windows 7 Media Foundation <em>source reader</em> and <em>sink writer</em> APIs. This tool copies multimedia files from one multimedia container to another. Copying can involve simply remultiplexing the streams, transcoding to convert the streams to a different format. The source code is provided to use as a reference for learning about the source reader and sink writer.</font></p>  <p><b><font size="2" face="cali">Techniques:</font></b></p>  <p><font size="2"><font face="cali"><i>Transcoding</i> is converting from one media format to another. The previous blog post described three mechanisms that Media Foundation provides to perform transcoding, taking a detailed look at the transcode API.</font></font></p>  <ul>   <li><font size="2" face="cali">Configure the Media Foundation </font><a href="https://msdn.microsoft.com/en-us/library/ms703988(VS.85).aspx"><font size="2" face="cali">media session</font></a><font size="2" face="cali"> directly. </font></li>    <li><font size="2" face="cali">Use the higher level </font><a href="https://msdn.microsoft.com/en-us/library/dd317903(VS.85).aspx"><font size="2" face="cali">transcode API</font></a><font size="2" face="cali"> to configure the media session. </font></li>    <li><font size="2" face="cali">Use </font><a href="https://msdn.microsoft.com/en-us/library/dd389281(VS.85).aspx"><font size="2" face="cali">source reader</font></a><font size="2" face="cali"> and </font><a href="https://msdn.microsoft.com/en-us/library/dd388105(VS.85).aspx"><font size="2" face="cali">sink writer</font></a><font size="2" face="cali">. </font></li> </ul>  <p><font size="2" face="cali">&#160;</font></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/MFSimpleEncode_FA70/image_4.png" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFSimpleEncode_FA70/image_4.png"><font size="2" face="cali"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="clip_image002" border="0" alt="clip_image002" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/MFCopy_AA50/clip_image002_09d41dde-a65b-43ab-816d-6505194e3629.gif" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFCopy_AA50/clip_image002_09d41dde-a65b-43ab-816d-6505194e3629.gif" width="244" height="148" /></font></a></p>  <p align="center"><font size="2" face="cali">Figure 1. Three ways to perform transcoding</font></p>  <p align="center"><font size="2" face="cali">&#160;</font></p>  <p><font size="2" face="cali">We will now describe the source reader and sink writer objects, and how they can be used for transcoding.</font></p>  <p><i><font size="2" face="cali">Source Reader:</font></i></p>  <p><font size="2" face="cali">The source reader is a Media Foundation component that provides direct access to multimedia data. Applications can use the source reader to extract sample data in the native format (usually compressed, but not necessarily), or can request that the source reader decode the multimedia data and output uncompressed samples. The source reader provides a consistent API regardless or container or format. Since it is built on the Media Foundation platform, the source reader supports any of the media sources and codecs registered with the platform.</font></p>  <p><i><font size="2" face="cali">How to use the Source Reader:</font></i></p>  <ul>   <li><font size="2" face="cali">Create the reader object from either a URL, a byte stream, or an existing media source instance. </font></li>    <li><font size="2" face="cali">Select or deselect streams. </font></li>    <li><font size="2" face="cali">Configure the desired output format for the streams. </font></li>    <li><font size="2" face="cali">Seek to the starting position if desired. </font>      <ul>       <li><font size="2" face="cali">Process multimedia data by calling IMFSourceReader::ReadSample until reaching the end of the stream, or until you have processed as much data as you want. The source reader supports both synchronous and asynchronous processing. </font></li>     </ul>   </li> </ul>  <p><font size="2" face="cali">To read more about the source reader: </font><a href="https://msdn.microsoft.com/en-us/library/dd389281(VS.85).aspx"><font size="2" face="cali">https://msdn.microsoft.com/en-us/library/dd389281(VS.85).aspx</font></a></p>  <p><i><font size="2" face="cali">Sink Writer:</font></i></p>  <p><font size="2" face="cali">The sink writer is a Media Foundation component that provides a simple way to generate multimedia files. The application configures the target container and format for each stream and then gives each sample received from the source reader to the writer object. Like the source reader, the sink writer provides a consistent API regardless of the destination container or format.</font></p>  <p><i><font size="2" face="cali">How to use the Sink Writer:</font></i></p>  <ul>   <li><font size="2" face="cali">Create the writer object from either a URL, a byte stream, or an existing media sink instance. </font></li>    <li><font size="2" face="cali">Add output streams, specifying the format of the data that will be written to the file. </font></li>    <li><font size="2" face="cali">Configure the input format, specifying the format of the data that will be passed to sink writer. </font></li>    <li><font size="2" face="cali">Call IMFSinkWriter::BeginWriting. </font></li>    <li><font size="2" face="cali">Process multimedia data by calling IMFSinkWriter::WriteSample until the end of the stream.Call IMFSinkWriter::Finalize to complete the file authoring process. This method can either block or call an asynchronous callback method when it completes. </font></li> </ul>  <p><font size="2" face="cali">To read more about the sink writer: </font><a href="https://msdn.microsoft.com/en-us/library/dd374642(VS.85).aspx"><font size="2" face="cali">https://msdn.microsoft.com/en-us/library/dd374642(VS.85).aspx</font></a><b></b></p>  <p><b><font size="2" face="cali">Project Structure: </font></b></p>  <p><i><font size="2" face="cali">MFCopy.vcproj</font></i></p>  <blockquote>   <p><a><font size="2" face="cali">The Visual Studio project file</font></a></p> </blockquote>  <p><i><font size="2" face="cali">main.cpp</font></i></p>  <blockquote>   <p><font size="2" face="cali">Contains the application entry point and all user interaction, including command-line parsing and progress notification.</font></p> </blockquote>  <p><i><font size="2" face="cali">mfcopy.cpp</font></i></p>  <blockquote>   <p><font size="2" face="cali">Implements the copying engine that configures the source reader and sink writer and processes multimedia samples. </font></p> </blockquote>  <p><b><font size="2" face="cali">Usage:</font></b></p>  <p><font size="2" face="cali">mfcopy.exe [-?] [-a audio_format] [-nc num_channels] [-sr sample_rate] [-v video format] [-fs resolution] [-fr framerate] [-im interlace_mode] [-br video_bitrate] [-q] [-s milliseconds] [-d milliseconds] [-d milliseconds] [-hw] [-xa] [-xv] [-xo] [-xm] input_filename output_filename</font></p>  <p><font size="2"><font face="cali"><em>-?</em>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Display usage information.         <br /></font></font><font size="2"><font face="cali"><em>-a audio_format          <br /></em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Set the output audio format.&#160; Defaults to the native format from the input file.         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Examples:&#160; AAC, WMAudioV8, WMAudioV9, WMAudio_Lossless         <br /></font></font><font size="2"><font face="cali"><em>-nc num_channels          <br /></em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Set the number of audio channels.         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Example:&#160; 2         <br /></font></font><font size="2"><font face="cali"><em>-sr sample_rate          <br /></em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Resample the audio to the specified rate.         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Examples: 44100, 48000         <br /></font></font><font size="2"><font face="cali"><em>-v video_format          <br /></em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Set the output video format.&#160; Defaults to the native format from the input file.         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Examples:&#160; H264, WMV2, WMV3, WVC1         <br /><em>-fs resolution</em>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Resize the video to the specified width and height.         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Example: 640x480         <br /><em>-fr framerate</em>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Convert the video frame rate to the specified rate.         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Example: 30:1         <br /></font></font><font size="2"><font face="cali"><em>-im interlace_mode          <br /></em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Set the video interlace mode.         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Example: Progressive         <br /></font></font><font size="2"><font face="cali"><em>-br video_bitrate          <br /></em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Set the average encoded bit rate for the video stream.         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Example: 5000000         <br /><em>-q</em>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Quiet mode.         <br /><em>-s milliseconds</em>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Specify a start position in milliseconds.         <br /></font></font><font size="2"><font face="cali"><em>-d milliseconds          <br /></em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Specify the duration to copy in milliseconds.         <br /><em>-hw</em>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Enable hardware transforms.         <br /><em>-xa</em>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Exclude audio streams.         <br /><em>-xv</em>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Exclude video streams.         <br /><em>-xo</em>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Exclude non audio/video streams (for example, text or script streams).         <br /><em>-xm</em>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Exclude metadata.         <br /><em>input_filename</em>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; The path to the source file.         <br /><em>output_filename</em>         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; The path to the destination file. </font></font></p>  <p><strong><font size="2" face="cali">Examples:</font></strong></p>  <ol>   <li><font size="2" face="cali">Copy 20 seconds of a WMV file without re-encoding: mfcopy.exe -d 20000 input.wmv output.wmv </font></li>    <li><font size="2" face="cali">Resize the video from a WMV file while preserving the original audio stream: mfcopy.exe -fs 320x240 input.wmv output.wmv </font></li>    <li><font size="2" face="cali">Transcode WMV to MP4 ensuring progressive video: mfcopy.exe -a AAC -v H264 -im Progressive input.wmv output.mp4 </font></li>    <li><font size="2" face="cali">Extract the audio stream from a WMV clip: mfcopy.exe -xv input.wmv output.wma </font></li> </ol>  <p><b><font size="2" face="cali">Limitations:</font></b></p>  <ol>   <li><font size="2" face="cali">The in-box Media Foundation file archive sinks support a maximum of one audio stream and one video stream in the output file. </font></li>    <li><font size="2" face="cali">The Media Foundation source reader and sink writer do not support DRM transcoding. </font></li>    <li><font size="2" face="cali">This tool cannot transcode to the MP3 format unless a third-party MP3 encoder MFT is installed. This is because the inbox MP3 encoder MFT is licensed for Microsoft applications only and will not work when loaded by third-party applications. </font></li>    <li><font size="2" face="cali">Remuxing to a different container type might fail due to the specific container requirements. </font></li> </ol>  <p><b><font size="2" face="cali">Downloading the Sample</font></b></p>  <p><font size="2" face="cali">You can download MFCopy from </font><a href="https://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=mfblog&amp;DownloadId=8574"><font size="2" face="cali">https://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=mfblog&amp;DownloadId=8574</font></a></p>  <p><font size="2" face="cali">Follow the instruction at </font><a href="https://code.msdn.microsoft.com/mfblog"><font size="2" face="cali">https://code.msdn.microsoft.com/mfblog</font></a><font size="2" face="cali"> for tips and instructions to build the sample.</font></p>  <p><i><font size="2" face="cali">This posting is provided &quot;AS IS&quot; with no warranties and confers no rights.</font></i></p>]]></content:encoded>
    </item>
    <item>
      <title>MFSimpleEncode</title>
      <link>https://docs.microsoft.com/archive/blogs/mf/mfsimpleencode</link>
      <pubDate>Wed, 02 Dec 2009 11:26:00 GMT</pubDate>
      <dc:creator><![CDATA[mfblog]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mf/2009/12/02/mfsimpleencode/</guid>
      <description><![CDATA[MFSimpleEncode.exe - This is a command line tool that transcodes files from one media format to...]]></description>
      <content:encoded><![CDATA[<p><font size="2">MFSimpleEncode.exe - This is a command line tool that transcodes files from one media format to another. The source code is provided to use as a reference if you write your own transcode application. This tool uses the Media Foundation </font><a href="https://msdn.microsoft.com/en-us/library/dd317903(VS.85).aspx" mce_href="https://msdn.microsoft.com/en-us/library/dd317903(VS.85).aspx"><font size="2">transcode API</font></a><font size="2">, which was introduced in Windows 7. </font></p>  <p><strong><font size="2">Techniques:</font></strong></p>  <p><font size="2"><i>Transcoding</i> is converting from one media format to another. Media Foundation provides three ways to perform transcoding: </font></p>  <ul>   <li><font size="2">Configure the Media Foundation </font><a href="https://msdn.microsoft.com/en-us/library/ms703988(VS.85).aspx" mce_href="https://msdn.microsoft.com/en-us/library/ms703988(VS.85).aspx"><font size="2">media session</font></a><font size="2"> directly. </font></li>    <li><font size="2">Use the higher level transcode API to configure the media session. </font></li>    <li><font size="2">Use </font><a href="https://msdn.microsoft.com/en-us/library/dd389281(VS.85).aspx" mce_href="https://msdn.microsoft.com/en-us/library/dd389281(VS.85).aspx"><font size="2">source reader</font></a><font size="2"> and </font><a href="https://msdn.microsoft.com/en-us/library/dd388105(VS.85).aspx" mce_href="https://msdn.microsoft.com/en-us/library/dd388105(VS.85).aspx"><font size="2">sink writer</font></a><font size="2">. </font></li> </ul>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/MFSimpleEncode_FA70/image_4.png" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFSimpleEncode_FA70/image_4.png" mce_href="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFSimpleEncode_FA70/image_4.png"><font size="2"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mf/WindowsLiveWriter/MFSimpleEncode_FA70/image_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFSimpleEncode_FA70/image_thumb_1.png" width="244" height="146" mce_src="https://blogs.msdn.com/blogfiles/mf/WindowsLiveWriter/MFSimpleEncode_FA70/image_thumb_1.png" /></font></a><font size="2"> </font></p>  <p align="center"><font size="2">Figure 1. Three ways to perform transcoding</font></p>  <p><font size="2">Configuring the media session directly is not straightforward. For example, you must understand the different encoders and media sinks to configure them properly. The transcode API provides a set of functions that makes it easier to build a transcode pipeline. It provides a simple profile to configure different encoders and sinks in the same way, and it automatically transfers metadata from t</font><a title="_GoBack" name="_GoBack"></a><font size="2">he source file to the transcoded file. </font></p>  <p><font size="2">Here is how to use the transcode API: </font></p>  <ul>   <li><font size="2">Create a </font><a href="https://msdn.microsoft.com/en-us/library/ms697527(VS.85).aspx" mce_href="https://msdn.microsoft.com/en-us/library/ms697527(VS.85).aspx"><font size="2">media source</font></a><font size="2"> from a URL or </font><a href="https://msdn.microsoft.com/en-us/library/ms698720(VS.85).aspx" mce_href="https://msdn.microsoft.com/en-us/library/ms698720(VS.85).aspx"><font size="2">bytestream</font></a><font size="2"> via </font><a href="https://msdn.microsoft.com/en-us/library/aa371340(VS.85).aspx" mce_href="https://msdn.microsoft.com/en-us/library/aa371340(VS.85).aspx"><font size="2">source resolver</font></a><font size="2">. </font></li>    <li><font size="2">Call </font><a href="https://msdn.microsoft.com/en-us/library/dd388113(VS.85).aspx" mce_href="https://msdn.microsoft.com/en-us/library/dd388113(VS.85).aspx"><font size="2">MFCreateTranscodeProfile</font></a><font size="2"> to create a transcode profile with output settings. </font></li>    <li><font size="2">Call </font><a href="https://msdn.microsoft.com/en-us/library/dd388118(VS.85).aspx" mce_href="https://msdn.microsoft.com/en-us/library/dd388118(VS.85).aspx"><font size="2">MFCreateTranscodeTopology</font></a><font size="2"> to create a transcode topology. </font></li>    <li><font size="2">Set the transcode </font><a href="https://msdn.microsoft.com/en-us/library/ms698943(VS.85).aspx" mce_href="https://msdn.microsoft.com/en-us/library/ms698943(VS.85).aspx"><font size="2">topology</font></a><font size="2"> on the media session. </font></li>    <li><font size="2">Start the transcode session by calling Start on the media session and wait for the session to fire the </font><a href="https://msdn.microsoft.com/en-us/library/ms704703(VS.85).aspx" mce_href="https://msdn.microsoft.com/en-us/library/ms704703(VS.85).aspx"><font size="2">MESessionEnded</font></a><font size="2"> event. </font></li> </ul>  <p><font size="2">The transcode API is based on the media session, so you don’t need to manipulate the samples yourself, or understand the low-level details. However, if you need to manipulate the sample data – for example, to add effects to the samples before encoding them -- the source reader and sink writer might be a better choice. We will have some topics about the source reader and sink writer later in this series. </font></p>  <p><font size="2">To read more about the transcode API: </font><a href="https://msdn.microsoft.com/en-us/library/dd317903(VS.85).aspx" mce_href="https://msdn.microsoft.com/en-us/library/dd317903(VS.85).aspx"><font size="2">https://msdn.microsoft.com/en-us/library/dd317903(VS.85).aspx</font></a></p>  <p><strong><font size="2">Project Structure: </font></strong></p>  <p><em><font size="2">MFSimpleEncode.vcproj</font></em></p>  <blockquote>   <p><font size="2">The main project file for VC++ projects generated using an Application Wizard. It contains information about the version of Visual C++ that generated the file, and information about the platforms, configurations, and project features selected with the Application Wizard.</font></p> </blockquote>  <p><em><font size="2">MFSimpleEncode.cpp</font></em></p>  <blockquote>   <p><font size="2">The main application source file.</font></p> </blockquote>  <p><em><font size="2">EncodeEngine.cpp</font></em></p>  <blockquote>   <p><font size="2">This is the encoding engine that the application calls into. </font></p> </blockquote>  <p><em><font size="2">EventHandler.cpp</font></em></p>  <blockquote>   <p><font size="2">This class handles asynchronous callbacks. </font></p> </blockquote>  <p><em><font size="2">ProfileBuilder.cpp</font></em></p>  <blockquote>   <p><font size="2">This class is used to create the preferred output media types for transcoding. </font></p> </blockquote>  <p><em><font size="2">SourceManager.cpp</font></em></p>  <blockquote>   <p><font size="2">This class is used to create a Media Foundation media source from a URL.</font></p> </blockquote>  <p><strong><font size="2">Usage:</font></strong></p>  <p><font size="2">MFSimpleEncode.exe -i INPUTFILE -o OUTPUTFILE [-p PROFILE] [-t DURATION] [-splitAudio CONTAINER] [-splitVideo CONTAINER] [-remux CONTAINER] </font></p>  <p><font size="2"><em>-i INPUTFILE</em> </font></p>  <blockquote>   <p><font size="2">The path to the input file. The tool supports built-in input file formats: ASF, AVI, WAV, MPEG4, 3GP, MP3 and the registered 3<sup>rd</sup> party MF sources. </font></p> </blockquote>  <p><font size="2"><em>- o OUTPUTFILE</em> </font></p>  <blockquote>   <p><font size="2">The path to the output file. It is highly recommended that you include the correct file extension, based on the file container. The tool supports built-in output file formats: ASF, MPEG4, 3GP and MP3.</font></p> </blockquote>  <p><em><font size="2">-p PROFILE</font></em></p>  <blockquote>   <p><font size="2">The path to the transcode profile file. Some example profiles are provided under .\profiles. They are in XML format, so that you can easily see the configuration or modify them for your own use. Several example profiles are included: </font></p> </blockquote>  <ul>   <ul>     <li><font size="2">TranscodeProfileASF.xml - Transcodes to an ASF file. </font></li>   </ul>    <ul>     <li><font size="2">TranscodeProfileMPEG4.xml - Transcodes to an MPEG-4 file. </font></li>   </ul>    <ul>     <li><font size="2">TranscodeProfileWMA_64k.xml - Transcode to a 64kbps WMA file. </font></li>   </ul>    <ul>     <li><font size="2">TranscodeProfileWMA_128k.xml - Transcode to a 128kbps WMA file. </font></li>   </ul>    <ul>     <li><font size="2">TranscodeProfileWMA_160k.xml - Transcode to a 160kbps WMA file. </font></li>   </ul>    <ul>     <li><font size="2">TranscodeProfileWMA_196k.xml - Transcode to a 196kbps WMA file. </font></li>   </ul> </ul>  <p><font size="2"><em>-t DURATION</em> </font></p>  <blockquote>   <p><font size="2">Specifies a stop time earlier than the end of file, in milliseconds. Use this parameter to get a segment of the original file. </font></p> </blockquote>  <p><em><font size="2">- splitAudio CONTAINER</font></em></p>  <blockquote>   <p><font size="2">Splits the audio stream from the original file, without re-encoding. </font></p> </blockquote>  <p><em><font size="2">- splitVideo CONTAINER</font></em></p>  <blockquote>   <p><font size="2">Splits the video stream from the original file, without re-encoding. </font></p> </blockquote>  <p><em><font size="2">-remux CONTAINER</font></em></p>  <blockquote>   <p><font size="2">Remux the streams from the original file, without re-encoding.</font></p> </blockquote>  <blockquote>   <p><font size="2">CONTAINER specifies the file container type. Currently, the tool supports the following container name strings: </font></p> </blockquote>  <ul>   <ul>     <li><font size="2">“MPEG4” </font></li>   </ul>    <ul>     <li><font size="2">“ASF” </font></li>   </ul>    <ul>     <li><font size="2">“3GP” </font></li>   </ul>    <ul>     <li><font size="2">“MP3” </font></li>   </ul> </ul>  <p><font size="2">It is highly recommended keeping the same container type as the input file container for remuxing and splitting scenarios. For example, if the input file format is ASF/WMV/WMA, “ASF” will be the preferred CONTAINER name string. </font></p>  <p><font size="2">The following options are mutually exclusive: -p, -splitAudio, -splitVideo, -remux. </font></p>  <p><strong><font size="2">Examples:</font></strong></p>  <p><font size="2">1. Transcode ASF to MPEG-4:</font></p>  <blockquote>   <p><font size="2">MFSimpleencode.exe –i Input.wmv –o output.mp4 –p TranscodeProfileMPEG4.xml</font></p> </blockquote>  <p><font size="2">2. Transcode MPEG-4 to ASF:</font></p>  <blockquote>   <p><font size="2">MFSimpleencode.exe –i input.mp4 –o output.wmv –p TranscodeProfileASF.xml</font></p> </blockquote>  <p><font size="2">3. Strip audio from ASF: </font></p>  <blockquote>   <p><font size="2">MFSimpleencode.exe –i input.wmv –o output.wma -splitAudio ASF</font></p> </blockquote>  <p><font size="2">4. Strip video from MPEG-4:</font></p>  <blockquote>   <p><font size="2">MFSimpleencode.exe –i input.mp4 –o output.mp4 –splitVideo MPEG4</font></p> </blockquote>  <p><font size="2">5. Get a 2-second segment from a WMA file:</font></p>  <blockquote>   <p><font size="2">MFSimpleencode.exe -i input.wma –o output.wma –remux ASF –t 2000</font></p> </blockquote>  <p><font size="2"><strong>&#160;</strong><strong>Limitations:</strong></font></p>  <ol>   <li><font size="2">The Media Foundation transcode API supports a maximum of one audio stream and one video stream in the output file. </font></li>    <li><font size="2">This tool does not support DRM transcoding. </font></li>    <li><font size="2">This tool cannot transcode to mp3 file format unless a 3<sup>rd</sup> party mp3 encoder MFT is installed. This is because the inbox mp3 encoder MFT is licensed for Microsoft applications only and will not work when loaded by 3<sup>rd</sup> party applications. </font></li>    <li><font size="2">Remuxing/splitting to different containers might fail due to the specific container requirements. </font></li> </ol>  <p><font size="2"></font></p>  <p><strong><font size="2">Downloading the Sample</font></strong></p>  <p><font size="2">You can download MFSimpleEncode from </font><a href="https://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=mfblog&amp;DownloadId=8439" mce_href="https://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=mfblog&amp;DownloadId=8439"><font size="2">https://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=mfblog&amp;DownloadId=8439</font></a><font size="2">. </font></p>  <p><font size="2">Follow the instruction at </font><a href="https://code.msdn.microsoft.com/mfblog"><font size="2">https://code.msdn.microsoft.com/mfblog</font></a><font size="2"> for tips and instructions to build the sample.</font></p>  <p><em><font size="2">This posting is provided &quot;AS IS&quot; with no warranties and confers no rights.</font></em></p>]]></content:encoded>
    </item>
  </channel>
</rss>