diff --git a/dev/convert.html b/dev/convert.html index 658b6b4..d204380 100644 --- a/dev/convert.html +++ b/dev/convert.html @@ -104,6 +104,8 @@ }, */ video: () => ({ + //width: 640, + //rotate: 90, //forceTranscode: true, //forceTranscode: true, //width: 1280, @@ -189,7 +191,7 @@ }, trim: { //start: 0, - end: 10 + end: 2 }, }); console.log(conversion); diff --git a/src/conversion.ts b/src/conversion.ts index a6dccfe..f93ed10 100644 --- a/src/conversion.ts +++ b/src/conversion.ts @@ -1086,6 +1086,8 @@ export class Conversion { } if (needsRerender) { + outputTrackRotation = 0; // Since the rotation is baked into the output + this._trackPromises.push((async () => { await this._started; @@ -1101,8 +1103,6 @@ export class Conversion { const iterator = sink.canvases(this._startTimestamp, this._endTimestamp); const frameRate = trackOptions.frameRate; - outputTrackRotation = 0; // Since the rotation is baked into the output - let lastCanvas: HTMLCanvasElement | OffscreenCanvas | null = null; let lastCanvasTimestamp: number | null = null; let lastCanvasEndTimestamp: number | null = null; diff --git a/test/browser/conversion.test.ts b/test/browser/conversion.test.ts new file mode 100644 index 0000000..da0cbfb --- /dev/null +++ b/test/browser/conversion.test.ts @@ -0,0 +1,49 @@ +import { ALL_FORMATS } from '../../src/input-format.js'; +import { Input } from '../../src/input.js'; +import { Mp4OutputFormat } from '../../src/output-format.js'; +import { Output } from '../../src/output.js'; +import { BufferSource, UrlSource } from '../../src/source.js'; +import { expect, test } from 'vitest'; +import { BufferTarget } from '../../src/target.js'; +import { Conversion } from '../../src/conversion.js'; +import { assert } from '../../src/misc.js'; + +test('Rotation is baked-in when rerendering', async () => { + using input = new Input({ + source: new UrlSource('/rotate-buck-bunny.mp4'), + formats: ALL_FORMATS, + }); + + const ogTrack = await input.getPrimaryVideoTrack(); + assert(ogTrack); + + expect(ogTrack.rotation).toBe(90); + expect(ogTrack.codedWidth).toBe(1920); + expect(ogTrack.codedHeight).toBe(1080); + expect(ogTrack.displayWidth).toBe(1080); + expect(ogTrack.displayHeight).toBe(1920); + + const output = new Output({ + format: new Mp4OutputFormat(), + target: new BufferTarget(), + }); + + const conversion = await Conversion.init({ input, output, video: { + width: 320, + } }); + await conversion.execute(); + + using newInput = new Input({ + source: new BufferSource(output.target.buffer!), + formats: ALL_FORMATS, + }); + + const track = await newInput.getPrimaryVideoTrack(); + assert(track); + + expect(track.codedWidth).toBe(320); + expect(track.codedHeight).toBe(570); + expect(track.displayWidth).toBe(320); + expect(track.displayHeight).toBe(570); + expect(track.rotation).toBe(0); +}); diff --git a/test/public/rotate-buck-bunny.mp4 b/test/public/rotate-buck-bunny.mp4 new file mode 100644 index 0000000..4903e7a Binary files /dev/null and b/test/public/rotate-buck-bunny.mp4 differ diff --git a/tsconfig.vitest.json b/tsconfig.vitest.json index b2de3f3..129fafc 100644 --- a/tsconfig.vitest.json +++ b/tsconfig.vitest.json @@ -6,7 +6,7 @@ "composite": true, "noEmit": false, "paths": { - "mediabunny": ["./src/index.ts"], + //"mediabunny": ["./src/index.ts"], So that the direct source imports are preferred "@mediabunny/ac3": ["./packages/ac3/src/index.ts"], "@mediabunny/aac-encoder": ["./packages/aac-encoder/src/index.ts"], "@mediabunny/flac-encoder": ["./packages/flac-encoder/src/index.ts"],