首页 文章

如何使用c#将system.io流对象输入到ffmpeg

提问于
浏览
-1

我有一个System.io流对象,这是原始的pcm数据,如果我想使用ffmpeg转换它我应该使用什么命令

1 回答

  • 0

    您需要将流传输到ffmpeg进程 . 这个博客很有帮助https://mathewsachin.github.io/blog/2017/07/28/ffmpeg-pipe-csharp.html

    如果该链接出现故障

    using System.Diagnostics;
    
    var inputArgs = "-framerate 20 -f rawvideo -pix_fmt rgb32 -video_size 1920x1080 -i -";
    var outputArgs = "-vcodec libx264 -crf 23 -pix_fmt yuv420p -preset ultrafast -r 20 out.mp4";
    
    var process = new Process
    {
        StartInfo =
        {
            FileName = "ffmpeg.exe",
            Arguments = $"{inputArgs} {outputArgs}",
            UseShellExecute = false,
            CreateNoWindow = true,
            RedirectStandardInput = true
        }
    };
    
    process.Start();
    
    var ffmpegIn = process.StandardInput.BaseStream;
    
    // Write Data
    ffmpegIn.Write(Data, Offset, Count);
    
    // After you are done
    ffmpegIn.Flush();
    ffmpegIn.Close();
    
    // Make sure ffmpeg has finished the work
    process.WaitForExit();
    

相关问题