How to Convert Format of a Video File

Article Description for Manual Users Perspective 

This article explains, for .Net programmers, how to convert video formats (for example AVI, MPEG and the others) and capture images from a video without actually downloading an application consisting of a huge megabytes like (50 MB) or GB of software. Some users might ask, is it really possible? For all those users, my answer is yes. This is the article I want to explain and share with you. In addition, I will also include code snippets.

Scenario for .Net Programmers to Convert Video Format File

In Sales and Entertainment Domain projects, we come across the scenario that users upload an advertisement in various formats. Let us say we need to convert all those formats to a single format, such as .swf. Therefore, this article will be useful for a requirement like this. 

These days, users are bothered by the requirement to convert a video format because one video format file may not be compatible in all the players. For Example, Windows Media player, VLC Media player, Xing player and so on). Some video formats are compatible with Windows Media Player whereas other video files are not compatible with it. Whereas, some are compatible in xing player and some video files are not compatible in the same player. So, you need to convert your video formats for playing in the Media player. For this, there is a software required  for converting formats of those videos. But that's where the beauty of a Linux command is useful. You can easily convert any video format file and capture multiple images from a video. This can be done with a simple and easily written Linux command on the command prompt. This command will convert various video formats, and capture images from video. But for this, you need an executable file that is freely downloadable and less than 3 Mb of size. The executable file name is ffmpeg. I will illustrate the usage with code snippets.

Schema of the Command will be like this

ffmpeg -i location of the input file name (with extension of the file) -ar 32000 -ab 64 and location of the destination file (with extension of the file) where you want to save it; ffmpeg will be in that specified drive. In the following example, the C drive is the location of ffmpeg.

  1. c://ffmpeg -i c:/movie.avi -ar 32000 -ab 64 c:/movie.swf  
Now, I will briefly explain the preceding code snippet. 
ffmpeg: It is the free executable downloadable from your search engine. This .exe file should be in that specific drive (C, D...).
-i :It is the input of the source file.

Location of the Source Movie/Video

The location of the source and destination movie file or video anywhere in the computer. You just need to specify the exact path.

Audio rates and Audio bits

This specifies how to increase/decrease the audio volumes of your video.You can increase the audio volumes in multiples of two, ar and ab. And without this specification your videos can't be converted in some versions of ffmpeg.

Location of the Destination Video

It can be placed anywhere and in any drive of your computer that you would like to save after changing the video format. Audio files can also be converted like this.
Now for .Net programmers, the code goes like this.
  1. proc = new Process()  
  2. proc.StartInfo.FileName = " c://ffmpeg -i c:/movie.avi -ar 32000 -ab 64 c:/movie.mpeg "  
  3. proc.StartInfo.Arguments = ""  
  4. proc.StartInfo.UseShellExecute = false  
  5. proc.StartInfo.RedirectStandardInput = true  
  6. proc.StartInfo.RedirectStandardOutput = true  
  7. proc.Start()  
  8. proc.WaitForExit()  
Note: Remember, this ffmpeg.exe will be available in Google search and whenever you are using it in .Net, ensure it is in a separate folder. For example, the Utility folder.

If you want to extract the .exe, download the Zip Files.

Real Time Images process in the command prompt when execute in your command prompt manually.

Step 1

Convert the the nindu.mpeg file format to nindus.avi format file.

Step 2

Conversion completion status in your command prompt can be seen in the following screenshot.

Step 3

Here is the result, the format in your drive. Now, see the following nindu.mpeg and nindus.avi files.

Now, let us say you want to play the newly converted file. Here, the actual running video is shown here. You can also check that the title of the video is nindus.avi.

In the next article, you will learn how to extract the thumbnails from a video.

I hope you enjoyed reading the article.

Up Next
    Ebook Download
    View all
    View all