FFmpeg C#应用(三):音频格式转换——AMR转WAV

利用FFmpeg可将amr格式的音频文件转为wav格式。

			public bool VoiceTransfer(string inputPath, string outputPath)
	        {
	            if (System.IO.File.Exists(inputPath))
	            {
	                if (System.IO.File.Exists(outputPath))
	                {
	                    File.Delete(outputPath);
	                }
	
	                string ffmpegPath = new FileInfo(Process.GetCurrentProcess().MainModule.FileName).DirectoryName + @"\ffmpeg.exe";
	                string output = string.Empty;
	                string error = string.Empty;
	                Process pc = new Process();
                
                    string cmd = "\"" + ffmpegPath + "\"" + " -y -i " + "\"" + inputPath + "\"" + " -ar 8000 -ab 12.2k -ac 1 " + "\"" + outputPath + "\"";
                    this.ExecuteCommand(pc, cmd, out output, out error);
                    // 通过正则表达式获取信息里面的宽度信息
                    Regex regex = new Regex("(\\d{2,4})x(\\d{2,4})", RegexOptions.Compiled);
                    if (!string.IsNullOrEmpty(error))
                    {
                        Match m = regex.Match(error);
                        if (m != null)
                        {
                            if (!m.Success)
                            {
                                if (System.IO.File.Exists(outputPath))
                                {
                                    System.IO.File.Delete(inputPath);

                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                        }
                    }

                    return false;
	            }
	
	            return false;
	        }

你可能感兴趣的:(ffmpeg)