5,286,006 members and growing! (20,084 online)
Email Password   helpLost your password?
Web Development » ASP.NET » Samples     Intermediate License: The Code Project Open License (CPOL)

FFMPEG using ASP.NET

By arinhere

This piece of code will show you to convert any video file format to high quality flv and stream it on web server
VB (VB 7.x, VB 8.0, VB 9.0, VB 6, VB), .NET (.NET, .NET 2.0), Ajax, ASP.NET, Dev

Posted: 7 Apr 2008
Updated: 15 Jun 2008
Views: 6,803
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
6 votes for this Article.
Popularity: 1.95 Rating: 2.50 out of 5
1 vote, 50.0%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
0 votes, 0.0%
4
1 vote, 50.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

Many of us have seen that, package like FFMPEG is quite hectic to use in our web application. Many of us have already opt different modules like Media Handler etc. to convert their video files to flv and stream it over the server.

This module will help you to convert your video files to flv which can easily stream on the server. Moreover you can can get high quality flv using this code.

Background

The very basic idea behind this article is to use the FFMPEG command line argument to fulfill the requirement. All other popular modules available in the internet are based on those command lines which you can use directly to achieve your goal.

Using the code

Here is the website which I tried to develop. Its still under construction. So some bugs you may find over there. But the conversion portion is working fine. Check it out..

http://emazeworks.net/vidshack/default.aspx

here are the steps...

Step - 1

Just download FFMPEG module from the internet. The latest version of FFMPEG will be a zip file which contains all the source code, FFMPEG.exe, FLVTOOL.exe and more. Extract those files into your application directory. FFMPEG.exe basically convert the video files into flv and FLVTOOL insert the metadata to the flv files. So that the video files will have all the video information.Without the metadata the video files won't be able to stream properly.

Step -2

Assign the exepath and directories.

      
        AppPath = Request.PhysicalApplicationPath 'Get the application path
        inputPath = AppPath & "videos\org_video" 'Path of the original file
        outputPath = AppPath & "videos\conv_video" 'Path of the converted file
        imgpath = AppPath & "videos\thumbs" 'Path of the generated thumanails
        prevpath = AppPath & "videos\preview" 'Path of the preview file

Now the main thing is the command line that executes ffmpeg.exe on the server...

string cmd as string = " -i """ & newPath & """ """ & outputPath & "\" & out & 
"""" '-i specifies the input file

Here newpath is the path of the source video file, outputpath is path of the converted video and out is the filename.

The above command line will convert the video into flv format. Now if you like to get high quality flv then use the following code..

Dim fileargs As String = "-i " & newPath & " -acodec mp3 -ab 64k -ac 2 
-ar 44100 -f flv -deinterlace -nr 500 -croptop 4 -cropbottom 8 -cropleft 
8 -cropright 8 -s 640x480 -aspect 4:3 -r 25 -b 650k -me_range 25 -i_qfactor 
0.71 -g 500 " & outputPath & "\" & out & ""
The above code will generate high quality flv. Now to insert metadata into those generated flv file use the following command line
Dim filebuffer As String = "-U """ & outputPath & "\" & out & """"
To create thumbnail use the following code....
Dim imgargs As String = " -i """ & newPath & """ -f image2 -ss 1 -vframes 1 -s 
80x60 -an """ & imgpath & "\" & thumbnm & """"
-i = input file -f = file format -vframe = video frame -s = size

Now create a function which can execute those command line

       Dim proc As New System.Diagnostics.Process()
        proc.StartInfo.FileName = exepath 
'Path of exe that will be executed, only for "filebuffer" it will be "flvtool2.exe"
        proc.StartInfo.Arguments = cmd 'The command which will be executed
        proc.StartInfo.UseShellExecute = False
        proc.StartInfo.CreateNoWindow = True
        proc.StartInfo.RedirectStandardOutput = False
        proc.Start()
Step - 3

The above code will convert any kind of video into FLV now the only thing you have to do is to stream the video using any flash video player.

Points of Interest

You can easily develop any streaming video application using this code and easily build a site like youtube or sharkle. For any kind of help feel free to mail me at arinhere@gmail.com

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

arinhere



Occupation: Web Developer
Location: India India

Other popular ASP.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 12 of 12 (Total in Forum: 12) (Refresh)FirstPrevNext
Subject  Author Date 
QuestionSource Codememberknoami20:59 19 Jun '08  
AnswerRe: Source Codememberarinhere23:30 19 Jun '08  
Generalcommentsmembermgp227:34 21 May '08  
GeneralRe: commentsmemberarinhere22:32 25 May '08  
GeneralThank you!membermgp227:51 26 May '08  
GeneralRe: Thank you!memberarinhere8:42 26 May '08  
Generalquestionmembermgp227:31 21 May '08  
GeneralRe: questionmemberarinhere22:30 25 May '08  
GeneralC# Versionmemberjesalg11:11 7 Apr '08  
GeneralRe: C# Versionmembersamsudeen21:16 18 Apr '08  
GeneralRe: C# Versionmemberjesalg21:36 18 Apr '08  
GeneralNice articlememberRajib Ahmed9:40 7 Apr '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 15 Jun 2008
Editor:
Copyright 2008 by arinhere
Everything else Copyright © CodeProject, 1999-2008
Web13 | Advertise on the Code Project