feat: Add support for custom MP4 metadata with mdta format (#132)

* feat: Add support for custom MP4 metadata with mdta format

- Add metadataFormat option ('mdir' | 'mdta') to IsobmffOutputFormatOptions
- Implement complete mdta format with keys box generation
- Enable custom metadata fields readable by ffmpeg/ffprobe
- Maintain backward compatibility with default mdir format

* Refactor ISOBMFF metadata tag writing logic

* Autism

---------

Co-authored-by: tanfu <[email protected]>
Co-authored-by: Vanilagy <[email protected]>
This commit is contained in:
DragonZ
2025-09-18 23:41:08 +02:00
committed by GitHub
co-authored by tanfu Vanilagy
parent d426d36386
commit 420423bc0f
7 changed files with 141 additions and 65 deletions
+20
View File
@@ -140,6 +140,18 @@ export type IsobmffOutputFormatOptions = {
*/
minimumFragmentDuration?: number;
/**
* The metadata format to use for writing metadata tags.
*
* - `'auto'` (default): Behaves like `'mdir'` for MP4 and like `'udta'` for QuickTime, matching FFmpeg's default
* behavior.
* - `'mdir'`: Write tags into `moov/udta/meta` using the 'mdir' handler format.
* - `'mdta'`: Write tags into `moov/udta/meta` using the 'mdta' handler format, equivalent to FFmpeg's
* `use_metadata_tags` flag. This allows for custom keys of arbitrary length.
* - `'udta'`: Write tags directly into `moov/udta`.
*/
metadataFormat?: 'auto' | 'mdir' | 'mdta' | 'udta';
/**
* Will be called once the ftyp (File Type) box of the output file has been written.
*
@@ -216,6 +228,14 @@ export abstract class IsobmffOutputFormat extends OutputFormat {
if (options.onMoof !== undefined && typeof options.onMoof !== 'function') {
throw new TypeError('options.onMoof, when provided, must be a function.');
}
if (
options.metadataFormat !== undefined
&& !['mdir', 'mdta', 'udta', 'auto'].includes(options.metadataFormat)
) {
throw new TypeError(
'options.metadataFormat, when provided, must be either \'auto\', \'mdir\', \'mdta\', or \'udta\'.',
);
}
super();