gpt4 book ai didi

stream - 使用 ffmpeg 将 MP3 比特率从一个流转换为另一个流

转载 作者:行者123 更新时间:2023-12-04 23:17:32 26 4
gpt4 key购买 nike

使用 ffmpeg,我想知道是否可以在收到数据 block 时转换 mp3 比特率?

这意味着我会缓慢地将 block 发送到 ffmpeg,以便它输出具有另一个比特率的 mp3。

所以在非常伪代码中,它看起来像这样:

  • 来自用户
  • 的 MP3 请求
  • 将默认 mp3 发送到带有参数的 ffmpeg,以转换为所需的比特率。
  • 在写入新文件时,在响应输出流中写入到目前为止所写的内容(我在 ASP.Net 中)

  • 这是可行的还是我需要切换到另一种技术?

    [编辑]

    目前,我正在尝试这样的解决方案: Convert wma stream to mp3 stream with C# and ffmpeg

    [编辑 2]

    我回答了我的问题,将 url 作为输入和标准输出作为输出是可行的。使用 url 允许逐 block 处理文件,使用 stdout,我们可以在处理数据时访问数据。

    最佳答案

    这是 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.
    }

    关于stream - 使用 ffmpeg 将 MP3 比特率从一个流转换为另一个流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12554499/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com