Skip to content

Support for images not having huffman table #76

Closed

Description

@codec-abc

Hi,

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.

Activity

  1. changed the title [-]Support for image not having huffman table[/-] [+]Support for images not having huffman table[/+] on Aug 25, 2017
  2. kaksmet commented on Aug 25, 2017

    @kaksmet
    Member

    @codec-abc Please upload a sample file and I'll take a look at this.

  3. codec-abc commented on Aug 25, 2017

    @codec-abc
    Author

    Here you go,

    This is the image buffer once I added a huffman table from another jpeg with a hex editor.
    bufferfixed

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

    EDIT: They both display well in Chrome and Firefox I did not expected that.

  4. codec-abc commented on Aug 27, 2017

    @codec-abc
    Author

    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.

  5. kaksmet commented on Aug 27, 2017

    @kaksmet
    Member

    @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.

  6. codec-abc commented on Aug 28, 2017

    @codec-abc
    Author

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions