Add configurable minimum MP4 fragment duration and Matroska cluster duration

This commit is contained in:
Vanilagy
2025-03-22 15:33:00 +01:00
parent 1652b4f614
commit b14daf6dca
6 changed files with 38 additions and 22 deletions
+4 -1
View File
@@ -118,6 +118,7 @@ export class IsobmffMuxer extends Muxer {
private nextFragmentNumber = 1;
// Only relevant for fragmented files, to make sure new fragments start with the highest timestamp seen so far
private maxWrittenTimestamp = -Infinity;
private minimumFragmentDuration: number;
constructor(output: Output, format: IsobmffOutputFormat) {
super(output);
@@ -136,6 +137,8 @@ export class IsobmffMuxer extends Muxer {
if (this.fastStart === 'in-memory' || this.isFragmented) {
this.writer.ensureMonotonicity = true;
}
this.minimumFragmentDuration = format._options.minimumFragmentDuration ?? 1;
}
async start() {
@@ -683,7 +686,7 @@ export class IsobmffMuxer extends Muxer {
});
if (
currentChunkDuration >= 1.0
currentChunkDuration >= this.minimumFragmentDuration
&& keyFrameQueuedEverywhere
&& sample.timestamp > this.maxWrittenTimestamp
) {