.net 音頻轉換 .amr 轉 .mp3 (ffmpeg轉換法)

來源:互聯網
上載者:User

標籤:

最近看來是跟聲音幹上了啊!

音頻轉換的第二種方法,這種方法相對第一種來說,要簡單的多!

首先,你得下載個“ffmpeg.exe” 外掛程式,然後把它放到你的項目中,如:

程式中會調用該檔案,以助於轉換音頻格式!

上代碼:

using System;using System.Threading;using System.IO;using System.Diagnostics;using System.Security;public partial class cowala_201512Chritmas_amrtest : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {    if (!IsPostBack)     {      changedPlay.Visible = false;    }    }    protected void Ffmpeg_Click(object sender, EventArgs e)    {        if (AmrFileUp.HasFile)        {            string key = AmrFileUp.FileName;            string savepath = Server.MapPath("~/upload/amr/") + key;            AmrFileUp.SaveAs(savepath);            string mp3SavePth = Server.MapPath("~/upload/mp3/") + key.Split(‘.‘)[0].ToString() + ".mp3";            if (!string.IsNullOrEmpty(ConvertToMp3(savepath, mp3SavePth)))            {                changedPlay.Visible = true;                changedPlay.Attributes.Add("src", "upload/mp3/" + key.Split(‘.‘)[0].ToString() + ".mp3");                Response.Write("<script>alert(‘轉換成功!‘);</script>");            }        }    }    public string ConvertToMp3(string pathBefore, string pathLater)    {        string c = Server.MapPath("/ffmpeg/") + @"ffmpeg.exe -i " + pathBefore + " " + pathLater;        string str = RunCmd(c);        return str;    }    /// <summary>    /// 執行Cmd命令    /// </summary>    private string RunCmd(string c)    {        try        {            ProcessStartInfo info = new ProcessStartInfo("cmd.exe");            info.RedirectStandardOutput = false;            info.UseShellExecute = false;            Process p = Process.Start(info);            p.StartInfo.UseShellExecute = false;            p.StartInfo.RedirectStandardInput = true;            p.StartInfo.RedirectStandardOutput = true;            p.StartInfo.RedirectStandardError = true;            p.Start();            p.StandardInput.WriteLine(c);            p.StandardInput.AutoFlush = true;            Thread.Sleep(1000);            p.StandardInput.WriteLine("exit");            p.WaitForExit();            string outStr = p.StandardOutput.ReadToEnd();            p.Close();            return outStr;        }        catch (Exception ex)        {            return "error" + ex.Message;        }    }}

 

接著來張:

好了,就這麼簡單,不要不敢不相信你的眼睛,其實就是這麼簡單!

最後,來個問題:你們解完手後,擦時,習慣用左手還是右手?

 

有任何疑問歡迎進群騷擾:225443677  不要不好意思哦!

TKS!!!

 

.net 音頻轉換 .amr 轉 .mp3 (ffmpeg轉換法)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.