I'm writing a c++ webcam viewer using video4linux. I need a RGB24 output (interleaved R8B8G8) for displaying. I'm able to get video input for almost all low-resolution webcam, using YUYV, GREY8 or RGB24. But I need to get input also from high-resolution webcams, that use MJPEG for compression when high framerate is needed.
I'm able to get MJPEG stream using V4L2_PIX_FMT_MJPEG
as pixel format, but received framebuffer is compressed.
How can I quickly convert it to RGB24?
Can I use libjpeg for this?
The quickest solution I've found is
decode_jpeg_raw
from mjpegtools which decode jpeg data to planar YUV420. Then the conversion from yuv420 to rgb24 is done by this function: