Convert Video to MP4 - Console C#

This tutorial shows how to perform conversions of video files into MP4 file format with the ConvertCtrl in a C# Windows Console application using the LEADTOOLS Multimedia SDK.

Summary This tutorial covers how to convert a video file into MP4 file format in a C# Windows Console application.
Completion Time 15 minutes
Visual Studio Project Download tutorial project (3 KB)
Platform Windows C# Console Application
IDE Visual Studio 2017, 2019
Development License Download LEADTOOLS
Try it in another language

The LEADTOOLS Multimedia Convert Control contains many advanced features that simplify many multimedia tasks such as media conversion, streaming, and transcoding. The toolkit is shipped with various demos that make use of these features, such as the main Multimedia Convert demo that has different editions in multiple programming languages.

Required Knowledge

Get familiar with the basic steps of creating a project by reviewing the Add References and Set a License tutorial, before working on the Convert Video to MP4 - Console C# tutorial.

Create the Project and Add LEADTOOLS References

Start with a copy of the project created in the Add References and Set a License tutorial. If you do not have that project, 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:


Different SDK features require different references. For a complete list, refer to Multimedia Files You Must Include With Your Application.

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:

Add the Convert Video Code

With the project created, the references added, the toolkit unlocked, and the license set, coding can begin.

In the Solution Explorer, open Program.cs, then add using Leadtools; and using Leadtools.Multimedia; to the using block at the top.

// Using block at the top 
using System.Windows.Forms; 
using Leadtools; 
using Leadtools.Multimedia; 

Add a new method called ConvertVideo(), and call it in the Main method after the UnlockMultimedia() method call.

static void Main(string[] args) 
static void ConvertVideo() 
   string inputFile = @"C:\LEADTOOLS22\Resources\Media\DaDa_CMP.avi"; 
   string outputFile = @"C:\LEADTOOLS22\Resources\Media\converted.mp4"; 
   ConvertCtrl convert = new ConvertCtrl(true); 
   Console.WriteLine("Preparing to convert.."); 
   convert.SourceFile = inputFile; 
   convert.TargetFile = outputFile; 
   convert.TargetFormat = TargetFormatType.ISO; 
   // select suitable compressors 
   convert.VideoCompressors.H264.Selected = true; 
   convert.AudioCompressors.AAC.Selected = true; 
   convert.AllowedStreams = StreamFormatType.AudioVideo; 
   Console.WriteLine("Converting. Please wait..."); 
   int previousPercent = 0; 
   while (convert.State != ConvertState.Stopped) 
      if (convert.PercentComplete - previousPercent >= 1) // print a dot every 1 percent or so 
         previousPercent = convert.PercentComplete; 
         Console.Write(". "); 
   Console.WriteLine($"\nFinished conversion to file {outputFile}. Press any key to continue..."); 

Run the Project

Make sure the input and output file names are set correctly. For this tutorial, the file DaDa_H264.avi can be used as input, which is shipped with the LEADTOOLS v22 Multimedia SDK in the <INSTALL_DIR>\LEADTOOLS22\Resources\Media folder. Run the project by pressing F5, or by selecting Debug -> Start Debugging.

If the steps were followed correctly, the application starts and converts the input file to a new MP4 (ISO) file.


This tutorial showed how to convert a video file using the ConvertCtrl 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.