C# amr转mp3 (ffmpeg)


刚开始是为了做微信朗读投票,微信接口临时音频文件只保留三天,下载接口只提供amr格式音频,当时想把临时性音频转永久性素材来使用,结果微信不提供永久性音频素材播放接口。只好把amr转为mp3。。。。

     public bool ConvertToMp3(string pathBefore, string pathLater)
        {
            string c = System.Web.HttpContext.Current.Server.MapPath("/ffmpeg/") + @"ffmpeg.exe -i " + pathBefore + " " + pathLater;
            string output = "";
            RunCmd(c, out  output);
            if (!string.IsNullOrEmpty(output))
            {
                if (File.Exists(pathLater))
                    return true;
                else
                    return false;
            }
            else
                return false;
        }

        /// <summary>
        /// 执行Cmd命令
        /// </summary>
        private static void RunCmd(string cmd, out string output)
        {
            cmd = cmd.Trim().TrimEnd('&') + "&exit";
            using (Process p = new Process())
            {
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.UseShellExecute = false;        //是否使用操作系统shell启动
                p.StartInfo.RedirectStandardInput = true;   //接受来自调用程序的输入信息
                p.StartInfo.RedirectStandardOutput = true;  //由调用程序获取输出信息
                p.StartInfo.RedirectStandardError = true;   //重定向标准错误输出
                p.StartInfo.CreateNoWindow = true;          //不显示程序窗口
                p.Start();//启动程序
                //向cmd窗口写入命令
                p.StandardInput.WriteLine(cmd);
                p.StandardInput.AutoFlush = true;
                //获取cmd窗口的输出信息
                output = p.StandardOutput.ReadToEnd();
                p.WaitForExit();//等待程序执行完退出进程
                p.Close();
            }
        }

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM