"... and no one shall work for money, and no one shall work for fame; But each for the joy of the working, and each, in his separate star, shall draw the thing as he sees it, for the god of things as they are"

-Kipling

 

Tanta:
Windows Media Foundation Sample Projects

Summary

This purpose of this project is to provide documentation and code samples which can assist people in developing applications for Windows Media Foundation in the C# language.

Normally, WMF is considered to be a C++ tool - however the full functionality of Windows Media Foundation is available to users of the C# language via the very capable open source MF.Net interface library.

Using C# and MF.Net you can source streams of media data, render those streams to the screen or save them to files. You can also manipulate the data as it passes through the Media Pipeline and make whatever changes to it you wish. The full debugging capabilities of Visual Studio are also available so you can step through your C# code to observe its operation.

The Tanta project has two parts: a free book (in pdf format) which provides detailed "get started" information and a series of C# Sample Projects which illustrate various WMF Concepts.

Background

Originally there was no intention of writing a book or a diverse set of Sample Projects. The Tanta project originated in the mid 2000's as a vehicle to use DirectShow to try out various digital signal processing techniques. I had just obtained the book Digital Signal Processing (3rd Edition) by Gonzalez and Woods and wanted to have a go at some of the methods they describe. What is more, I wanted to do it in C# and also have the code available to C# in a standard debugger. For that you need to get access to the stream of video data (either coming off a file or from a web camera) and somehow get it up into the user layer. I kind of got this working with DirectShow but was never terribly satisfied with it. So I put the project aside and never wrote it up or made it available on this website.

Well, the years rolled on and I was starting in on another project (named FPath) one aspect of which requires a computer to make decisions based on video data. I looked at the old Tanta project to see what might be usable within it. As part of the background research, I dug around and discovered Microsoft had really moved DirectShow forward with its successor technology: Windows Media Foundation. It seemed that it was possible that a WMF component called a Transform might be much more useful than what I had before (spoiler alert: yes it is - Transforms are a very good fit for the requirements).

So, the old DirectShow Tanta project was scrapped and the name re-used for a new Windows Media Foundation based project with the same goal: Make a demonstration project that provides a C# application with access to raw video data at the user level. From the FPath project perspective, the TantaTransformDirect and TantaCaptureToScreenAndFile sample applications are the only two which are of interest. However, as part of the learning process, I wanted to thoroughly understand the usage and capabilities of the Windows Media Foundation technology and thus wrote the other sample applications (and the book).

The Book

When I was looking (Spring 2018), there did not seem to be anything intended for the beginner which brought all of the information together and presented specific novice friendly advice on how to get started in Windows Media Foundation programming. This book has been written in an attempt to address that issue. In other words, this book contains the information I would like to have had when I was first trying to figure out how to make anything at all work in WMF using C#.

The book entitled "Windows Media Foundation: Getting Started in C#" is available free of charge. It is over 350 pages in length and, hopefully, along with the Sample Projects will enable you to write your own C# WMF applications. Although the book is intended for the C# programmer it does contain plenty of background material that would be of use to users of other languages.

Download: Windows Media Foundation: Getting Started in C# (2.5Mb)

It should be noted that the above book, although it is a free download, is copyrighted material. Please do not distribute or copy it (in whole or in part) without permission. A print version of this book can be found on Amazon at nominal cost.

The Sample Code

The Tanta Sample Projects are open source and released under the MIT License. It should be noted that some parts of the code in the Tanta Sample Projects are based on the MF.Net samples and that code, in turn, is derived from the original Microsoft samples. These have been placed in the public domain without copyright. The Windows Media Foundation: Getting Started in C# book available for download above contains a detailed discussion of most of the techniques used in these applications.

You can download, clone or fork the Tanta Sample Projects at the following address:

https://github.com/OfItselfSo/Tanta

A selection of sample MP3 and MP4 files are available at the root of the Tanta Sample Application repository. All of the Tanta Sample Projects expect, by default, to read and write to a directory named "C:\Dump". You can save yourself a bit of typing if you create that directory and copy the sample files there.

There are 15 Sample Projects (listed below) but 4 of them will probably not work on Windows 7 due to missing codecs on that system. Windows 10 and Visual Studio 2017 (the community edition is fine) is the recommended development platform.

The Tanta Sample Projects

TantaAudioFileCopyViaPipelineAndWriter
Demonstrates the Hybrid Architecture by copying a single stream (audio) MP3 file. This application may not work on Windows 7 due to codec unavailability.

TantaAudioFileCopyViaPipelineMP3Sink
Demonstrates the Pipeline Architecture by copying a single stream (audio) MP3 file.

TantaAudioFileCopyViaReaderWriter
Demonstrates the Reader-Writer Architecture by copying a single stream (audio) MP3 file. This application may not work on Windows 7 due to codec unavailability.

TantaCaptureToFileViaReaderWriter
Uses a Reader-Writer Architecture to capture video directly to a file.

TantaCaptureToScreenAndFile
Uses a Hybrid Architecture to display video on the screen and, optionally, capture it to a file.

TantaFilePlaybackAdvanced
Uses the Pipeline Architecture to play a media file containing audio and video tracks. This application uses the ctlTantaEVRFilePlayer control from the TantaCommon library and demonstrates various Pipeline control mechanisms such as Pause, Fast-Forward, Jump Scrolling and volume control etc.

TantaFilePlaybackSimple
Uses the Pipeline Architecture to play a media file containing audio and video tracks. This application uses the ctlTantaEVRStreamDisplay control from the TantaCommon library to demonstrate simple audio and video playback with multiple streams.

TantaTransformDirect
Uses the Pipeline Architecture to demonstrate how to use the Tanta Transform Base classes to build and add Transforms to a Topology. This application contains Transforms which count the video frames, convert the image to grayscale or write text on the video display - both Synchronous and Asynchronous Mode Transforms are demonstrated.

TantaTransformInDLLClient
A Pipeline Architecture client which uses a DLL based Transform. This application also demonstrates various methods the client application can use to communicate with DLL based Transforms.

TantaTransformInDLL
A project which creates a Transform as a DLL and also, optionally, registers it on the system. The Transform in this application rotates or mirrors the video on display.

TantaTransformPicker
A project which uses the ctlTantaTransformPicker control in the TantaCommon library to enumerate and display the capabilities of the Transforms registered on the system.

TantaVideoFileCopyViaPipelineAndWriter
Demonstrates the Hybrid Architecture by copying a two stream (audio and video) MP4 file. This application may not work on Windows 7 due to codec unavailability.

TantaVideoFileCopyViaPipelineMP4Sink
Demonstrates the Pipeline Architecture by copying a two stream (audio and video) MP4 file.

TantaVideoFileCopyViaReaderWriter
Demonstrates the Reader-Writer Architecture by copying a two stream (audio and video) MP4 file. This application may not work on Windows 7 due to codec unavailability.

TantaVideoFormats
Uses the ctlTantaVideoPicker control from the TantaCommon library to show the video formats offered by the video capture devices (webcams) on the PC.

Acknowledgements

As discussed, at the top of this page, all of the C# interaction with Windows Media Foundation is done through the open source MF.Net library. This library, written by users "snarfle" and "nowinskie", is fine work and their effort creating it and releasing it as open source is much appreciated.

The icon used for the Tanta apps is from the the lovely Underwater Icons set by TurboMilk.

The open source sample MP4 and MP3 files which ship with the Tanta Software have been provided by https://www.sample-videos.com/.

Screenshots

Each Tanta Sample application has its own interface. The example screenshot below is the TantaTransformDirect Sample Project in the process of demonstrating how to write text on a video stream.