You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I try to make use of this library to convert MJPG encoded frames to a format (RGB, RGBA or YUV) that can suite my needs for image processing . This is because on my Windows computer (and maybe others) the only webcam encoding that can provide (somewhat) high resolution with decent framerate is the MJPG one.
Anyway, I am using a modified version of Escapi which is a Rust library around some Windows API for Webcam capture (among other things). I managed to get the MJPG encoded frames buffer but while trying to decode them I got the following error:
Error is invalid JPEG format: scan makes use of unset dc huffman table
After dumping a frame into a file on looking at it in an hex editor I can confirm that the file has no huffman table section. The Windows image viewer cannot open the file but GIMP manage to do it. Plus, inserting some huffman tables before the "start of scan" section from another random jpeg (found on the web) allow me to see it in the Windows image viewer and to decode it using this library. So I am no expert in JPG nor data compression/decompression but it seems that while my buffers are not strictly valid jpeg files because they lack huffman tables, there is a way to decode nonetheless them. Do you think you will be able to add support for this case?
By the way, I can provide some files if you want to take a look at the MJPG buffers.
I did some reading and it seems that the JPEG standard define some huffman tables (Near the end of the page). I think that how GIMP, Firefox and Chrome are able to display those images. Moreover, it seems that usually most jpg uses these default tables, that's would explain why after pasting the tables from a random jpg it display without problem. I will test my hypothesis and post the result.
@codec-abc Yes, it seems that it is valid for MJPEG frames to omit the huffman table and expect some default tables to be used. More info can be found here.
I plan to add support for this behavior by detecting MJPEGs and falling back to these huffman tables if no others has been defined. Hopefully I'll have a patch for it during the week.
I ran some test and indeed adding the default huffman tables when none are provided fix this edge case. You may want to look at my commit if you plan to fix this edge case. My fix seems a bit hackish so I am not doing a pull request but feel free to get the huffman tables from it if it's convenient for you.
Activity
[-]Support for image not having huffman table[/-][+]Support for images not having huffman table[/+]kaksmet commentedon Aug 25, 2017
@codec-abc Please upload a sample file and I'll take a look at this.
codec-abc commentedon Aug 25, 2017
Here you go,
This is the image buffer once I added a huffman table from another jpeg with a hex editor.

This is the raw buffer that I got from the webcam capture.

EDIT: They both display well in Chrome and Firefox I did not expected that.
codec-abc commentedon Aug 27, 2017
I did some reading and it seems that the JPEG standard define some huffman tables (Near the end of the page). I think that how GIMP, Firefox and Chrome are able to display those images. Moreover, it seems that usually most jpg uses these default tables, that's would explain why after pasting the tables from a random jpg it display without problem. I will test my hypothesis and post the result.
kaksmet commentedon Aug 27, 2017
@codec-abc Yes, it seems that it is valid for MJPEG frames to omit the huffman table and expect some default tables to be used. More info can be found here.
I plan to add support for this behavior by detecting MJPEGs and falling back to these huffman tables if no others has been defined. Hopefully I'll have a patch for it during the week.
codec-abc commentedon Aug 28, 2017
I ran some test and indeed adding the default huffman tables when none are provided fix this edge case. You may want to look at my commit if you plan to fix this edge case. My fix seems a bit hackish so I am not doing a pull request but feel free to get the huffman tables from it if it's convenient for you.