mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-02 21:33:52 +02:00
Add support for LanguageBCP47
This commit is contained in:
@@ -88,6 +88,7 @@ export enum EBMLId {
|
|||||||
FlagLacing = 0x9c,
|
FlagLacing = 0x9c,
|
||||||
Name = 0x536e,
|
Name = 0x536e,
|
||||||
Language = 0x22b59c,
|
Language = 0x22b59c,
|
||||||
|
LanguageBCP47 = 0x22b59d,
|
||||||
CodecID = 0x86,
|
CodecID = 0x86,
|
||||||
CodecPrivate = 0x63a2,
|
CodecPrivate = 0x63a2,
|
||||||
CodecDelay = 0x56aa,
|
CodecDelay = 0x56aa,
|
||||||
|
|||||||
@@ -1014,6 +1014,7 @@ export class MatroskaDemuxer extends Demuxer {
|
|||||||
|
|
||||||
case EBMLId.Language: {
|
case EBMLId.Language: {
|
||||||
if (!this.currentTrack) break;
|
if (!this.currentTrack) break;
|
||||||
|
if (this.currentTrack.languageCode) break; // LanguageBCP47 was present, which takes precedence
|
||||||
|
|
||||||
this.currentTrack.languageCode = reader.readAsciiString(size);
|
this.currentTrack.languageCode = reader.readAsciiString(size);
|
||||||
|
|
||||||
@@ -1022,6 +1023,23 @@ export class MatroskaDemuxer extends Demuxer {
|
|||||||
}
|
}
|
||||||
}; break;
|
}; 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: {
|
case EBMLId.Video: {
|
||||||
if (this.currentTrack?.info?.type !== 'video') break;
|
if (this.currentTrack?.info?.type !== 'video') break;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user