From a3e13339d4479c33d5e221e6b6d4dd8ab60e6504 Mon Sep 17 00:00:00 2001 From: jstebbins Date: Tue, 1 Jun 2010 23:02:41 +0000 Subject: [PATCH] handle the utf8 byte order mark when present at the beginning of srt subs it was tripping us up and causing the loss of the first subtitle git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3344 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- libhb/decsrtsub.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libhb/decsrtsub.c b/libhb/decsrtsub.c index 7f1602b74..daf210d6f 100644 --- a/libhb/decsrtsub.c +++ b/libhb/decsrtsub.c @@ -42,6 +42,7 @@ struct hb_work_private_s char utf8_buf[2048]; int utf8_pos; int utf8_end; + int utf8_bom_skipped; unsigned long current_time; unsigned long number_of_entries; unsigned long last_entry_number; @@ -117,6 +118,16 @@ static int utf8_fill( hb_work_private_t * pv ) pv->utf8_end = q - pv->utf8_buf; pv->pos = p - pv->buf; + if ( !pv->utf8_bom_skipped ) + { + uint8_t *buf = (uint8_t*)pv->utf8_buf; + if (buf[0] == 0xef && buf[1] == 0xbb && buf[2] == 0xbf) + { + pv->utf8_pos = 3; + } + pv->utf8_bom_skipped = 1; + } + if( ( retval == -1 ) && ( errno == EINVAL ) ) { /* Incomplete multibyte sequence, read more data */ @@ -461,8 +472,6 @@ static int decsrtInit( hb_work_object_t * w, hb_job_t * job ) buffer = hb_buffer_init( 0 ); hb_fifo_push( w->fifo_in, buffer); - pv->file = fopen( w->subtitle->config.src_filename, "r" ); - pv->current_state = k_state_potential_new_entry; pv->number_of_entries = 0; pv->last_entry_number = 0; -- 2.40.0