C # - analyzing ffmpeg standard output when extracting images

I am extracting individual video frames by starting the ffmpeg process from my C # code. The default behavior is to write these images to disk. However, to speed up processing, I want to redirect the standard output of ffmpeg to get the stream and process it further in my program.

I use arguments like this:

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

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

This may work fine for movie streams, since I have only one output, but the call above will create 10 separate images (when writing to the hard drive), how can I parse the byte stream from the standard output and split it into single files?

+3
source share
2 answers

I found a solution that seems to work, but strangely enough is not mentioned in the ffmpeg documentation : Use image2pipeas output format.

So, for the example above, this would be:

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

This redirects the stream of bytes to stdout and allows you to capture and analyze images

+2
source

Thanks for your answer @leepfrog This is basically the same:

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();
0
source

All Articles