Add support for LanguageBCP47

This commit is contained in:
Vanilagy
2025-08-23 15:58:58 +02:00
parent bb1b20afa7
commit e6420caea4
2 changed files with 19 additions and 0 deletions
+1
View File
@@ -88,6 +88,7 @@ export enum EBMLId {
FlagLacing = 0x9c,
Name = 0x536e,
Language = 0x22b59c,
LanguageBCP47 = 0x22b59d,
CodecID = 0x86,
CodecPrivate = 0x63a2,
CodecDelay = 0x56aa,
+18
View File
@@ -1014,6 +1014,7 @@ export class MatroskaDemuxer extends Demuxer {
case EBMLId.Language: {
if (!this.currentTrack) break;
if (this.currentTrack.languageCode) break; // LanguageBCP47 was present, which takes precedence
this.currentTrack.languageCode = reader.readAsciiString(size);
@@ -1022,6 +1023,23 @@ export class MatroskaDemuxer extends Demuxer {
}
}; break;
case EBMLId.LanguageBCP47: {
if (!this.currentTrack) break;
const bcp47 = reader.readAsciiString(size);
const languageSubtag = bcp47.split('-')[0];
if (languageSubtag) {
// Technically invalid, for now: The language subtag might be a language code from ISO 639-1,
// ISO 639-2, ISO 639-3, ISO 639-5 or some other thing (source: Wikipedia). But, `languageCode` is
// documented as ISO 639-2. Changing the definition would be a breaking change. This will get
// cleaned up in the future by defining languageCode to be BCP 47 instead.
this.currentTrack.languageCode = languageSubtag;
} else {
this.currentTrack.languageCode = UNDETERMINED_LANGUAGE;
}
}; break;
case EBMLId.Video: {
if (this.currentTrack?.info?.type !== 'video') break;