@@ -44,6 +44,20 @@ void ff_text_init_avio(void *s, FFTextReader *r, AVIOContext *pb)
r->buf_pos += 3;
}
}
+ if (r->type != FF_UTF_8) {
+ // Check for double BOM in UTF-16 LE/BE files
+ for (i = 0; i < 2; i++)
+ r->buf[r->buf_len++] = avio_r8(r->pb);
+ if (strncmp("\xFF\xFE\xFF\xFE", r->buf, 4) == 0 ||
+ strncmp("\xFE\xFF\xFE\xFF", r->buf, 4) == 0) {
+ // We did find a second BOM, so move buf_pos two bytes ahead
+ r->buf_pos += 2;
+ } else {
+ // We did not find a second BOM, undo the seek
+ r->buf_len -= 2;
+ avio_seek(r->pb, -2, SEEK_CUR); // Seek back two bytes
+ }
+ }
if (s && (r->type == FF_UTF16LE || r->type == FF_UTF16BE))
av_log(s, AV_LOG_INFO,
"UTF16 is automatically converted to UTF8, do not specify a character encoding\n");