Processing jpgs stream from the standard output

为君一笑 提交于 2019-12-11 04:21:36

问题


Using FFmpeg I converted a video (mpeg2) into jpgs, redirecting the output into the standard output.

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

I'm able to receive the callback from the process with the data:

_ffmpegProc.OutputDataReceived += new DataReceivedEventHandler(_ffmpegProc_OutputDataReceived);

But how can I save that back into jpg files?, I'd need to know the size of each jpg, but I cant figure out how.

Thanks.


回答1:


You can't without reading and at least partially understanding the stream structure because JPEG files don't contain e.g. an explicit length indication somewhere at file start.

I see two possibilities that don't involve transcoding:

  1. store the intermediate files on disk, but I guess that's just what you want to avoid.
  2. try minimally parsing the files - a JPEG file starts with a SOI marker (hex FF D8) and ends with an EOI marker (hex FF D9). With a relatively simple state machine you could try splitting the stream of JPG's into separate frames this way. Now, for robustness sake it's probably better to read the segments individually (see the JPEG file format for more info). You can also study the ffmpeg mjpeg decoder's source implementation, it looks quite robust.


来源:https://stackoverflow.com/questions/11742896/processing-jpgs-stream-from-the-standard-output

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!