資源簡介
微信公眾號開發中,有涉及到微信語音功能,但是對于amr格式的音頻在某些地方無法播放,因此只能想辦法轉成其他格式,例如mp3。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.IO;
using?System.Linq;
using?System.Web;
namespace?_2016_01_15?{
????public?class?MediaFileFormatConverter?{
????????///?
????????///?音頻運行格式轉換(?.amr?=>?.mp3?)
????????///?
????????///?
????????///?源文件物理路徑
????????///?目標文件虛擬路徑
????????///?
????????public?string?ConvertAudio(string?ffmpegVirtualPath?string?sourceFile?string?fileVirtualPath)?{
????????????//取得ffmpeg.exe的物理路徑
????????????string?ffmpeg?=?System.Web.HttpContext.Current.Server.MapPath(ffmpegVirtualPath);
????????????if?(!File.Exists(ffmpeg))?{
????????????????return?“找不到格式轉換程序!“;
????????????}
????????????if?(!File.Exists(sourceFile))?{
????????????????return?“找不到源文件!“;
????????????}
????????????string?destFile?=?HttpContext.Current.Server.MapPath(fileVirtualPath);
????????????System.Diagnostics.ProcessStartInfo?FilestartInfo?=?new?System.Diagnostics.ProcessStartInfo(ffmpeg);
????????????FilestartInfo.Windowstyle?=?System.Diagnostics.ProcessWindowstyle.Hidden;
????????????/*ffmpeg參數說明
?????????????*?-i?1.avi???輸入文件
?????????????*?-ab/-ac?<比特率>?設定聲音比特率,前面-ac設為立體聲時要以一半比特率來設置,比如192kbps的就設成96,轉換?
????????????????均默認比特率都較小,要聽到較高品質聲音的話建議設到160kbps(80)以上
?????????????*?-ar?<采樣率>?設定聲音采樣率,PSP只認24000
?????????????*?-b?<比特率>?指定壓縮比特率,似乎ffmpeg是自動VBR的,指定了就大概是平均比特率,比如768,1500這樣的???--加了以后轉換不正常
?????????????*?-r?29.97?楨速率(可以改,確認非標準楨率會導致音畫不同步,所以只能設定為15或者29.97)
?????????????*?s?320x240?指定分辨率
?????????????*?最后的路徑為目標文件
?????????????*/
????????????FilestartInfo.Arguments?=?“?-i?“?+?sourceFile?+?“?-vn?-ar?8?-ac?2?-ab?192?-f?mp3?“?+?destFile;
????????????try?{
????????????????//轉換
????????????????System.Diagnostics.Process.Start(FilestartInfo);
????????????}
????????????catch?{
????????????????return?“格式轉換失敗!“;
????????????}
????????????return?“格式轉換成功!“;
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2020-06-29?10:30??ffmpeg(amr轉換mp3).exe\
?????文件????????9371??2016-01-15?11:58??ffmpeg(amr轉換mp3).exe\2016-01-15.csproj
?????文件????????1084??2016-01-15?11:58??ffmpeg(amr轉換mp3).exe\2016-01-15.csproj.user
?????目錄???????????0??2020-06-29?10:30??ffmpeg(amr轉換mp3).exe\bin\
?????文件????????5120??2016-01-15?11:59??ffmpeg(amr轉換mp3).exe\bin\2016-01-15.dll
?????文件???????13824??2016-01-15?11:59??ffmpeg(amr轉換mp3).exe\bin\2016-01-15.pdb
?????文件?????1843432??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\Microsoft.AI.Agent.Intercept.dll
?????文件???????55552??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\Microsoft.AI.DependencyCollector.dll
?????文件???????50384??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\Microsoft.AI.DependencyCollector.xm
?????文件???????66824??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\Microsoft.AI.PerfCounterCollector.dll
?????文件???????77072??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\Microsoft.AI.ServerTelemetryChannel.dll
?????文件???????19326??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\Microsoft.AI.ServerTelemetryChannel.xm
?????文件???????51904??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\Microsoft.AI.Web.dll
?????文件???????19163??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\Microsoft.AI.Web.xm
?????文件???????36584??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\Microsoft.AI.WindowsServer.dll
?????文件???????23812??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\Microsoft.AI.WindowsServer.xm
?????文件??????149752??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\Microsoft.ApplicationInsights.dll
?????文件??????135417??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\Microsoft.ApplicationInsights.xm
?????文件???????29344??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll
?????文件????????1805??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.xm
?????目錄???????????0??2020-06-29?10:30??ffmpeg(amr轉換mp3).exe\bin\roslyn\
?????文件???????41608??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\roslyn\csc.exe
?????文件???????85192??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\roslyn\Microsoft.Build.Tasks.CodeAnalysis.dll
?????文件?????4000448??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\roslyn\Microsoft.CodeAnalysis.CSharp.dll
?????文件?????1724080??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\roslyn\Microsoft.CodeAnalysis.dll
?????文件?????4901064??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\roslyn\Microsoft.CodeAnalysis.VisualBasic.dll
?????文件????????6416??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\roslyn\Microsoft.CSharp.Core.targets
?????文件????????5846??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\roslyn\Microsoft.VisualBasic.Core.targets
?????文件??????204544??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\roslyn\System.Collections.Immutable.dll
?????文件??????262896??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\roslyn\System.Reflection.me
?????文件???????41608??2016-01-15?11:52??ffmpeg(amr轉換mp3).exe\bin\roslyn\vbc.exe
............此處省略24個文件信息
- 上一篇:矩陣計算中文版——GH戈盧布
- 下一篇:greenplum
評論
共有 條評論