Fix conversion progress non-monotonicity

This commit is contained in:
Vanilagy
2025-09-07 22:36:53 +02:00
parent f3613b7260
commit cb9f4e0fdf
4 changed files with 18 additions and 10 deletions
+6 -6
View File
@@ -1,12 +1,12 @@
{ {
"name": "mediabunny", "name": "mediabunny",
"version": "1.14.1", "version": "1.14.2",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "mediabunny", "name": "mediabunny",
"version": "1.14.1", "version": "1.14.2",
"license": "MPL-2.0", "license": "MPL-2.0",
"workspaces": [ "workspaces": [
"packages/*" "packages/*"
@@ -7749,9 +7749,9 @@
} }
}, },
"node_modules/mediabunny": { "node_modules/mediabunny": {
"version": "1.14.0", "version": "1.14.1",
"resolved": "https://registry.npmjs.org/mediabunny/-/mediabunny-1.14.0.tgz", "resolved": "https://registry.npmjs.org/mediabunny/-/mediabunny-1.14.1.tgz",
"integrity": "sha512-GaULQgUWpz5m4S7N6iNjpyLxqhpudjcSNGLC4Ni9A0A2vA6l5frBpxQJZM2JmqrN1B2BkArnCgyuTZv7ePw2vQ==", "integrity": "sha512-TjLg8GQGGsnGePcA6i0NItGe9a5G8WaleCGaXpb5V5okwuK5KpNKfcmTZXItnjfPLo7FvfEZI0NFp1lIR8Os7Q==",
"license": "MPL-2.0", "license": "MPL-2.0",
"peer": true, "peer": true,
"workspaces": [ "workspaces": [
@@ -12242,7 +12242,7 @@
}, },
"packages/mp3-encoder": { "packages/mp3-encoder": {
"name": "@mediabunny/mp3-encoder", "name": "@mediabunny/mp3-encoder",
"version": "1.14.1", "version": "1.14.2",
"license": "MPL-2.0", "license": "MPL-2.0",
"devDependencies": { "devDependencies": {
"@types/emscripten": "^1.40.1" "@types/emscripten": "^1.40.1"
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "mediabunny", "name": "mediabunny",
"author": "Vanilagy", "author": "Vanilagy",
"version": "1.14.1", "version": "1.14.2",
"description": "Pure TypeScript media toolkit for reading, writing, and converting media files, directly in the browser.", "description": "Pure TypeScript media toolkit for reading, writing, and converting media files, directly in the browser.",
"type": "module", "type": "module",
"workspaces": [ "workspaces": [
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "@mediabunny/mp3-encoder", "name": "@mediabunny/mp3-encoder",
"author": "Vanilagy", "author": "Vanilagy",
"version": "1.14.1", "version": "1.14.2",
"description": "MP3 encoder extension for Mediabunny, based on LAME.", "description": "MP3 encoder extension for Mediabunny, based on LAME.",
"main": "./dist/bundles/mediabunny-mp3-encoder.mjs", "main": "./dist/bundles/mediabunny-mp3-encoder.mjs",
"module": "./dist/bundles/mediabunny-mp3-encoder.mjs", "module": "./dist/bundles/mediabunny-mp3-encoder.mjs",
+10 -2
View File
@@ -534,9 +534,14 @@ export class Conversion {
if (this.onProgress) { if (this.onProgress) {
this._computeProgress = true; this._computeProgress = true;
this._totalDuration = Math.min( this._totalDuration = Math.min(
await this.input.computeDuration() - this._startTimestamp, (await this.input.computeDuration()) - this._startTimestamp,
this._endTimestamp - this._startTimestamp, this._endTimestamp - this._startTimestamp,
); );
for (const track of this.utilizedTracks) {
this._maxTimestamps.set(track.id, 0);
}
this.onProgress?.(0); this.onProgress?.(0);
} }
@@ -1160,7 +1165,10 @@ export class Conversion {
} }
assert(this._totalDuration !== null); assert(this._totalDuration !== null);
this._maxTimestamps.set(trackId, Math.max(endTimestamp, this._maxTimestamps.get(trackId) ?? -Infinity)); this._maxTimestamps.set(
trackId,
Math.max(endTimestamp, this._maxTimestamps.get(trackId)!),
);
const minTimestamp = Math.min(...this._maxTimestamps.values()); const minTimestamp = Math.min(...this._maxTimestamps.values());
const newProgress = clamp(minTimestamp / this._totalDuration, 0, 1); const newProgress = clamp(minTimestamp / this._totalDuration, 0, 1);