[vlc-devel] [PATCH] Vobsubs in mkv extract the original_frame_width, original_frame_height and palette from the tracks CodecPrivate data which libavformat supplies in AVCodecContext extradata. Vobsubs in mkv were only using default values for these items.
John Stebbins
john at stebbins.name
Tue May 12 02:13:37 CEST 2009
---
modules/demux/avformat/demux.c | 59 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 59 insertions(+), 0 deletions(-)
diff --git a/modules/demux/avformat/demux.c b/modules/demux/avformat/demux.c
index dd0f7c9..bd4e5aa 100644
--- a/modules/demux/avformat/demux.c
+++ b/modules/demux/avformat/demux.c
@@ -271,6 +271,65 @@ int OpenDemux( vlc_object_t *p_this )
case CODEC_TYPE_SUBTITLE:
es_format_Init( &fmt, SPU_ES, fcc );
+ if (strncmp(p_sys->ic->iformat->name, "matroska", 8) == 0 &&
+ cc->codec_id == CODEC_ID_DVD_SUBTITLE)
+ {
+ char *pos;
+
+ pos = strstr((char*)cc->extradata, "size:");
+ if( pos && sscanf( pos, "size: %dx%d",
+ &fmt.subs.spu.i_original_frame_width,
+ &fmt.subs.spu.i_original_frame_height ) == 2 )
+ {
+ msg_Dbg( p_demux, "original frame size: %dx%d",
+ fmt.subs.spu.i_original_frame_width,
+ fmt.subs.spu.i_original_frame_height );
+ }
+ else
+ {
+ msg_Warn( p_demux, "reading original frame size failed" );
+ }
+
+ pos = strstr((char*)cc->extradata, "palette:");
+ if( pos && sscanf( pos,
+ "palette: %x, %x, %x, %x, %x, %x, %x, %x, "
+ "%x, %x, %x, %x, %x, %x, %x, %x",
+ &fmt.subs.spu.palette[1],
+ &fmt.subs.spu.palette[2], &fmt.subs.spu.palette[3],
+ &fmt.subs.spu.palette[4], &fmt.subs.spu.palette[5],
+ &fmt.subs.spu.palette[6], &fmt.subs.spu.palette[7],
+ &fmt.subs.spu.palette[8], &fmt.subs.spu.palette[9],
+ &fmt.subs.spu.palette[10], &fmt.subs.spu.palette[11],
+ &fmt.subs.spu.palette[12], &fmt.subs.spu.palette[13],
+ &fmt.subs.spu.palette[14], &fmt.subs.spu.palette[15],
+ &fmt.subs.spu.palette[16] ) == 16 )
+ {
+ int j;
+ for( j = 1; j < 17; j++ )
+ {
+ uint8_t r = 0, g = 0, b = 0;
+ uint8_t y = 0, u = 0, v = 0;
+ r = (fmt.subs.spu.palette[j] >> 16) & 0xff;
+ g = (fmt.subs.spu.palette[j] >> 8) & 0xff;
+ b = (fmt.subs.spu.palette[j] >> 0) & 0xff;
+ y = (uint8_t) __MIN(abs(r * 2104 + g * 4130 + b * 802 + 4096 + 131072) >> 13, 235);
+ u = (uint8_t) __MIN(abs(r * -1214 + g * -2384 + b * 3598 + 4096 + 1048576) >> 13, 240);
+ v = (uint8_t) __MIN(abs(r * 3598 + g * -3013 + b * -585 + 4096 + 1048576) >> 13, 240);
+ fmt.subs.spu.palette[j] = 0;
+ fmt.subs.spu.palette[j] |= (y&0xff)<<16;
+ fmt.subs.spu.palette[j] |= (u&0xff);
+ fmt.subs.spu.palette[j] |= (v&0xff)<<8;
+
+ }
+ fmt.subs.spu.palette[0] = 0xBeef;
+ msg_Dbg( p_demux, "vobsub palette read" );
+ }
+ else
+ {
+ msg_Warn( p_demux, "reading original palette failed" );
+ }
+ }
+
psz_type = "subtitle";
break;
--
1.6.2.2
More information about the vlc-devel
mailing list