查看: 3041|回覆: 1
收起左側

[求助] (C#) FFmpeg pipe wav

[複製連結]

發表於 2012-11-18 23:57:27 | 顯示全部樓層 |閱讀模式

馬上註冊,結交更多好友,享用更多功能,讓你輕鬆玩轉社區。

您需要 登錄 才可以下載或查看,沒有賬號?註冊

x
本文章最後由 acerx 於 2012-11-19 00:10 編輯
  1.        private string LocalDirectory = System.Environment.CurrentDirectory;
  2.         
  3.         private byte[] ReadBuffer = new byte[4096];
  4.         private System.Diagnostics.Process Decoder = new System.Diagnostics.Process();
  5.         private System.Diagnostics.Process Encoder = new System.Diagnostics.Process();
  6.         private System.IO.BinaryWriter EncoderRawInput;

  7.         //Create WAV temp file for testing
  8.         private System.IO.Stream AS = new System.IO.FileStream("D:\\temporary.wav", System.IO.FileMode.Create);
  9.         private System.IO.BinaryWriter DecoderOutputRaw;
  10.         

  11.         public void AudioDecoding()
  12.         {
  13.             string INPUT = '"' + tbInputMedia.Text + '"';
  14.             string FFmpegOpts = "";
  15.             string FFmpegCL = String.Format("-i {0} -y -vn {1} -f wav - ", INPUT, FFmpegOpts);
  16.             tbResult.AppendText("FFmpeg " + FFmpegCL + "\r\n\r\n");

  17.             System.Diagnostics.ProcessStartInfo FFmpegPSI = new System.Diagnostics.ProcessStartInfo(Coder.FullName("FFmpeg"), FFmpegCL);
  18.             FFmpegPSI.UseShellExecute = false;
  19.             FFmpegPSI.Arguments = FFmpegCL;
  20.             FFmpegPSI.CreateNoWindow = true;
  21.             FFmpegPSI.RedirectStandardOutput = true;
  22.             FFmpegPSI.RedirectStandardError = true;
  23.             
  24.             Decoder.StartInfo = FFmpegPSI;
  25.             Decoder.Exited += new EventHandler(Decoder_Exited);
  26.             Decoder.ErrorDataReceived += new System.Diagnostics.DataReceivedEventHandler(Decoder_ErrorDataReceived);
  27.             Decoder.Start();
  28.             
  29.             DecoderOutputRaw = new System.IO.BinaryWriter(AS);
  30.             Decoder.BeginErrorReadLine();
  31.             Decoder.StandardOutput.BaseStream.BeginRead(ReadBuffer, 0, ReadBuffer.Length, new AsyncCallback(ReadCallBack), null);
  32.         }

  33.         private void ReadCallBack(IAsyncResult asyncResult)
  34.         {
  35.             int read = Decoder.StandardOutput.BaseStream.EndRead(asyncResult);
  36.             if (read > 0)
  37.             {
  38.                 EncoderRawInput.Write(ReadBuffer);
  39.                 EncoderRawInput.Flush();
  40.                 DecoderOutputRaw.Write(ReadBuffer);
  41.                 DecoderOutputRaw.Flush();
  42.                 Decoder.StandardOutput.BaseStream.Flush();
  43.                 Decoder.StandardOutput.BaseStream.BeginRead(ReadBuffer, 0, ReadBuffer.Length, new AsyncCallback(ReadCallBack), null);               
  44.             }
  45.             else
  46.             {
  47.                 Decoder.StandardOutput.BaseStream.Close();
  48.                 DecoderOutputRaw.Close();
  49.                 EncoderRawInput.Close();
  50.             }

  51.         }
  52.         
  53.         private void Decoder_Exited(object sender, System.EventArgs e)
  54.         {
  55.             Console.WriteLine("Exit");
  56.         }

  57.         private void Decoder_ErrorDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs errLine)
  58.         {
  59.             Console.WriteLine("Error");

  60.             if (String.IsNullOrEmpty(errLine.Data)) return;
  61.             this.Invoke(new MethodInvoker(() =>
  62.                 {
  63.                     tbResult.AppendText(errLine.Data + "\r\n");
  64.                 }));
  65.         }
  66.         
  67.         public void AudioEncoding()
  68.         {
  69.             //Encoder Settings
  70.             string EncoderFullName = Coder.FullName("qaac");
  71.             string Input = "-";
  72.             string Output = "-o" + ' ' + '"' + tbOutputPath.Text + "\\Test.aac" + '"';
  73.             string Opts = "-q 2 --tvbr 100 --ignorelength";

  74.             string EncoderCL = String.Format("{0} {2} {1}", Input, Output, Opts);

  75.             System.Diagnostics.ProcessStartInfo EncoderPSI = new System.Diagnostics.ProcessStartInfo(EncoderFullName);
  76.             EncoderPSI.UseShellExecute = false;
  77.             EncoderPSI.Arguments = EncoderCL;
  78.             EncoderPSI.CreateNoWindow = false;
  79.             EncoderPSI.RedirectStandardInput = true;
  80.             EncoderPSI.RedirectStandardError = false;
  81.             Encoder.StartInfo = EncoderPSI;
  82.             Encoder.Start();
  83.             EncoderRawInput = new System.IO.BinaryWriter(Encoder.StandardInput.BaseStream);            
  84.         }
複製代碼
經過 pipe 後 聲道 Layout 完全亂掉
雖然可以在 qaac 內指定 輸入RAW 的 Layout
但其他的 Encoder 則不一定有這項能,neroAacEnc 似乎就沒有
求各位前輩賜教


發表於 2012-11-19 19:45:06 | 顯示全部樓層
您好!有關您的問題推薦一個很棒的論壇,
那邊有許多後期高手都會自行編譯軟體,
看是否有所幫助~ 日後也希望您能不吝分享個人編譯的作品,造福更多網友
http://www.nmm-hd.org/newbbs/
回覆

使用道具 舉報

您需要登錄後才可以回文 登入 | 註冊

本版積分規則

熱門推薦

史詩級 Barefoot Atmos 錄音室巡禮|Butch Vig 導覽專訪
史詩級 Barefoot Atmos 錄
史詩級 Barefoot Atmos 錄音室巡禮|Butch Vig 導覽專訪 如果
MillSounds 沉浸式體驗:Barefoot LFE-15
MillSounds 沉浸式體驗:B
MillSounds 沉浸式體驗:Barefoot LFE-15 Barefoot LFE-15:極
Storm Audio風暴EVO AoIP進駐!成就5.4.4.7精準美聲客廳沉浸系統之巔
Storm Audio風暴EVO AoIP
Storm Audio風暴EVO AoIP進駐!成就5.4.4.7精準美聲客廳沉浸系統
經典影音測試片《芙莉歐莎:瘋狂麥斯傳奇篇章》
經典影音測試片《芙莉歐莎
對中生代的影音玩家來說,2015 年上映的《瘋狂麥斯:憤怒道》,
BOE、洲明、青松、飛利浦、海信、TCL、兆馳等20+企業MLED、投影、商顯新品齊聚美國的Infocomm展會
BOE、洲明、青松、飛利浦
BOE、洲明、青松、飛利浦、海信、TCL、兆馳等20+企業MLED、投影

聯絡我們| 問題反映| 小黑屋| 手機版| Archiver|  本網站特別聘請 蔡家豪律師 為本站法律顧問

快速回覆 返回頂部 返回列表