Upload any video and convert to .mp4 online in .net

Posted on

Problem :

I have a strange requirement. User can upload their video of any format (or a limited format). We have to store them and convert them to .mp4 format so we can play that in our site.

Same requirement also for audio files.

I have googled but I can’t get any proper idea. Any help or suggestions….??

Thanks in advance

Solution :

You can convert almost any video/audio user files to mp4/mp3 with FFMpeg command line utility. From .NET it can be called using wrapper library like Video Converter for .NET (this one is nice because everything is packed into one DLL):

(new NReco.VideoConverter.FFMpegConverter()).ConvertMedia(pathToVideoFile, pathToOutputMp4File, Formats.mp4)

Note that video conversion requires significant CPU resources; it’s good idea to run it in background.

Your Answer

please Replace .flv to .mp4 you will get your answer

private bool ReturnVideo(string fileName)
{
string html = string.Empty;
//rename if file already exists

int j = 0;
string AppPath;
string inputPath;
string outputPath;
string imgpath;
AppPath = Request.PhysicalApplicationPath;
//Get the application path
inputPath = AppPath + "OriginalVideo";
//Path of the original file
outputPath = AppPath + "ConvertVideo";
//Path of the converted file
imgpath = AppPath + "Thumbs";
//Path of the preview file
string filepath = Server.MapPath("~/OriginalVideo/" + fileName);
while (File.Exists(filepath))
{
j = j + 1;
int dotPos = fileName.LastIndexOf(".");
string namewithoutext = fileName.Substring(0, dotPos);
string ext = fileName.Substring(dotPos + 1);
fileName = namewithoutext + j + "." + ext;
filepath = Server.MapPath("~/OriginalVideo/" + fileName);
}
try
{
this.fileuploadImageVideo.SaveAs(filepath);
}
catch
{
return false;
}
string outPutFile;
outPutFile = "~/OriginalVideo/" + fileName;
int i = this.fileuploadImageVideo.PostedFile.ContentLength;
System.IO.FileInfo a = new System.IO.FileInfo(Server.MapPath(outPutFile));
while (a.Exists == false)
{

}
long b = a.Length;
while (i != b)
{

}

string cmd = " -i "" + inputPath + ""\"" + fileName + """" """" + outputPath + ""\"" + fileName.Remove(fileName.IndexOf(""."")) + "".flv"" + """"""

Leave a Reply

Your email address will not be published. Required fields are marked *