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;
	        }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章