从标准输出处理jpgs流 [英] Processing jpgs stream from the standard output

查看:152
本文介绍了从标准输出处理jpgs流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用FFmpeg我将视频(mpeg2)转换为jpgs,将输出重定向到标准输出。

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

但是如何将其保存回jpg文件?我需要知道每个jpg的大小,但我无法弄清楚如何。

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.

谢谢。

推荐答案

你不能没有阅读,至少部分了解流结构,因为JPEG文件不包含例如文件开头某处的显式长度指示。

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. 将中间文件存储在磁盘上,但我想这只是你想要避免的。

  2. 尝试最低限度的解析文件 - JPEG文件以 SOI 标记(十六进制FF D8)开始,并以 EOI 标记(十六进制)结尾FF D9)。使用相对简单的状态机,您可以尝试将JPG的流分成单独的帧。现在,为了坚固的缘故,可能会更好地单独阅读细分(参见 JPEG文件格式获取更多信息)。您还可以学习 ffmpeg mjpeg解码器的源代码实现,它看起来很健壮。

  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.

这篇关于从标准输出处理jpgs流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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