【发布时间】:2020-01-07 16:16:31
【问题描述】:
我正在使用 Video4Linux2 打开与连接到我机器的摄像头的连接。我可以从我的相机设备请求 YUV 或 MJPEG 数据。由于增加相机请求的分辨率,同时也请求 YUV,导致程序减慢超过相机的刷新率(大概是因为在这段时间内发送的数据太多),我需要使用来自的 MJPEG 数据相机。我被困了一段时间,在网上找到的关于如何解码 MJPEG 的资源很少。
顺便说一下,我有以下所有数据:
unsigned char *data; // pointing to the data for the most current mjpeg frame from v4l2
size_t data_size; // the size (in bytes) of the mjpeg frame received from v4l2
unsigned char *r, *g, *b; // three heap allocated arrays in which to store the resulting data
// Can easily be altered to represent an array of structs holding all 3 components,
// as well as using yuv at different rates.
我所需要的只是将我的 mjpeg 帧实时转换为原始数据,RGB 或 YUV。 我听说过 libjpeg、mjpegtools、nvjpeg 等库,但是我无法找到很多关于如何使用它们来解码我所在位置的 mjpeg。任何帮助将不胜感激!
【问题讨论】:
-
试试这个gist.github.com/PhirePhly/3080633,但不要从文件中读取,而是使用
data和data_sizeforjpg_buffer和jpg_size。 -
另外,mjpeg 相机通常会忽略霍夫曼表,请参阅 github.com/jamieguinan/cti/blob/master/jpeg_misc.c#L234 和 github.com/jamieguinan/cti/blob/master/jpeghufftables.c
-
非常感谢@jamieguinan!我能够使用您链接到的示例代码。