diff options
author | jstebbins <[email protected]> | 2011-09-24 18:42:05 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2011-09-24 18:42:05 +0000 |
commit | fe0b9bb16dec420d447a4520cf1f001e99a92021 (patch) | |
tree | 2a50956735ae4941d628f84eb76f40a989019467 | |
parent | 083d7487b2ec5a59b3c0a3d6f350d2018e1b0ace (diff) |
Fix parsing of SSA layer field
SSA subtitles have an empty layer field (bare ','). The
scanf format specifier "%*128[^,]" will not match on a
bare ','. There must be at least one non ',' character in
the match. So the format specifier is placed directly next
to the 'Dialogue:' string so that the next expected ' '
after the ':' will be the character it matches on when
there is no layer field.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4244 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r-- | libhb/decssasub.c | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/libhb/decssasub.c b/libhb/decssasub.c index 2d2ec3d2b..9e1c36b47 100644 --- a/libhb/decssasub.c +++ b/libhb/decssasub.c @@ -217,7 +217,13 @@ static int parse_timing_from_ssa_packet( char *in_data, int64_t *in_start, int64 */ int start_hr, start_min, start_sec, start_centi; int end_hr, end_min, end_sec, end_centi; - int numPartsRead = sscanf( (char *) in_data, "Dialogue: %*128[^,]," + // SSA subtitles have an empty layer field (bare ','). The scanf + // format specifier "%*128[^,]" will not match on a bare ','. There + // must be at least one non ',' character in the match. So the format + // specifier is placed directly next to the ':' so that the next + // expected ' ' after the ':' will be the character it matches on + // when there is no layer field. + int numPartsRead = sscanf( (char *) in_data, "Dialogue:%*128[^,]," "%d:%d:%d.%d," // Start "%d:%d:%d.%d,", // End &start_hr, &start_min, &start_sec, &start_centi, @@ -367,7 +373,13 @@ static hb_buffer_t * ssa_to_mkv_ssa( hb_work_object_t * w, hb_buffer_t * in ) // Convert the SSA line to MKV-SSA format char *layerField = malloc( len ); - int numPartsRead = sscanf( curLine, "Dialogue: %128[^,],", layerField ); + // SSA subtitles have an empty layer field (bare ','). The scanf + // format specifier "%*128[^,]" will not match on a bare ','. There + // must be at least one non ',' character in the match. So the format + // specifier is placed directly next to the ':' so that the next + // expected ' ' after the ':' will be the character it matches on + // when there is no layer field. + int numPartsRead = sscanf( curLine, "Dialogue:%128[^,],", layerField ); if ( numPartsRead != 1 ) { free( layerField ); @@ -387,8 +399,13 @@ static hb_buffer_t * ssa_to_mkv_ssa( hb_work_object_t * w, hb_buffer_t * in ) out->start = in_start; out->stop = in_stop; + // The sscanf conversion above will result in an extra space + // before the layerField. Strip the space. + char *stripLayerField = layerField; + for(; *stripLayerField == ' '; stripLayerField++); + sprintf( mkvOut, "%d,%s,%s", - pv->readOrder++, layerField, styleToTextFields ); + pv->readOrder++, stripLayerField, styleToTextFields ); free( layerField ); @@ -438,7 +455,13 @@ static hb_buffer_t *ssa_decode_line_to_picture( hb_work_object_t * w, uint8_t *i int mkvInSize; { char *layerField = malloc( in_size ); - int numPartsRead = sscanf( (char *) in_data, "Dialogue: %128[^,],", layerField ); + // SSA subtitles have an empty layer field (bare ','). The scanf + // format specifier "%*128[^,]" will not match on a bare ','. There + // must be at least one non ',' character in the match. So the format + // specifier is placed directly next to the ':' so that the next + // expected ' ' after the ':' will be the character it matches on + // when there is no layer field. + int numPartsRead = sscanf( (char *) in_data, "Dialogue:%128[^,],", layerField ); if ( numPartsRead != 1 ) goto fail; @@ -448,11 +471,16 @@ static hb_buffer_t *ssa_decode_line_to_picture( hb_work_object_t * w, uint8_t *i goto fail; } + // The sscanf conversion above will result in an extra space + // before the layerField. Strip the space. + char *stripLayerField = layerField; + for(; *stripLayerField == ' '; stripLayerField++); + mkvIn = malloc( in_size + 1 ); mkvIn[0] = '\0'; sprintf(mkvIn, "%d", pv->readOrder++); // ReadOrder: make this up strcat( mkvIn, "," ); - strcat( mkvIn, layerField ); + strcat( mkvIn, stripLayerField ); strcat( mkvIn, "," ); strcat( mkvIn, (char *) styleToTextFields ); |