From bb5090ac3a9e32b051ee4a703a6bc849930f1983 Mon Sep 17 00:00:00 2001 From: wangqr Date: Sun, 16 Jun 2019 19:14:10 -0400 Subject: [PATCH] Detect EBML magic number to skip encoding detection for MKV MKV loads slow after f733297499f72ea11c166f6be23751a7b002c51c --- libaegisub/common/charset.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libaegisub/common/charset.cpp b/libaegisub/common/charset.cpp index 1addb90ee..406cbfbd2 100644 --- a/libaegisub/common/charset.cpp +++ b/libaegisub/common/charset.cpp @@ -34,6 +34,15 @@ std::string Detect(agi::fs::path const& file) { if (fp.size() > 100 * 1024 * 1024) return "binary"; + + // FIXME: Dirty hack for Matroska. These 4 bytes are the magic + // number of EBML which is used by mkv and webm + if (fp.size() >= 4) { + const char* buf = fp.read(0, 4); + if (!strncmp(buf, "\x1a\x45\xdf\xa3", 4)) + return "binary"; + } + uint64_t binaryish = 0; #ifdef WITH_UCHARDET