4

I've encountered a problem during decoding RTP/MJPEG stream from ip-camera.

As rfc2435 states, quantization tables (for Q values 1 <= Q <= 99) should be calculated from these default tables:

/*
* Table K.1 from JPEG spec.
*/
static const int jpeg_luma_quantizer[64] = {
    16, 11, 10, 16, 24, 40, 51, 61,
    12, 12, 14, 19, 26, 58, 60, 55,
    14, 13, 16, 24, 40, 57, 69, 56,
    14, 17, 22, 29, 51, 87, 80, 62,
    18, 22, 37, 56, 68, 109, 103, 77,
    24, 35, 55, 64, 81, 104, 113, 92,
    49, 64, 78, 87, 103, 121, 120, 101,
    72, 92, 95, 98, 112, 100, 103, 99
};

/*
 * Table K.2 from JPEG spec.
 */
static const int jpeg_chroma_quantizer[64] = {
    17, 18, 24, 47, 99, 99, 99, 99,
    18, 21, 26, 66, 99, 99, 99, 99,
    24, 26, 56, 99, 99, 99, 99, 99,
    47, 66, 99, 99, 99, 99, 99, 99,
    99, 99, 99, 99, 99, 99, 99, 99,
    99, 99, 99, 99, 99, 99, 99, 99,
    99, 99, 99, 99, 99, 99, 99, 99,
    99, 99, 99, 99, 99, 99, 99, 99
};

This algorithm leads to poor picture quality (vlc shows better). I've looked through ffmpeg sources, and have found similar algorithm but with different tables:

static const uint8_t default_quantizers[128] = {
    /* luma table */
    16,  11,  12,  14,  12,  10,  16,  14,
    13,  14,  18,  17,  16,  19,  24,  40,
    26,  24,  22,  22,  24,  49,  35,  37,
    29,  40,  58,  51,  61,  60,  57,  51,
    56,  55,  64,  72,  92,  78,  64,  68,
    87,  69,  55,  56,  80,  109, 81,  87,
    95,  98,  103, 104, 103, 62,  77,  113,
    121, 112, 100, 120, 92,  101, 103, 99,

    /* chroma table */
    17,  18,  18,  24,  21,  24,  47,  26,
    26,  47,  99,  66,  56,  66,  99,  99,
    99,  99,  99,  99,  99,  99,  99,  99,
    99,  99,  99,  99,  99,  99,  99,  99,
    99,  99,  99,  99,  99,  99,  99,  99,
    99,  99,  99,  99,  99,  99,  99,  99,
    99,  99,  99,  99,  99,  99,  99,  99,
    99,  99,  99,  99,  99,  99,  99,  99
};

I've changed tables to ffmpeg tables and the picture now looks perfect. So, why are these tables different from rfc2435? What am I missing?

stakasha
  • 316
  • 2
  • 6

2 Answers2

0

Different tables work better for different content. Also better tables are found as time goes on. Finding the best table is really trial and error using human judges on quality, then making trade offs for what type of content you wish to optimize for. ffmpeg may also produce larger files. And the larger files may not have been acceptable when the jpeg spec was originally written.

szatmary
  • 29,969
  • 8
  • 44
  • 57
  • The problem is that in RTP/MJPEG stream (for Q values 1 <= Q <= 99) there are no tables provided. They are predefined by RTP payload standard rfc2435. If they are predefined there should be only one way to calculate them. I cannot figure out what way is right. – stakasha Mar 13 '14 at 08:25
  • I'm not sure why that is. I'm about at the edge of my knowledge for JPEG. Sorry, good luck! – – szatmary Mar 13 '14 at 18:58
0

The defaults are pre-calculated but you can also include your own for Q=100, See my implementation @ https://net7mma.codeplex.com/SourceControl/latest#Rtp/RFC2435Frame.cs

Jay
  • 3,276
  • 1
  • 28
  • 38