上传任何视频,并转换成在.NET网上.MP4上传、并转、网上、视频

由网友(自认与酒同醉)分享简介:我有一个奇怪的要求。用户可以上传任何格式(或有限的格式)的视频。我们必须存储它们,并将其转换为 .MP4 格式,因此我们可以发挥在我们的网站。I have a strange requirement. User can upload their video of any format (or a limited fo...

我有一个奇怪的要求。用户可以上传任何格式(或有限的格式)的视频。我们必须存储它们,并将其转换为 .MP4 格式,因此我们可以发挥在我们的网站。

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.

我用Google搜索,但我不能得到任何正确的想法。任何帮助或建议.... ??

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

在此先感谢

推荐答案

您答

请更换。FLV到的MP4,你会得到你的答案

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 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 + "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());
    }
阅读全文

相关推荐

最新文章