diff --git a/src/libse/Common/FileUtil.cs b/src/libse/Common/FileUtil.cs index 2ac9056e1..6565a7ebe 100644 --- a/src/libse/Common/FileUtil.cs +++ b/src/libse/Common/FileUtil.cs @@ -859,6 +859,18 @@ namespace Nikse.SubtitleEdit.Core.Common } } + public static bool IsMatroskaFileFast(string fileName) + { + using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + var buffer = new byte[4]; + fs.Read(buffer, 0, buffer.Length); + + // 1a 45 df a3 + return buffer[0] == 0x1a && buffer[1] == 0x45 && buffer[2] == 0xdf && buffer[3] == 0xa3; + } + } + /// /// Checks if a file is locked by attempting to open it with exclusive read access. /// diff --git a/src/ui/Forms/Main.cs b/src/ui/Forms/Main.cs index e0e1f01f4..7bd115b15 100644 --- a/src/ui/Forms/Main.cs +++ b/src/ui/Forms/Main.cs @@ -2952,7 +2952,12 @@ namespace Nikse.SubtitleEdit.Forms } } - if (ext == ".mkv" || ext == ".mks") + if (ext == ".mkv" || ext == ".mks" || + + // allow for mkv files with wrong extension + ((ext == ".mp4" || ext == ".mov" || ext == ".m4v" || ext == ".wmv") && FileUtil.IsMatroskaFileFast(fileName) && FileUtil.IsMatroskaFile(fileName)) + + ) { ImportSubtitleFromMatroskaFile(fileName); return;