C#-提取图像时解析ffmpeg标准输出 [英] C# - Parsing ffmpeg standard output when extracting images

查看:267
本文介绍了C#-提取图像时解析ffmpeg标准输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am extracting single Video frames by starting a ffmpeg process from my c# code. The default behaviour is to write these images to disk. However to speed up processing I want to redirect the ffmpeg standard output to receive the stream and process it further in my program.

我使用的参数与此类似:

I am using arguments similar to this:

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

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

This redirects the byte stream to standard output which I can redirect to my program using process.StartInfo.RedirectStandardOutput = true.

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

This may work fine for movie streams as I only have a singe output, but the call above would produce 10 single images (when writing to hard disk), how can I parse the byte stream from standard output and split it into single files?

推荐答案

我发现了一个似乎可行的解决方案,但

I have found a solution which seems to work but strangly enough is not mentioned in the ffmpeg documentation: Use image2pipe as output format.

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

So for the example above it would be:

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

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

This redirects the byte stream to stdout and allows to capture and parse the images

这篇关于C#-提取图像时解析ffmpeg标准输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆