Click here to Skip to main content
15,908,843 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is the code that i am use but unable to convert

C#
ReturnVideo(this.FileUpload1.FileName.ToString());


C#
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 + "Admin\\Uploads\\Videos\\OriginalVideo";
        //Path of the original file
        outputPath = AppPath + "Admin\\Uploads\\Videos\\ConvertVideo";
        //Path of the converted file
        imgpath = AppPath + "Admin\\Uploads\\Videos\\Thumbs";
        //Path of the preview file
        string filepath = Server.MapPath("~/Admin/Uploads/Videos/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("~/Admin/Uploads/Videos/OriginalVideo/" + fileName);
        }
        try
        {
            this.FileUpload1.SaveAs(filepath);
        }
        catch
        {
            return false;
        }
        string outPutFile;
        outPutFile = "~/Admin/Uploads/Videos/OriginalVideo/" + fileName;
        int i = this.FileUpload1.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(".")) + ".wmv" + "\"";
        ConvertNow(cmd);
        ViewState["fileName"] = fileName.Remove(fileName.IndexOf(".")) + ".wmv";
        string imgargs = " -i \"" + outputPath + "\\" + fileName.Remove(fileName.IndexOf(".")) + ".wmv" + "\" -f image2 -ss 1 -vframes 1 -s 280x200 -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 + "Admin\\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 "wmvtool2.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)
        {
        }

    }
Posted
Updated 7-Nov-11 19:25pm
v2

 
Share this answer
 
v2
Comments
ShashankUpadhyay 11-Oct-12 8:32am    
i used the code above to convert the video file to flv. but the converted file is of 0 kb. please help to resolve the issue.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900