Converting Videos to Flv Formate Usinh Asp.Net

If you want to put your video on YouTube to share with people all over the world, you may choose FLV format video as it’s the best way for all of you. But not all videos are FLV video format. So, you may search video to FLV converter via google. You might find some free video converter with low quality, or some commercial video converter with high quality and also high price. Is there any other method with high quality and free of payment? There is always a way for your imagination.
Besides using video converter to convert video to FLV, you also can use C#.NET to convert video to FLV on WEB, with high quality and free of payment. The method is very easy if you know something about C#.NET.
First, you need download some files from .NET
1)ffmpeg.exe
2)ffplay.exe
3)pthreadGC2.dll
After downloading the 3 files above, we’ll start the converting of video to flv steps:
1), Make a windows application or new .net web site
2), Copy & Paste the 3 downloaded files to root location
3), Now, you need Copy & Paste the codes (written below)
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” + “\”";
        ConvertNow(cmd);
        string imgargs = ” -i \”" + outputPath + “\\” + fileName.Remove(fileName.IndexOf(“.”)) + “.flv” + “\” -f image2 -ss 1 -vframes 1 -s 280×200 -an \”" + imgpath + “\\” + fileName.Remove(fileName.IndexOf(“.”)) + “.jpg” + “\”";
        ConvertNow(imgargs);
        return true;
    }
    private void ConvertNow(string cmd)
    {
        string exepath;
        string AppPath = Request.PhysicalApplicationPath;
        //Get the application path
        exepath = AppPath + “ffmpeg.exe”;
        System.Diagnostics.Process proc = 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();
        while (proc.HasExited == false)
        {
        }
    }
    protected void btn_Submit_Click(object sender, EventArgs e)
    {
        ReturnVideo(this.fileuploadImageVideo.FileName.ToString());
    }
4), Here, you need put an upload to page, and then, rename to “ fileuploadImageVideo”
5), put an button and rename to “btn_Submit”
6), Make the following folders
    a, OriginalVideo
    b, ConvertVideo
    c, Thumbs
7), Import Class “using System.IO;”
Now, you can run the application and choose a video file to convert the video to FLV format. You’ll get the converted video in ConvertVideo Folder

0 comments:

Post a Comment