使用ffmpeg,我想知道是否可以在收到数据块时转换mp3比特率?
这意味着我会慢慢向ffmpeg发送块,以便输出另一个比特率的mp3。
所以在非常伪代码中,它看起来像:
来自用户的MP3请求
使用参数将默认mp3发送到ffmpeg以转换为所需的比特率。
当它正在编写一个新文件时,写下目前为止在Response outputstream中编写的内容(我在ASP.Net中)
这是可行的还是我需要切换到另一种技术?
[编辑]
目前,我正在尝试这样的解决方案:Convert wma stream to mp3 stream with C# and ffmpeg
[编辑2]
我回答了我的问题,将url作为输入和标准输出作为输出是可行的。使用url允许按块处理文件块,并使用stdout,我们可以在处理数据时访问它。
答案 0 :(得分:1)
以下是C#中的方法,在http://jesal.us/2008/04/how-to-manipulate-video-in-net-using-ffmpeg-updated/上读取并更改为从流到流的工作方式。这意味着使用ffmpeg“实时”转换流。
命令末尾的' - '代表“标准输出”,这就是为什么它是目的地。
private void ConvertVideo(string srcURL)
{
string ffmpegURL = @"C:\ffmpeg.exe";
DirectoryInfo directoryInfo = new DirectoryInfo(@"C:\");
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = ffmpegURL;
startInfo.Arguments = string.Format("-i \"{0}\" -ar 44100 -f mp3 -", srcURL);
startInfo.WorkingDirectory = directoryInfo.FullName;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardError = true;
startInfo.CreateNoWindow = false;
startInfo.WindowStyle = ProcessWindowStyle.Normal;
using (Process process = new Process())
{
process.StartInfo = startInfo;
process.EnableRaisingEvents = true;
process.ErrorDataReceived += new DataReceivedEventHandler(process_ErrorDataReceived);
process.OutputDataReceived += new DataReceivedEventHandler(process_OutputDataReceived);
process.Exited += new EventHandler(process_Exited);
try
{
process.Start();
process.BeginErrorReadLine();
process.BeginOutputReadLine();
process.WaitForExit();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
process.ErrorDataReceived -= new DataReceivedEventHandler(process_ErrorDataReceived);
process.OutputDataReceived -= new DataReceivedEventHandler(process_OutputDataReceived);
process.Exited -= new EventHandler(process_Exited);
}
}
}
void process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
if (e.Data != null)
{
byte[] b = System.Text.Encoding.Unicode.GetBytes(e.Data);
// If you are in ASP.Net, you do a
// Response.OutputStream.Write(b)
// to send the converted stream as a response
}
}
void process_Exited(object sender, EventArgs e)
{
// Conversion is finished.
// In ASP.Net, do a Response.End() here.
}