zoukankan      html  css  js  c++  java
  • .net 音频转换 .amr 转 .mp3 (ffmpeg转换法)

    最近看来是跟声音干上了啊!

    音频转换的第二种方法,这种方法相对第一种来说,要简单的多!

    首先,你得下载个“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;
            }
        }
    }

    接着来张效果图:

    好了,就这么简单,不要不敢不相信你的眼睛,其实就是这么简单!

    最后,来个问题:你们解完手后,擦时,习惯用左手还是右手?

    转载请注明本博地址:http://www.cnblogs.com/LittleBai/p/5924416.html

    原创,装载注明!

    有任何疑问欢迎进群骚扰:225443677  不要不好意思哦!

    TKS!!!

  • 相关阅读:
    Python3全栈学习目录
    五句话搞定javavscript作用域
    Python线程池
    luogu4016 负载平衡问题
    luogu2756 飞行员配对方案问题
    luogu1251 餐巾计划问题
    luogu3386 【模板】二分图匹配 匈牙利算法 hdu2063 过山车 dinic
    luogu3381 【模板】最小费用最大流
    luogu3376 【模板】网络最大流 dinic
    luogu2740 [USACO4.2]草地排水Drainage Ditches 最大流EK
  • 原文地址:https://www.cnblogs.com/LittleBai/p/5924416.html
Copyright © 2011-2022 走看看