Allow reading matroska files with "mp4" ext

Related to #9010
This commit is contained in:
Nikolaj Olsson 2024-11-17 21:13:58 +01:00
parent 4a8c0be28a
commit 1cf4ccd05b
2 changed files with 18 additions and 1 deletions

View File

@ -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;
}
}
/// <summary> /// <summary>
/// Checks if a file is locked by attempting to open it with exclusive read access. /// Checks if a file is locked by attempting to open it with exclusive read access.
/// </summary> /// </summary>

View File

@ -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); ImportSubtitleFromMatroskaFile(fileName);
return; return;