Commit a1fbc870 authored by John Stebbins's avatar John Stebbins Committed by Laurent Aimar

vobsub idx parsing in matroska tracks

 Added capability to avformat and mkv demuxers to extract the
original_frame_width, original_frame_height and palette from their tracks
private data.
 Vobsubs in mkv were only using default values for these items.
Signed-off-by: default avatarLaurent Aimar <fenrir@videolan.org>
parent b6b78047
......@@ -47,6 +47,7 @@
#include "../../codec/avcodec/avcodec.h"
#include "avformat.h"
#include "../vobsub.h"
//#define AVFORMAT_DEBUG 1
......@@ -271,6 +272,48 @@ 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 &&
cc->extradata != NULL &&
cc->extradata_size > 0 )
{
char *psz_start;
char *psz_buf = malloc( cc->extradata_size + 1);
if( psz_buf != NULL )
{
memcpy( psz_buf, cc->extradata , cc->extradata_size );
psz_buf[cc->extradata_size] = '\0';
psz_start = strstr( psz_buf, "size:" );
if( psz_start &&
vobsub_size_parse( psz_start,
&fmt.subs.spu.i_original_frame_width,
&fmt.subs.spu.i_original_frame_height ) == VLC_SUCCESS )
{
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" );
}
psz_start = strstr( psz_buf, "palette:" );
if( psz_start &&
vobsub_palette_parse( psz_start, &fmt.subs.spu.palette[1] ) == VLC_SUCCESS )
{
fmt.subs.spu.palette[0] = 0xBeef;
msg_Dbg( p_demux, "vobsub palette read" );
}
else
{
msg_Warn( p_demux, "reading original palette failed" );
}
free( psz_buf );
}
}
psz_type = "subtitle";
break;
......
......@@ -28,6 +28,10 @@
#include "demux.hpp"
extern "C" {
#include "../vobsub.h"
}
/* GetFourCC helper */
#define GetFOURCC( p ) __GetFOURCC( (uint8_t*)p )
static vlc_fourcc_t __GetFOURCC( uint8_t *p )
......@@ -1095,22 +1099,41 @@ bool matroska_segment_c::Select( mtime_t i_start_time )
tracks[i_track]->fmt.i_codec = VLC_CODEC_SPU;
if( tracks[i_track]->i_extra_data )
{
char *p_start;
char *p_buf = (char *)malloc( tracks[i_track]->i_extra_data + 1);
memcpy( p_buf, tracks[i_track]->p_extra_data , tracks[i_track]->i_extra_data );
p_buf[tracks[i_track]->i_extra_data] = '\0';
char *psz_start;
char *psz_buf = (char *)malloc( tracks[i_track]->i_extra_data + 1);
if( psz_buf != NULL )
{
memcpy( psz_buf, tracks[i_track]->p_extra_data , tracks[i_track]->i_extra_data );
psz_buf[tracks[i_track]->i_extra_data] = '\0';
p_start = strstr( p_buf, "size:" );
if( sscanf( p_start, "size: %dx%d",
&tracks[i_track]->fmt.subs.spu.i_original_frame_width, &tracks[i_track]->fmt.subs.spu.i_original_frame_height ) == 2 )
psz_start = strstr( psz_buf, "size:" );
if( psz_start &&
vobsub_size_parse( psz_start,
&tracks[i_track]->fmt.subs.spu.i_original_frame_width,
&tracks[i_track]->fmt.subs.spu.i_original_frame_height ) == VLC_SUCCESS )
{
msg_Dbg( &sys.demuxer, "original frame size vobsubs: %dx%d", tracks[i_track]->fmt.subs.spu.i_original_frame_width, tracks[i_track]->fmt.subs.spu.i_original_frame_height );
msg_Dbg( &sys.demuxer, "original frame size vobsubs: %dx%d",
tracks[i_track]->fmt.subs.spu.i_original_frame_width,
tracks[i_track]->fmt.subs.spu.i_original_frame_height );
}
else
{
msg_Warn( &sys.demuxer, "reading original frame size for vobsub failed" );
}
free( p_buf );
psz_start = strstr( psz_buf, "palette:" );
if( psz_start &&
vobsub_palette_parse( psz_start, &tracks[i_track]->fmt.subs.spu.palette[1] ) == VLC_SUCCESS )
{
tracks[i_track]->fmt.subs.spu.palette[0] = 0xBeef;
msg_Dbg( &sys.demuxer, "vobsub palette read" );
}
else
{
msg_Warn( &sys.demuxer, "reading original palette failed" );
}
free( psz_buf );
}
}
}
else if( !strcmp( tracks[i_track]->psz_codec, "B_VOBBTN" ) )
......
......@@ -40,6 +40,7 @@
#include <vlc_charset.h>
#include "ps.h"
#include "vobsub.h"
#define MAX_LINE 8192
......@@ -488,8 +489,8 @@ static int ParseVobSubIDX( demux_t *p_demux )
else if( !strncmp( "size:", line, 5 ) )
{
/* Store the original size of the video */
if( sscanf( line, "size: %dx%d",
&p_sys->i_original_frame_width, &p_sys->i_original_frame_height ) == 2 )
if( vobsub_size_parse( line, &p_sys->i_original_frame_width,
&p_sys->i_original_frame_height ) == VLC_SUCCESS )
{
msg_Dbg( p_demux, "original frame size: %dx%d", p_sys->i_original_frame_width, p_sys->i_original_frame_height );
}
......@@ -500,33 +501,8 @@ static int ParseVobSubIDX( demux_t *p_demux )
}
else if( !strncmp( "palette:", line, 8 ) )
{
int i;
/* Store the palette of the subs */
if( sscanf( line, "palette: %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x",
&p_sys->palette[0], &p_sys->palette[1], &p_sys->palette[2], &p_sys->palette[3],
&p_sys->palette[4], &p_sys->palette[5], &p_sys->palette[6], &p_sys->palette[7],
&p_sys->palette[8], &p_sys->palette[9], &p_sys->palette[10], &p_sys->palette[11],
&p_sys->palette[12], &p_sys->palette[13], &p_sys->palette[14], &p_sys->palette[15] ) == 16 )
{
for( i = 0; i < 16; i++ )
{
uint8_t r = 0, g = 0, b = 0;
uint8_t y = 0, u = 0, v = 0;
r = (p_sys->palette[i] >> 16) & 0xff;
g = (p_sys->palette[i] >> 8) & 0xff;
b = (p_sys->palette[i] >> 0) & 0xff;
/* msg_Dbg( p_demux, "palette %d: R=%x, G=%x, B=%x", i, r, g, b ); */
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);
p_sys->palette[i] = 0;
p_sys->palette[i] |= (y&0xff)<<16;
p_sys->palette[i] |= (u&0xff);
p_sys->palette[i] |= (v&0xff)<<8;
/* msg_Dbg( p_demux, "palette %d: y=%x, u=%x, v=%x", i, y, u, v ); */
}
if( vobsub_palette_parse( line, p_sys->palette ) == VLC_SUCCESS )
{
p_sys->b_palette = true;
msg_Dbg( p_demux, "vobsub palette read" );
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment