Advanced Conversion Using Processors

Take the following steps to create and run a multimedia convert application with processors using the LEADTOOLS Media Foundation ConvertCtrl control.

  1. Start Visual Studio.

  2. Choose File->New->Project... from the menu.

  3. In the New Project dialog box, choose either Visual C# Projects or VB Projects in the Projects Type List, and choose Windows Application in the Templates List.

  4. Type the project name as Multimedia Conversion with Processors in the Project Name field, and then if desired, type a new location for your project or select a directory using the Browse button, and then choose OK.

  5. In the Solution Explorer window, right-click on the References folder, and select Add Reference... from the context menu. In the Add Reference dialog box, select the .NET tab and select Leadtools.MediaFoundation and click OK. If this DLL does not appear under the .NET tab, you will need select the Browse tab and add it from the "<LEADTOOLS_INSTALLDIR>\Bin\Dotnet4\Win32" folder, by selecting the following DLL:

    • Leadtools.MediaFoundation.dll

    After browsing, click the Select button and then press the OK button to add the above DLL to the application.

  6. Make sure Form1 is in design view. Go to the toolbox (View->Toolbox) and drag and drop a ConvertCtrl control on the form.

    NOTE: If you do not have ConvertCtrl in your toolbox, select Tools->Choose Toolbox Items from the menu. Click Browse and then select Leadtools.MediaFoundation.dll from "<LEADTOOLS_INSTALLDIR>\Bin\Dotnet4\Win32" and then click Open and then click OK. After adding it to the form, set the following properties on the convert control:

    Property Value
    Name _convertctrl
    Anchor Top, Bottom, Left, Right
    BackColor Black
  7. Go to the toolbox (View->Toolbox) and drag and drop a ProgressBar control on the form (below the convert control) and set the following properties:

    Property Value
    Name _progress
    Anchor Bottom, Left, Right
    Step 1
  8. Go to the toolbox (View->Toolbox) and drag and drop two Button controls to the bottom of the form and set the following properties:

    Property Value
    Name _buttonProcessor
    Text Processor...
    Anchor Bottom, Right
  9. Switch Form1 to code view (right-click Form1 in the solution explorer then select View Code) and add the following lines at the beginning of the file:

    VB
    Imports Leadtools.MediaFoundation 
    C#
    using Leadtools.MediaFoundation; 

  10. Declare the following private variable:

    VB
    Private _sourceFile As String 
    Private _targetFile As String 
    Private _addedProc As Boolean 
    C#
    private string _sourceFile; 
    private string _targetFile; 
    private bool _addedProc; 

  11. Add an event handler to the Form1 Load event and code it as follows:

    VB
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
       _sourceFile = @"<LEADTOOLS_INSTALLDIR>\Media\DaDa_DVD_MPEG2.mpg" 
       _targetFile = "DaDa_H264_Deinterlaced.mp4" 
       _addedProc = False 
    End Sub 
    C#
    private void Form1_Load(object sender, System.EventArgs e) 
    { 
       _sourceFile = @"<LEADTOOLS_INSTALLDIR>\Media\DaDa_DVD_MPEG2.mpg"; 
       _targetFile = "DaDa_H264_Deinterlaced.mp4"; 
       _addedProc = false; 
    } 

  12. Add an event handler to the _convertctrl Progress event and code it as follows:

    VB
    Private Sub _convertctrl_Progress(ByVal sender As System.Object, ByVal e As ProgressEventArgs) Handles _convertctrl.Progress 
       _progress.Value = CInt((_progress.Maximum * e.percent / 100)) 
    End Sub 
    C#
    private void _convertctrl_Progress(object sender, ProgressEventArgs e) 
    { 
       _progress.Value = (int)(_progress.Maximum * e.percent / 100); 
    } 

  13. Add an event handler to the _convertctrl Complete event and code it as follows:

    VB
    Private Sub _convertctrl_Complete(ByVal sender As System.Object, ByVal e As EventArgs) Handles _convertctrl.Complete 
       MessageBox.Show("Conversion Complete") 
       _buttonProcessor.Enabled = True 
       _buttonConvert.Enabled = True 
    End Sub 
    C#
    private void _convertctrl_Complete(object sender, EventArgs e) 
    { 
       MessageBox.Show("Conversion Complete"); 
       _buttonProcessor.Enabled = true; 
       _buttonConvert.Enabled = true; 
    } 

  14. Add an event handler to the _buttonProcessor Click event and code it as follows:

    VB
    Private Sub _buttonProcessor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _buttonProcessor.Click 
       Try 
         Dim nIndex As Integer  = _convertctrl.VideoProcessors.IndexOf("{E2B7ED97-38C5-11D5-91F6-00104BDB8FF9}") 
         Dim deinterlace As Processor = _capturectrl.VideoProcessors(nIndex) 
         Dim procName As String = deinterlace.Name 
         If (_addedProc = False) Then 
             _convertctrl.SelectedVideoProcessors.Add(deinterlace) 
             _addedProc = True 
         End If 
         If (_convertctrl.SelectedVideoProcessors[procName].HasDialog(ProcessorDlg.Properties)) Then 
             _convertctrl.SelectedVideoProcessors[procName].ShowDialog(ProcessorDlg.Properties, this) 
         End If 
       Catch ex As Exception 
         MessageBox.Show(ex.Message) 
       End Try 
    End Sub 
    C#
    private void _buttonProcessor_Click(object sender, System.EventArgs e) 
    { 
       try 
       { 
         int nIndex = _convertctrl.VideoProcessors.IndexOf("{E2B7ED97-38C5-11D5-91F6-00104BDB8FF9}"); 
         Processor deinterlace = _capturectrl.VideoProcessors[nIndex]; 
         string procName = deinterlace.Name; 
         if (!_addedProc) 
         { 
             _convertctrl.SelectedVideoProcessors.Add(deinterlace); 
             _addedProc = true; 
         } 
         if (_convertctrl.SelectedVideoProcessors[procName].HasDialog(ProcessorDlg.Properties)) 
         { 
             _convertctrl.SelectedVideoProcessors[procName].ShowDialog(ProcessorDlg.Properties, this); 
         } 
       catch (Exception ex) 
       { 
         MessageBox.Show(this, ex.Message); 
       } 
    } 

  15. Add an event handler to the _buttonConvert Click event and code it as follows:

    VB
    Private Sub _buttonConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _buttonConvert.Click 
       Try 
           _convertctrl.Preview = True 
           _convertctrl.SourceFile = _sourceFile 
           _convertctrl.TargetFormats.Selection = TargetFormatType.MP4    
           Dim trgvideoformats As TargetVideoFormats = _convertctrl.TargetFormats(_convertctrl.MP4).VideoFormats 
           targetvideoformats.Selection = targetvideoformats.IndexOf("{34363248-0000-0010-8000-00AA00389B71}") ' // H264 
           _convertctrl.TargetFile = _targetFile 
                            
           _convertctrl.StartConvert() 
           _buttonProcessor.Enabled = False 
           _buttonConvert.Enabled = False 
       Catch ex As Exception 
           MessageBox.Show(ex.Message) 
       End Try 
    End Sub 
    C#
    private void _buttonConvert_Click(object sender, System.EventArgs e) 
    { 
       try 
       { 
         _convertctrl.Preview = true; 
         _convertctrl.SourceFile = _sourceFile; 
         _convertctrl.TargetFormats.Selection = (int)TargetFormatType.MP4; 
         TargetVideoFormats targetvideoformats = _convertctrl.TargetFormats[TargetFormatType.MP4].VideoFormats; 
         targetvideoformats.Selection = targetvideoformats.IndexOf("{34363248-0000-0010-8000-00AA00389B71}");// H264 
         _convertctrl.TargetFile = _targetFile; 
                          
         _convertctrl.StartConvert(); 
         _buttonProcessor.Enabled = false; 
         _buttonConvert.Enabled = false; 
       } 
       catch (Exception ex) 
       { 
         MessageBox.Show(this, ex.Message); 
       } 
    } 

  16. Build, and Run the program to test it.

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

LEADTOOLS Multimedia