diff options
author | wm4 <wm4@nowhere> | 2016-01-12 23:50:01 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2016-01-12 23:50:01 +0100 |
commit | a4cdf1a727a3d9d59ba200c944a7eb74806c752c (patch) | |
tree | a06dde6a56a0f1a22048aa4d7228f0d09cbe0f79 /demux | |
parent | e420464ba693a5920d4dc172b3f7e9a0c725e3d4 (diff) | |
download | mpv-a4cdf1a727a3d9d59ba200c944a7eb74806c752c.tar.bz2 mpv-a4cdf1a727a3d9d59ba200c944a7eb74806c752c.tar.xz |
demux_lavf: fix charset conversion with UTF-16 subtitles
UTF-16 subtitles are special in that they are usually read by
libavformat directly, even though they are not in UTF-8. This is
explicitly handled convert_charset() and skips conversion to UTF-8.
There was a bug due to not resetting the file position: if conversion
happens, the actual stream is replaced with a memory stream containing
the converted data, but if conversion is skipped, the original stream
with the wrong file position is kept.
Fix by always opening a memory stream. (We _could_ seek back, but there
is a slight possibility of additional failure due to unseekable
streams.)
Also, don't enter conversion if the subtitle is detected as UTF-8
either.
Fixes #2700.
Diffstat (limited to 'demux')
-rw-r--r-- | demux/demux_lavf.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c index 712b208460..e054d29bbd 100644 --- a/demux/demux_lavf.c +++ b/demux/demux_lavf.c @@ -275,18 +275,19 @@ static void convert_charset(struct demuxer *demuxer) MP_WARN(demuxer, "File too big (or error reading) - skip charset probing.\n"); return; } + void *alloc = data.start; cp = (char *)mp_charset_guess(priv, demuxer->log, data, cp, 0); if (cp && !mp_charset_is_utf8(cp)) MP_INFO(demuxer, "Using subtitle charset: %s\n", cp); // libavformat transparently converts UTF-16 to UTF-8 - if (!mp_charset_is_utf16(cp)) { + if (!mp_charset_is_utf16(cp) && !mp_charset_is_utf8(cp)) { bstr conv = mp_iconv_to_utf8(demuxer->log, data, cp, MP_ICONV_VERBOSE); if (conv.start) - priv->stream = open_memory_stream(conv.start, conv.len); - if (conv.start != data.start) - talloc_free(conv.start); + data = conv; } - talloc_free(data.start); + if (data.start) + priv->stream = open_memory_stream(data.start, data.len); + talloc_free(alloc); } static char *remove_prefix(char *s, const char *const *prefixes) |