C# - 提取图像时解析ffmpeg标准输出

时间:2012-05-08 20:03:41

标签: c# ffmpeg

我通过从c#代码启动ffmpeg进程来提取单个视频帧。默认行为是将这些映像写入磁盘。 但是为了加快处理速度,我想重定向ffmpeg标准输出以接收流并在我的程序中进一步处理。

我正在使用类似的论据:

-i \"" + Filename + "\" -vf \"scale=640:-1\" -an -vframes 100 -r 1 -f image2 -

这会将字节流重定向到标准输出,我可以使用process.StartInfo.RedirectStandardOutput = true将其重定向到我的程序。

这可能适用于电影流,因为我只有一个单输出,但上面的调用会产生10个单个图像(当写入硬盘时),我如何从标准输出解析字节流并将其拆分为单个文件?

2 个答案:

答案 0 :(得分:2)

我找到了一个似乎有效的解决方案,但在ffmpeg documentation中未提及:使用image2pipe作为输出格式。

因此,对于上面的示例,它将是:

-i \"" + Filename + "\" -vf \"scale=640:-1\" -an -vframes 100 -r 1 -f image2pipe -

这会将字节流重定向到stdout,并允许捕获和解析图像

答案 1 :(得分:0)

感谢您的回答@leepfrog 这基本上是一样的:

StringBuilder str = new StringBuilder();

        //Input file path
        str.Append(string.Format(" -i {0}", myinputFile));

        //Set the frame rate
        str.Append(string.Format(" -r {0}", myframeRate);

        //Indicate the output format
        str.Append(" -f image2pipe");

        //Connect the output to the standard output
        str.Append(" pipe:1");



        return str.ToString();