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

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

我使用类似这样的参数:

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

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

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

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

所以对于上面的例子,它将是:

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

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

谢谢你的回答@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();