
【如何使用C#AMR文件轉換成MP3】最近看來是跟聲音干上了啊!音頻轉換的第二種方法,這種方法相對第一種來說,要簡單的多!首先,你得下載個“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("");}}}public string ConvertToMp3(string pathBefore, string pathLater){string c = Server.MapPath("/ffmpeg/") + @"ffmpeg.exe -i " + pathBefore + " " + pathLater;string str = RunCmd(c);return str;}/// /// 執行Cmd命令/// 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;}}}
猜你喜歡
- 問:為什么玩紅警2共和國之輝會出現一半的時候突然卡死,只能強制退出,我是win8的系統,如何解決(
- 淘寶物流紅章憑證怎么開?如何判別真假?
- 抖音賬號交易平臺哪個最安全?如何判斷?
- 如何在百度里發表文章
- 京東卡買什么比較劃算?怎么使用?
- 東北立秋后天氣會如何
- 如何關閉 proxy server
- 自己種空心菜如何預防莖基部腫大
- 如何查詢商品房合同備案?
- 奶瓶刻度正確使用方法
