如何将所有类型(音频*)转换为mp3?使用FFMPEG

时间:2016-10-28 13:10:02

标签: asp.net-mvc audio ffmpeg converter

可以将所有音频转换为mp3吗?

System.Diagnostics.Process proc = new System.Diagnostics.Process();
                    proc.EnableRaisingEvents = false;
                    proc.StartInfo.FileName = @"""C:\ffmpeg\bin\ffmpeg.exe""";
                    proc.StartInfo.Arguments = "-i C:\\Matheus\\Matheus_Project\\Matheus_Project\\App_Data\\" + User.Identity.Name + "\\" + fileNameAndType + " -acodec libmp3lame -ab 128k C:\\Matheus\\Matheus_Project\\Matheus_Project\\App_Data\\" + User.Identity.Name + "\\" + fileName + ".mp3";  /* use /y to overwrite if there it exists already or will fail */
                    proc.StartInfo.UseShellExecute = false;
                    proc.StartInfo.CreateNoWindow = false;
                    proc.StartInfo.RedirectStandardOutput = true;
                    proc.StartInfo.RedirectStandardError = true;
                    proc.Start();

                    var output = proc.StandardOutput.ReadToEnd();
                    string output_error = proc.StandardError.ReadToEnd();

                    proc.WaitForExit();
                    proc.Close();

示例:

  • audio / x-m4a to mp3

  • audio / mp4 to mp3

  • audio / basic to mp3

  • audio / L24 to mp3

  • audio / mid to mp3

  • audio / x-aiff to mp3

  • audio / x-mpegurl to mp3

  • audio / vnd.rn-realaudio to mp3

  • audio / ogg to mp3

  • audio / vorbis to mp3

  • audio / vnd.wav to mp3

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

public void ConvertWavToMp3(string filename)         {             尝试             {                 string Flacfilename = AppDomain.CurrentDomain.BaseDirectory +“FlacRecording”;

            ProcessStartInfo psi = new ProcessStartInfo();
            psi.UseShellExecute = false;
            psi.CreateNoWindow = true;
            psi.WindowStyle = ProcessWindowStyle.Hidden;
            psi.FileName = AppDomain.CurrentDomain.BaseDirectory + @"lame.exe";
            psi.Arguments = "-b" + "128" + " --resample " + "22.05" + " -m j " +
                           "\"" + filename + "\"" + " " +
                            "\"" + Flacfilename + "\\" + Path.GetFileNameWithoutExtension(filename) + ".mp3" + "\"";


            Process p = Process.Start(psi);
            p.WaitForExit();
            p.Close();
            p.Dispose();


        }
        catch (Exception ae)
        {
        }

    }

下载lame.exe并将其放入您的应用程序并使用wav文件名传递fullpath来调用abover函数。