0

I am trying to view live video from my webcam. I can draw the image to a window using OpenGL, get the frames in YUV and convert them on the fly into RGB. I can convert YUV colors into RGB easily, as well as I can get a pointer to the data from the MJPEG. all I need is the ability to decode MJPEG into either YUV or RGB live. I have heard of libjpeg, as well as libjpeg-turbo, however, I do not know how to use either of them. I have libjpeg

If I use MJPEG (and shrink the image buffer so that I don't read memory that's not mine):

mjpeg random noise

If I use YUV422:

enter image description here

  • If using opencv is possible, see if this helps https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_video_display/py_video_display.html – Saisai3396 Nov 29 '19 at 17:08
  • @Saisai3396, I am running my code on an embedded device which is why I want to write the code myself, in c++, to run as fast as possible. From what I have seen through testing on the device, although very useful, not only does it not give the amount of control I need, OpenCV is bloated and slower than I desire. I have looked through the source code of OpenCV thoroughly and can't seem to figure out how they decode the MJPEGs live. Would you happen to know how? – Gabe Rundlett Nov 29 '19 at 17:20
  • I believe, then a better option would be to use Video4Lan for kernel level access to the camera. It's a bit hard to wrap your head around but is very flexible and would definitely suit your needs. See https://linuxtv.org/downloads/v4l-dvb-apis/uapi/v4l/v4l2.html. I think opencv also uses this in the background for video streaming, camera settings, etc – Saisai3396 Nov 29 '19 at 17:33
  • 1
    @Saisai3396, I am already using Video4Linux2 to read the camera data, this is how I am getting the camera data in the first place. When opening the camera, you are able to specify the format in which one would like to stream the data. For my camera, there are two possible formats, YUYV (YUV422) and MJPEG. In the original post, the image with the correct camera data is me reading with YUYV, which is raw data. Although this is an easy way of reading the data from the camera, since it's raw (uncompressed), the camera is limited to 5fps at full resolution. Because of this, I want to use the MJPEG – Gabe Rundlett Nov 29 '19 at 17:41
  • My question is how do I convert this MJPEG frame to something like RGB or YUV, since then I can draw it, do image processing etc. – Gabe Rundlett Nov 29 '19 at 17:47
  • Alright. Now its much more clearer what you want! Might as well change the topic name to 'Decode MJPEG image on live stream'. Btw, have you tried ffmpeg? – Saisai3396 Nov 29 '19 at 17:52
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/203350/discussion-between-gabe-rundlett-and-saisai3396). – Gabe Rundlett Nov 29 '19 at 20:09

0 Answers0