(C#) FFmpeg pipe wav
本文章最後由 acerx 於 2012-11-19 00:10 編輯private string LocalDirectory = System.Environment.CurrentDirectory;
private byte[] ReadBuffer = new byte;
private System.Diagnostics.Process Decoder = new System.Diagnostics.Process();
private System.Diagnostics.Process Encoder = new System.Diagnostics.Process();
private System.IO.BinaryWriter EncoderRawInput;
//Create WAV temp file for testing
private System.IO.Stream AS = new System.IO.FileStream("D:\\temporary.wav", System.IO.FileMode.Create);
private System.IO.BinaryWriter DecoderOutputRaw;
public void AudioDecoding()
{
string INPUT = '"' + tbInputMedia.Text + '"';
string FFmpegOpts = "";
string FFmpegCL = String.Format("-i {0} -y -vn {1} -f wav - ", INPUT, FFmpegOpts);
tbResult.AppendText("FFmpeg " + FFmpegCL + "\r\n\r\n");
System.Diagnostics.ProcessStartInfo FFmpegPSI = new System.Diagnostics.ProcessStartInfo(Coder.FullName("FFmpeg"), FFmpegCL);
FFmpegPSI.UseShellExecute = false;
FFmpegPSI.Arguments = FFmpegCL;
FFmpegPSI.CreateNoWindow = true;
FFmpegPSI.RedirectStandardOutput = true;
FFmpegPSI.RedirectStandardError = true;
Decoder.StartInfo = FFmpegPSI;
Decoder.Exited += new EventHandler(Decoder_Exited);
Decoder.ErrorDataReceived += new System.Diagnostics.DataReceivedEventHandler(Decoder_ErrorDataReceived);
Decoder.Start();
DecoderOutputRaw = new System.IO.BinaryWriter(AS);
Decoder.BeginErrorReadLine();
Decoder.StandardOutput.BaseStream.BeginRead(ReadBuffer, 0, ReadBuffer.Length, new AsyncCallback(ReadCallBack), null);
}
private void ReadCallBack(IAsyncResult asyncResult)
{
int read = Decoder.StandardOutput.BaseStream.EndRead(asyncResult);
if (read > 0)
{
EncoderRawInput.Write(ReadBuffer);
EncoderRawInput.Flush();
DecoderOutputRaw.Write(ReadBuffer);
DecoderOutputRaw.Flush();
Decoder.StandardOutput.BaseStream.Flush();
Decoder.StandardOutput.BaseStream.BeginRead(ReadBuffer, 0, ReadBuffer.Length, new AsyncCallback(ReadCallBack), null);
}
else
{
Decoder.StandardOutput.BaseStream.Close();
DecoderOutputRaw.Close();
EncoderRawInput.Close();
}
}
private void Decoder_Exited(object sender, System.EventArgs e)
{
Console.WriteLine("Exit");
}
private void Decoder_ErrorDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs errLine)
{
Console.WriteLine("Error");
if (String.IsNullOrEmpty(errLine.Data)) return;
this.Invoke(new MethodInvoker(() =>
{
tbResult.AppendText(errLine.Data + "\r\n");
}));
}
public void AudioEncoding()
{
//Encoder Settings
string EncoderFullName = Coder.FullName("qaac");
string Input = "-";
string Output = "-o" + ' ' + '"' + tbOutputPath.Text + "\\Test.aac" + '"';
string Opts = "-q 2 --tvbr 100 --ignorelength";
string EncoderCL = String.Format("{0} {2} {1}", Input, Output, Opts);
System.Diagnostics.ProcessStartInfo EncoderPSI = new System.Diagnostics.ProcessStartInfo(EncoderFullName);
EncoderPSI.UseShellExecute = false;
EncoderPSI.Arguments = EncoderCL;
EncoderPSI.CreateNoWindow = false;
EncoderPSI.RedirectStandardInput = true;
EncoderPSI.RedirectStandardError = false;
Encoder.StartInfo = EncoderPSI;
Encoder.Start();
EncoderRawInput = new System.IO.BinaryWriter(Encoder.StandardInput.BaseStream);
}經過 pipe 後 聲道 Layout 完全亂掉
雖然可以在 qaac 內指定 輸入RAW 的 Layout
但其他的 Encoder 則不一定有這項能,neroAacEnc 似乎就沒有
求各位前輩賜教
您好!有關您的問題推薦一個很棒的論壇,
那邊有許多後期高手都會自行編譯軟體,
看是否有所幫助~ 日後也希望您能不吝分享個人編譯的作品,造福更多網友
http://www.nmm-hd.org/newbbs/
頁:
[1]