亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

asp.net音頻轉(zhuǎn)換之.amr轉(zhuǎn).mp3(利用ffmpeg轉(zhuǎn)換法)

 更新時(shí)間:2016年12月27日 11:36:24   作者:LI小白  
AMR轉(zhuǎn)MP3可實(shí)現(xiàn)將手機(jī)上的AMR錄音轉(zhuǎn)換成流行的MP3格式,以適用更廣泛的應(yīng)用。AMR的體積非常小,適用于存儲(chǔ)在手機(jī)中,當(dāng)我們想將在手機(jī)上的音頻上傳到網(wǎng)絡(luò),就需要將其轉(zhuǎn)換成MP3等流行的格式,本文就是介紹asp.net利用ffmpeg轉(zhuǎn)換法將.amr轉(zhuǎn).mp3的方法,下面來(lái)一起看看吧。

前言

上篇文章已經(jīng)跟大家分享了asp.net利用七牛轉(zhuǎn)換法將.amr轉(zhuǎn).mp3的方法,當(dāng)時(shí)也說(shuō)了還有另外一種方法是利用ffmpeg轉(zhuǎn)換法,下面這篇文章就給大家詳細(xì)介紹這種方法。這種方法相對(duì)第一種來(lái)說(shuō),要簡(jiǎn)單的多!

FFmpeg的名稱來(lái)自MPEG視頻編碼標(biāo)準(zhǔn),前面的“FF”代表“Fast Forward”,F(xiàn)Fmpeg是一套可以用來(lái)記錄、轉(zhuǎn)換數(shù)字音頻、視頻,并能將其轉(zhuǎn)化為流的開(kāi)源計(jì)算機(jī)程序??梢暂p易地實(shí)現(xiàn)多種視頻格式之間的相互轉(zhuǎn)換。

ffmpeg轉(zhuǎn)換法

首先,你得下載個(gè)“ffmpeg.exe” 插件,然后把它放到你的項(xiàng)目中,如下圖:

程序中會(huì)調(diào)用該文件,以助于轉(zhuǎn)換音頻格式!

上代碼:

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('轉(zhuǎn)換成功!');</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>
 /// 執(zhí)行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;
 }
 }
}

接著來(lái)張效果圖:

總結(jié)

好了,就這么簡(jiǎn)單,不要不敢不相信你的眼睛,其實(shí)就是這么簡(jiǎn)單!以上就是asp.net音頻轉(zhuǎn)換之.amr轉(zhuǎn).mp3(利用ffmpeg轉(zhuǎn)換法)的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流。

相關(guān)文章

最新評(píng)論