Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Media Foundation Capture and Convert with LEADTOOLS 18

1 Apr 2013 1  
Media Foundation Capture and Convert with LEADTOOLS 18

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.

Introduction

LEAD Technologies has been winning awards for its DirectShow Multimedia SDKs for over a decade and has leveraged its expertise to provide the same world-class SDK for Microsoft Media Foundation. LEADTOOLS Version 18 makes it easy to add multimedia playback, capture and conversion functionality with high level, programmer friendly objects and classes.

In addition to the top-notch development interfaces for C++ and .NET, LEADTOOLS Multimedia 18 includes codecs, media sources, media sinks, processing transforms and more. Boasting outstanding quality, compression and speed, LEADTOOLS is the complete package for all of your Multimedia development needs.

Key Media Foundation Capture and Convert Features in LEADTOOLS Multimedia SDKs

  • Capture in HD from any device including capture cards, cameras, TV Tuners, live web streams and more
  • Convert and save captured data in real time directly to file, memory, or create live streams for the public Internet or encrypted networks
  • Use LEAD’s advanced encoders, decoders, media sources and media sinks for the market’s best performance, quality and compression
    • MPEG-4
    • MPEG-2
    • h.264
    • h.263
    • AAC
    • AC3
    • AMR
    • MKV
    • MXF
    • ISO
    • OGG
    • Process the audio/video data with LEAD’s Media Foundation Transforms
    • Video Stabilizer
    • Deinterlace
    • Resize
    • Rotate
    • Text Overlay
    • Video Callback
    • Volume
  • High level .NET and C/C++ interfaces for 32 and 64 bit development

The Media Foundation Code

LEADTOOLS includes high level controls that do all the hard work of constructing the necessary topologies (or graphs if you are using the DirectShow version) for capturing and converting audio/video data. They also both come with live preview windows and callback events to monitoring the progress and other control states.

Capture

There are many ways to capture audio and video, and LEADTOOLS supports them all. Whether you are capturing from a webcam, microphone, IP camera, television signal, or even a military-grade UAV, LEADTOOLS only requires a few lines of code.

// Select the first available video device.  To choose from a list,
// you could enumerate and populate a ComboBox or similar control
_capturectrl.VideoDevices[0].Selected = true;
 
// Set the file format
_capturectrl.TargetFormats.Selection = (int)TargetFormatType.MP4;
_capturectrl.TargetFile = "capture.mp4";
 
// Set the target video format
TargetVideoFormats targetvideoformats = 
   _capturectrl.TargetFormats[TargetFormatType.MP4].VideoFormats;
targetvideoformats.Selection = targetvideoformats.IndexOf(
   Constants.MEDIASUBTYPE_H264); // H264
 
// Set other miscellaneous settings and start the capture
_capturectrl.Preview = true; // Display a live preview
_capturectrl.UseTimeLimit = true;
_capturectrl.TimeLimit = 10; // 10 seconds
_capturectrl.StartCapture(CaptureMode.Video);

Convert

Similarly, converting a multimedia file is as simple as setting the source file, destination file, and output settings.

// Set the input file to convert
_convertctrl.SourceFile = 
   @"C:\LEADTOOLS Multimedia 18\Media\DaDa_H264.mp4";
 
// Set the File Format
_convertctrl.TargetFormat = TargetFormatType.WMV;
_convertctrl.TargetFile = "DaDa.wmv";
 
// Set the target video format
TargetVideoFormats targetvideoformats =
   _convertctrl.TargetFormats[_convertctrl.TargetFormat].VideoFormats;
targetvideoformats.Selection = targetvideoformats.IndexOf(
   Constants.WMMEDIASUBTYPE_WMV3 + "/MP"); // Windows Media Video 9 (WMV) main profile
 
// Set the target audio format
TargetAudioFormats targetaudioformats = 
   _convertctrl.TargetFormats[_convertctrl.TargetFormat].AudioFormats;
targetaudioformats.Selection = targetaudioformats.IndexOf(
   Constants.WMMEDIASUBTYPE_WMAudioV8); // Windows Media Audio (WMA)
 
// Set other miscellaneous settings and start the conversion
_convertctrl.Preview = true;
_convertctrl.StartConvert();

Download the Full Media Foundation Capture and Convert Example

You can download a fully functional demo which includes the features discussed above. To run these examples you will need the following:

Support

Need help getting this sample up and going? Contact our support team for free technical support! For pricing or licensing questions, you can contact our sales team (sales@leadtools.com) or call us at 704-332-5532.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here