Apply a Filter to a Video File - WinForms C#

This tutorial shows how to apply a video filter to a media file and perform playback with the PlayCtrl in a WinForms C# application using the LEADTOOLS Multimedia SDK.

Overview  
Summary This tutorial covers how to apply a video filter in a WinForms C# application.
Completion Time 15 minutes
Visual Studio Project Download tutorial project (10 KB)
Platform Windows WinForms C# Application
IDE Visual Studio 2017, 2019
Development License Download LEADTOOLS
Try it in another language

The LEADTOOLS Multimedia Play Control contains many advanced features that simplify decoding, processing and playing back media from different sources such as files, memory buffers and network streams. The toolkit is shipped with various demos that make use of these features, such as the main Multimedia Player demo that has different editions in multiple programming languages.

Required Knowledge

Get familiar with the basic steps of creating a project and working with the PlayCtrl class by reviewing the Add References and Set a License and Playback a Video File tutorials before working on the Apply a Filter to a Video File - WinForms C# tutorial.

Create the Project and Add LEADTOOLS References

Start with a copy of the project created in the Playback a Video File tutorial. If the project is not available, follow the steps in that tutorial to create it.

This tutorial requires the following local DLLs, which are located at <INSTALL_DIR>\LEADTOOLS22\Bin\Dotnet4\x64:

It also requires adding a reference to the required filter's COM DLL, which is located at <INSTALL_DIR>\LEADTOOLS22\Bin\CDLL\x64:

Note

Different SDK features require different references. For a complete list, refer to Multimedia Files You Must Include With Your Application. In addition to this, the COM DLLs need to be registered on the deployment machine before they can be used.

Set the License File

The License unlocks the features needed for the project. It must be set before any toolkit function is called. For details, including tutorials for different platforms, refer to Setting a Runtime License.

There are two types of runtime licenses:

Note

Adding LEADTOOLS NuGet and local references and setting a license are covered in more detail in the Add References and Set a License tutorial.

Apply the Video Stabilizer Filter

With the project created, the references added, and the license set, coding can begin. For the purposes of this tutorial, the Video Stabilizer filter will be used alongside the Test_VideoStabilizer.avi video. This video can be found here: C:\LEADTOOLS22\Resources\Media

In Solution Explorer, right-click on Form1.cs and select View Code to display the code-behind of the form. Add the following statement to the lines that already exist in the using block at the top.

C#
// Using block at the top 
using System.Linq; 

Modify the openToolStripMenuItem_Click function to become as follows:

C#
private void openToolStripMenuItem_Click(object sender, EventArgs e) 
{ 
    try 
    { 
    OpenFileDialog dlg = new OpenFileDialog(); 
    dlg.InitialDirectory = @"C:\LEADTOOLS22\Resources\Media"; 
    dlg.FileName = "Test_VideoStabilizer.avi"; 
    if (dlg.ShowDialog(this) == DialogResult.OK) 
    { 
        string inputFile = dlg.FileName; 
                
        Processor stabilizer = _play.VideoProcessors.FirstOrDefault(p => p.FriendlyName == "LEAD Video Stabilizer Filter"); 
        if (stabilizer != null) 
        { 
            if(!_play.SelectedVideoProcessors.Contains(stabilizer)) // don't add it if it already exists. 
                _play.SelectedVideoProcessors.Add(stabilizer); 
            // retrieve the filter's interface 
            LMVStabilizeLib.ILMVStabilize stabilize = (LMVStabilizeLib.ILMVStabilize)_play.GetSubObject(PlayObject.SelVideoProcessor); 
            //set the fill color to yellow 
            stabilize.BkFillColor = 0xffff; 
            _play.SourceFile = inputFile; 
            _play.Run(); 
        } 
    } 
    } 
    catch (Exception ex) 
    { 
    MessageBox.Show(ex.ToString()); 
    } 
} 

Run the Project

Run the project by pressing F5, or by selecting Debug -> Start Debugging.

If the steps are followed correctly, the application runs and applies the Video Stabilizer filter on playback of a media file using the Open dialog box.

Wrap-up

This tutorial showed how to apply a filter to a video file using the PlayCtrl class.

See Also

Help Version 22.0.2024.3.20
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.