Creating a LEADTOOLS Multimedia Video File to DVD Disc Conversion Application

Perform the following steps to create and run a multimedia video-to-DVD disc conversion application using the LEADTOOLS Multimedia ConvertCtrl control and the DVD add-on module.

  1. Start Visual Studio .NET.

  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 Video-To-DVD Disc Converter" in the Project Name field, and then click OK. If desired, type a new location for your project or select a directory using the Browse button, and then click OK.

  5. In the "Solution Explorer" window, right-click the "References" folder, and select "Add Reference..." from the context menu. In the "Add Reference" dialog box, select the ".NET" tab and select Leadtools.Multimedia and Leadtools.MediaWriter and click OK.

  6. Make sure Form1 is in design view. Go to the toolbox (View->Toolbox) and drag 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.Multimedia.dll from "<LEADTOOLS_INSTALLDIR>\Bin\Dotnet\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 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 a Text control on the form (below the progress control) and set the following properties:

    Property Value
    Name _textStatus
    Anchor Bottom, Left
    BorderStyle None
    BackColor Control
    ForeColor Highlight
  9. Go to the toolbox (View->Toolbox) and drag two Button controls to the bottom of the form and set the following properties:

    Property Value
    Name _buttonConvert
    Text Convert
    Anchor Bottom, Right
    Name _buttonBurn
    Text Burn
    Anchor Bottom, Right
  10. Switch Form1 to code view (right-click Form1 in the Solution Explorer then choose View Code) and add the following lines to the beginning of the file:

    VB
    Imports Leadtools.Multimedia 
    Imports Leadtools.MediaWriter 
                      
         

    C#
    using Leadtools.Multimedia; 
    using Leadtools.MediaWriter; 
                      
         

  11. Declare the following private variable:

    VB
    Private _sourceFile As String 
    Private _targetPath As String 
    Private _aborted As Boolean 
                      
         

    C#
    private string _sourceFile; 
    private string _targetPath; 
    Private bool _aborted; 
                      
         

  12. 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" 
      _targetPath = Path.Combine(Directory.GetCurrentDirectory(), "DVD") 
                     
      _textStatus.Text = String.Empty 
      _buttonConvert.Enabled = True 
      _buttonBurn.Enabled = False 
                     
      If (Not Directory.Exists(_targetPath)) Then 
       Directory.CreateDirectory(_targetPath) 
      End If 
    End Sub 
                      
         

    C#
    private void Form1_Load(object sender, System.EventArgs e) 
    { 
       _sourceFile = @"<LEADTOOLS_INSTALLDIR>\Media\DaDa_DVD_MPEG2.mpg"; 
       _targetPath = Path.Combine(Directory.GetCurrentDirectory(), "DVD"); 
                     
       _textStatus.Text = string.Empty; 
       _buttonConvert.Enabled = true; 
       _buttonBurn.Enabled = false; 
                     
       if (!Directory.Exists(_targetPath)) 
          Directory.CreateDirectory(_targetPath); 
    } 
                      
         

  13. 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); 
    } 
                      
         

  14. 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 
      _textStatus.Text = "Conversion to DVD Format Completed" 
       _buttonBurn.Enabled = True 
    End Sub 
                      
         

    C#
    private void _convertctrl_Complete(object sender, EventArgs e) 
    { 
       _textStatus.Text = "Conversion to DVD Format Completed"; 
       _buttonBurn.Enabled = true; 
    } 
                      
         

  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 
       ConvertVideoToDvdFormat() 
    End Sub    
                      
         

    C#
    private void _buttonConvert_Click(object sender, System.EventArgs e) 
    { 
       ConvertVideoToDvdFormat(); 
    } 
                      
         

  16. Add an event handler to the _buttonBurn 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 
      BurnDvdToDisc() 
    End Sub    
                      
         

    C#
    private void _buttonProcessor_Click(object sender, System.EventArgs e) 
    { 
      BurnDvdToDisc() 
    } 
                      
         

  17. Add the following helper methods for use by the _buttonConvert and _buttonBurn event handlers:

    VB
    Private Sub ConvertVideoToDvdFormat() 
      Try 
       _convertctrl.Preview = True 
       _convertctrl.SourceFile = _sourceFile 
                     
       ' select video and audio compressors 
       _convertctrl.VideoCompressors.Mpeg2.Selected = True 
       _convertctrl.AudioCompressors.AC3.Selected = True 
                     
       ' select the DVD target format 
       Dim tf As TargetFormat = _convertctrl.TargetFormats(TargetFormatType.DVD) 
       tf.Selected = True 
                     
       ' set the allowed capture streams  
       _convertctrl.AllowedStreams = tf.Streams 
                     
       _convertctrl.TargetFile = _targetPath 
                     
       _convertctrl.StartConvert() 
                     
       _textStatus.Text = "Converting Video to DVD Format" 
                     
       _buttonBurn.Enabled = False 
       _buttonConvert.Enabled = False 
      Catch ex As Exception 
       MessageBox.Show(Me, ex.Message) 
      End Try 
    End Sub 
                     
    Private Sub BurnDvdToDisc() 
      _progress.Value = 0 
      _progress.Maximum = 10000 
                     
      Try 
       Dim dvdBurner As MediaWriter = New MediaWriter() 
       Dim dvdDrive As MediaWriterDrive = dvdBurner.Drives(1) 
       Dim dvdDisc As MediaWriterDisc = dvdDrive.CreateDisc() 
                     
       dvdDisc.VolumeName = "DVD Volume 1" 
       dvdDisc.InputPath = @"C:\InputFiles" 
                     
       dvdDrive.AutoEject = True 
                      
       AddHandler dvdDrive.OnProgress, AddressOf BurnProgress 
                      
       _progress.Value = 0 
       _textStatus.Text = String.Empty 
       _aborted = False 
                     
       dvdDrive.LoadDisc() 
       dvdDrive.BurnDisc(dvdDisc) 
                     
       Do While dvdDrive.State = MediaWriterState.StateIdle 
          Application.DoEvents() 
       Loop 
                     
       Do While dvdDrive.State = MediaWriterState.StateWriting 
          If _aborted Then 
             Throw New Exception("DVD Operation Aborted") 
          End If 
          Application.DoEvents() 
       Loop 
                     
       RemoveHandler drive.OnProgress, AddressOf BurnProgress 
                      
       _buttonConvert.Enabled = True 
       _buttonBurn.Enabled = True 
                      
      Catch ex As Exception 
         MessageBox.Show(ex.Message) 
      End Try 
    End Sub 
                     
    Public Sub BurnProgress(ByVal sender As Object, ByVal evt As MediaWriterProgressEventArgs) 
      _progress.Value = evt.Complete 
      _textStatus.Text = evt.Description 
      If evt.Progress = MediaWriterProgress.OperationProgressAborting Then 
         _aborted = True 
      End If 
    End Sub 
                      
         

    C#
    private void ConvertVideoToDvdFormat() 
    { 
       try 
       { 
          _convertctrl.Preview = true; 
          _convertctrl.SourceFile = _sourceFile; 
                     
          // select video and audio compressors 
          _convertctrl.VideoCompressors.Mpeg2.Selected = true; 
          _convertctrl.AudioCompressors.AC3.Selected = true; 
                     
          // select the DVD target format 
          TargetFormat tf = _convertctrl.TargetFormats[TargetFormatType.DVD]; 
          tf.Selected = true; 
                     
          // set the allowed capture streams  
          _convertctrl.AllowedStreams = tf.Streams; 
                     
          _convertctrl.TargetFile = _targetPath; 
                     
          _convertctrl.StartConvert(); 
                     
          _textStatus.Text = "Converting Video to DVD Format"; 
                     
          _buttonBurn.Enabled = false; 
          _buttonConvert.Enabled = false; 
       } 
       catch (Exception ex) 
       { 
          MessageBox.Show(this, ex.Message); 
       } 
    } 
                     
    private void BurnDvdToDisc() 
    { 
       _progress.Value = 0; 
       _progress.Maximum = 10000; 
                     
       try 
       { 
          MediaWriter dvdBurner = new MediaWriter(); 
          MediaWriterDrive dvdDrive = dvdBurner.Drives[1]; 
          MediaWriterDisc dvdDisc = dvdDrive.CreateDisc(); 
                            
          dvdDisc.VolumeName = "DVD Volume 1"; 
          dvdDisc.InputPath = @"C:\InputFiles"; 
                     
          dvdDrive.AutoEject = true; 
                      
          dvdDrive.OnProgress += BurnProgress; 
                      
          _progress.Value = 0; 
          _textStatus.Text = String.Empty; 
          _aborted = false; 
                     
          dvdDrive.LoadDisc(); 
          dvdDrive.BurnDisc(dvdDisc); 
                     
          while (dvdDrive.State = MediaWriterState.StateIdle) 
          { 
             Application.DoEvents(); 
          } 
                     
          While (dvdDrive.State = MediaWriterState.StateWriting) 
          { 
             if (_aborted) 
             { 
                throw new Exception("DVD Operation Aborted"); 
             } 
             Application.DoEvents(); 
          } 
                     
          drive.OnProgress -= BurnProgress; 
                      
         _buttonConvert.Enabled = true; 
         _buttonBurn.Enabled = True 
      } 
      catch (Exception ex) 
      { 
         MessageBox.Show(ex.Message); 
      } 
    } 
                     
    public void BurnProgress(Object sender, EventArgs evt) 
    { 
      _progress.Value = evt.Complete; 
      _textStatus.Text = evt.Description; 
      if (evt.Progress == MediaWriterProgress.OperationProgressAborting) 
      { 
         _aborted = true; 
      } 
    } 
                      
         

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

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Multimedia