Подтвердить что ты не робот

Загрузите любое видео и конвертируйте в .mp4 онлайн в .net

У меня странное требование. Пользователь может загружать свое видео в любом формате (или в ограниченном формате). Мы должны их хранить и преобразовывать в формат .mp4, чтобы мы могли играть на нашем сайте.

Такое же требование также для аудиофайлов.

У меня есть googled, но я не могу понять. Любая помощь или предложения....??

Заранее спасибо

4b9b3361

Ответ 1

Вы можете конвертировать практически любые видео/аудио файлы пользователя в mp4/mp3 с помощью утилиты командной строки FFMpeg. Из .NET его можно вызывать с помощью библиотеки обложек, например Video Converter for.NET (это хорошо, потому что все упаковано в одну DLL):

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

Обратите внимание, что для преобразования видео требуются значительные ресурсы ЦП; это хорошая идея запустить его в фоновом режиме.

Ответ 2

Ваш ответ

Замените .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());
    }