文章插图
【如何使用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
- 自己种空心菜如何预防茎基部肿大
- 如何查询商品房合同备案?
- 奶瓶刻度正确使用方法