C# 如何使用ffmpeg从视频文件中提取图像流

C# 如何使用ffmpeg从视频文件中提取图像流,c#,ffmpeg,C#,Ffmpeg,我想使用ffmpeg从视频文件中提取图像流 我知道我可以使用以下参数将它们直接提取到硬盘: -i--qscale 1 h:\out\img-%05d.jpg 但我想直接提取到一个流 这是我目前的代码: private void ExtractImagesFromVideo(byte[] data,string _args) { try { serverBuild = new Process(); server

我想使用ffmpeg从视频文件中提取图像流

我知道我可以使用以下参数将它们直接提取到硬盘:

-i--qscale 1 h:\out\img-%05d.jpg

但我想直接提取到一个流

这是我目前的代码:

private void ExtractImagesFromVideo(byte[] data,string _args)
    {
        try
        {
            serverBuild = new Process();
            serverBuild.StartInfo.WorkingDirectory = Environment.CurrentDirectory;
            serverBuild.StartInfo.Arguments = _args;
            serverBuild.StartInfo.FileName = Environment.CurrentDirectory + @"\ffmpeg.exe";
            serverBuild.StartInfo.UseShellExecute = false;
            serverBuild.StartInfo.RedirectStandardOutput = true;
            serverBuild.StartInfo.RedirectStandardError = true;
            serverBuild.StartInfo.RedirectStandardInput = true;
            serverBuild.StartInfo.CreateNoWindow = true;
            serverBuild.StartInfo.LoadUserProfile = false;
            serverBuild.EnableRaisingEvents = true;
            serverBuild.Start();

            using (BinaryWriter bw = new BinaryWriter(serverBuild.StandardInput.BaseStream))
            {
                bw.Write(data);
            }

            mStandardOutput = serverBuild.StandardOutput.BaseStream;
            mStandardOutput.BeginRead(mReadBuffer, 0, mReadBuffer.Length, StandardOutputReadCallback, null);
            serverBuild.WaitForExit();
            byte[] _data = mStandardOutputMs.ToArray();
            mStandardOutput.Close();

        }
        catch (Exception _ex)
        {

        }
        finally
        {               
            serverBuild.Dispose();
        }
    }
我这样称呼:

     string _argsOut = @"-i pipe:0 -qscale 1 -f mjpeg pipe:1 ";
     ExtractImagesFromVideo(data, _argsOut);
它挂在这条线上:

bw.Write(data);

感谢

前几天,我在尝试用FFMPEG从视频中提取单个图像时意外地做了这件事

这是您想要的命令行:“-i input.flv-f image2-vf fps=fps=1 out%d.png”


Input.flv是源,fps=fps=1将在视频的每秒钟生成一个图像,out%d.png将是输出的文件。文件名和文件扩展名之间需要“%d”,因为这将创建一个类似这样的模式:out1.png、out2.png、out3.png等等。

您好,抱歉。这实际上并没有给我一个JPEG的数组。它只给了我以字节为单位的视频文件?哦,天哪,很抱歉。那应该奏效了:那是我的错!试试这个“-i inputfile.avi-r 1-t 4图像-%d.jpeg”-r1表示每秒一帧,-t4表示持续4秒。我有一个存储在文本文档中的FFMPEG命令行列表,这是我用于提取帧的另一个列表。如果不是这样的话,那应该可以。我还有几个选择:phi,我真的很感谢你在这方面的时间和帮助,但是我真正想要的是从process类中的stdout管道派生的流中获取JPEG。所有这些只是将JPEG/图像写入硬盘,这不是我想要的。