我需要將 ffmpeg 輸出讀取為管道。有一個代碼示例: public static void PipeTest() { Process proc = new Process(); proc.StartInfo.FileName = Path.Combine(WorkingFolder, "ffmpeg"); proc.StartInfo.Arguments = String.Format("$ ffmpeg -i input.mp3 pipe:1"); proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardInput = true; proc.StartInfo.RedirectStandardOutput = true; proc.Start(); FileStream baseStream = proc.StandardOutput.BaseStream as FileStream; byte[] audioData; int lastRead = 0; using (MemoryStream ms = new MemoryStream()) { byte[] buffer = new byte[5000]; do { lastRead = baseStream.Read(buffer, 0, buffer.Length); ms.Write(buffer, 0, lastRead); } while (lastRead > 0); audioData = ms.ToArray(); } using(FileStream s = new FileStream(Path.Combine(WorkingFolder, "pipe_output_01.mp3"), FileMode.Create)) { s.Write(audioData, 0, audioData.Length); } }它是來自 ffmpeg 的日志,第一個文件被讀?。狠斎?#0,mp3,來自“norm.mp3”:元數(shù)據(jù):編碼器:Lavf58.17.103 持續(xù)時間:00:01:36.22,開始:0.023021,比特率:128 kb/s 流 #0:0:音頻:mp3,48000 Hz , 立體聲, fltp, 128 kb/s 元數(shù)據(jù): 編碼器: Lavc58.27然后管道:[NULL @ 0x7fd58a001e00] 無法為“$”$ 找到合適的輸出格式:參數(shù)無效如果我運行“-i input.mp3 pipe:1”,則日志為:無法為“管道:1”管道:1 找到合適的輸出格式:參數(shù)無效如何設置正確的輸出?ffmpeg 應該如何知道輸出格式是什么?
2 回答

侃侃爾雅
TA貢獻1801條經(jīng)驗 獲得超16個贊
每當您在 ffmpeg 中使用管道輸出時,都需要該-f fmt
參數(shù)來避免您看到的錯誤。
您可以通過鍵入獲取可能的格式列表ffmpeg -formats
。
例如,如果您想要一個 wav 文件,請?zhí)砑?code>-f wav.
在您的示例中,參數(shù)應該是:
-i input.mp3 -f wav pipe:1
您可以將 wav 替換為 flac 或您喜歡的任何其他音頻格式。

白衣染霜花
TA貢獻1796條經(jīng)驗 獲得超10個贊
在我看來好像有一個錯字"$ ffmpeg -i input.mp3 pipe:1"
。如果您只想ffmpeg
使用諸如此類的選項進行調(diào)用-i
,請忽略該$
字符。只是"ffmpeg -i input.mp3 pipe:1"
。. 您已經(jīng)將主程序名稱傳遞給StartInfo.FileName
. 所以你可能也應該把它排除在外。試試"-i input.mp3 pipe:1"
你的Arguments
.
- 2 回答
- 0 關注
- 519 瀏覽
添加回答
舉報
0/150
提交
取消