Click here to Skip to main content
Licence CPOL
First Posted 7 Apr 2008
Views 71,036
Bookmarked 44 times

FFMPEG using ASP.NET

By arinhere | 9 Jul 2008 | Unedited contribution
This piece of code will show you to convert any video file format to high quality flv and stream it on web server
3 votes, 25.0%
1

2
1 vote, 8.3%
3
1 vote, 8.3%
4
7 votes, 58.3%
5
3.41/5 - 16 votes
μ 3.03, σa 3.16 [?]

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.

[Sorry I have to close the link as some spamming is done in my server to this application. If anyone is interested then please contact me in my EMail id, I will help him/her as far as I can]

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

Web Developer

India India

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionWill this work for concurrency users PinmemberManjunatht@excel23:22 17 Jan '12  
QuestionFFMPEG using ASP.NET with C# Pinmemberdivydivy21:56 4 Dec '11  
AnswerRe: FFMPEG using ASP.NET with C# Pinmemberarinhere22:07 4 Dec '11  
GeneralMy vote of 5 Pinmemberdivydivy21:48 4 Dec '11  
QuestionASPX source for Grab thumbnail PinmemberNabbie0:10 22 Jun '11  
AnswerRe: ASPX source for Grab thumbnail Pinmemberarinhere22:09 4 Dec '11  
GeneralSource Code Plz PinmemberChetan Chaudhari3:54 19 Apr '11  
Generalsource code Pinmemberyusufseyrek13:25 3 Jan '11  
GeneralSource please Pinmemberzerataul23:52 8 Sep '10  
GeneralFFMPEG for C#.NET PinmemberGPUToaster8:03 16 Jun '10  
Generalc# code Pinmemberniravsahayata22:47 9 Jun '10  
GeneralRe: c# code PinmemberRob Bickel14:46 12 Oct '11  
GeneralPlease send me Code PinmemberRevanth Arji20:46 4 Apr '10  
GeneralI want a take a SNAP of video file at a time of Update video file. Pinmemberhumill_MCA19:38 19 Feb '10  
GeneralCreate Image from flash file PinmemberShyju.K21:44 4 Aug '09  
GeneralRe: Create Image from flash file Pinmemberarinhere22:05 4 Aug '09  
GeneralWorking project with realtime video conversion and Image generation PinmemberMember 45215863:48 13 May '09  
GeneralRe: Working project with realtime video conversion and Image generation PinmemberMember 30857900:44 11 Aug '09  
QuestionC# Code Pinmemberramyamr22:50 14 Dec '08  
AnswerRe: C# Code Pinmemberarinhere2:39 29 Dec '08  
Generali have some questions PinmemberSosyopat12:14 21 Nov '08  
GeneralRe: i have some questions Pinmemberarinhere6:20 22 Nov '08  
Hey,
 
Thanks for your comment. First of all about the video duration, you can get all video information using simple ffmpeg command and I hope from there you can easily get the video duration in a string.
 
FFMPEG supports multiple capture of video file. To capture multiple images use the following command line.
 
" -i """ & newPath & """ -f image2 -ss 1 -vframes 1 -s 400x300 -an """ & prevpath & "\" & prevnm & """"
 
newPath=video file path
prevpath=folder name, where the captured images will be stored
 
I hope this help...
 
Thanks - Arin
 
Please rate this article if it helps you..
 
Arin
Mail: arinhere@gmail.com
http://blogs.msdn.com/coding4fun/archive/2008/04/16/8399645.aspx

GeneralConverting a 3gp file into flash file by using this ffmpeg.exe i got one error can any one help me.......... Pinmembervijaya_sarathy1:23 12 Jul '08  
GeneralRe: Converting a 3gp file into flash file by using this ffmpeg.exe i got one error can any one help me.......... Pinmemberarinhere22:34 13 Jul '08  
QuestionSource Code Pinmemberknoami20:59 19 Jun '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120210.1 | Last Updated 9 Jul 2008
Article Copyright 2008 by arinhere
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid