[FFmpeg-user] Bad palette in decoding MPEG2 Subtitle

Emmanuel HOUITTE ehouitte at yacast.fr
Mon Oct 17 10:52:53 CEST 2011


Hi,

I'm trying to decode MPEG2 Subtitle in TS file.

There is no problem with an old version (02 december 2008) with rgba_palette code in AVSubtitleRect. rgba_palette was an (uint32_t *) variable.

Since recent version, ffmpeg has included rgba_palette in (uint8_t *) data[1] table and we have got an 8 bits palette instead of 32 bits.

So, every subtitle are monocolors.

Is there something I have misunderstood or there is really a bug?



This is some code to introduce my problem:



// Main
// Decode subtitle frame
int nRes = avcodec_decode_subtitle(pCodecCtx, pSubtitle, &frameFinished, packet.data, packet.size);

// Did we get a subtitle frame?
if(frameFinished != 0)
{
nSize = pSubtitle->num_rects;
for(i = 0; i < nSize; ++i)
{
int width = pSubtitle->rects[i].w;
int height = pSubtitle->rects[i].h;
SaveFrame(&pSubtitle->rects[i], width, height);
}

}





// Save
static void SaveFrame(AVSubtitleRect* pRect, int width, int height)
{
char szImagename[32];
sprintf(szImagename, "d:\\tmp\\ST\\frame%d.ppm", iFrame);
FILE* pImage=fopen(szImagename, "w");

int x, y, v;
for(y = 0; y < height; y++)
{
for(x = 0; x < width; x++)
{

// 20081202 version:  v is uint32_t
v = pRect->rgba_palette[pRect->bitmap[y * width + x]];

// recent version: v is uint8_t
//v = pRect->pict.data[1][pRect->pict.data[0][y * width + x]];

putc((v >> 16) & 0xff, pImage);
putc((v >> 8) & 0xff, pImage);
putc((v >> 0) & 0xff, pImage);
}
}
}






More information about the ffmpeg-user mailing list