C#console app处理FFMPEG jpg流输出

时间:2014-09-15 15:42:43

标签: c# ffmpeg

我正在寻找一些提示或想法,以便处理由fFMPEG命令创建的jpg文件流。

有一种方法可以将outpuStream拆分为捕获每个jpg文件吗?

这是命令 ffmpeg -i rtsp:// somertsp:554 -an -f image2pipe -vf fps = fps = 5 -

我使用C#应用程序执行该命令。

这是一个示例代码

class Program
{
    private static BackgroundWorker worker;
    private static MemoryStream buffer = new MemoryStream();
    private static BinaryWriter bufferWriter = new BinaryWriter(buffer);

    static void Main(string[] args)
    {
        string file = @"C:\ffmpeg\bin\ffmpeg.exe";
        string arguments = @"-i rtsp://xxx:yyy@v5demo.wavestore.com:554/rtsp/00004 -an -f image2pipe -vf fps=fps=5 -qscale 0 -";

        var processStartInfo = new ProcessStartInfo(file, arguments);
        processStartInfo.CreateNoWindow = false;
        processStartInfo.RedirectStandardError = true;
        processStartInfo.RedirectStandardOutput = true;
        processStartInfo.UseShellExecute = false;

        worker = new BackgroundWorker();
        worker.DoWork += worker_DoWork;
        worker.WorkerReportsProgress = true;
        worker.ProgressChanged += worker_ProgressChanged;

        var process = new Process();
        process.StartInfo = processStartInfo;
        process.Start();

        worker.RunWorkerAsync(process);
        process.WaitForExit();

    }

    static void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        // save the image
    }

    static void worker_DoWork(object sender, DoWorkEventArgs e)
    {
        try
        {

            var internalWorker = sender as BackgroundWorker;
            Process p = e.Argument as Process;
            buffer = new MemoryStream();
            bufferWriter = new BinaryWriter(buffer);
            using (var reader = new BinaryReader(p.StandardOutput.BaseStream))
            {
                while (true)
                {
                   //get the jpg image
                }
            }

        }
        catch (Exception ex)
        {
          // Log the error, continue processing the live stream
        }
    }        
}

0 个答案:

没有答案