diff --git a/package.json b/package.json index e721689..8cdae87 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lumen5/framefusion", - "version": "0.0.21", + "version": "0.0.22", "type": "module", "scripts": { "docs": "typedoc framefusion.ts", diff --git a/src/backends/beamcoder.ts b/src/backends/beamcoder.ts index 6fcf671..26f1511 100644 --- a/src/backends/beamcoder.ts +++ b/src/backends/beamcoder.ts @@ -338,6 +338,7 @@ export class BeamcoderExtractor extends BaseExtractor implements Extractor { if ((nextFrame && nextFrame.pts > targetPTS) || (closestFramePTS === targetPTS)) { // We have a next frame, so we know the frame being displayed at targetPTS is the previous one, // which corresponds to outputFrame. + this.#previousTargetPTS = targetPTS; return outputFrame; } } @@ -380,6 +381,7 @@ export class BeamcoderExtractor extends BaseExtractor implements Extractor { VERBOSE && console.log('closestFramePTS', closestFramePTS, 'targetPTS', targetPTS); if (!outputFrame || closestFramePTS <= targetPTS) { VERBOSE && console.log('assigning outputFrame', closestFrame?.pts); + this.#previousTargetPTS = targetPTS; outputFrame = closestFrame; } else { diff --git a/test/framefusion.test.ts b/test/framefusion.test.ts index a7c8ea0..fb8d2de 100644 --- a/test/framefusion.test.ts +++ b/test/framefusion.test.ts @@ -235,6 +235,18 @@ describe('FrameFusion', () => { await extractor.dispose(); }); + it('can get frames when looping', async() => { + const extractor = await BeamcoderExtractor.create({ + inputFileOrUrl: 'https://media-share.lumen5.com/proxy-url/?url=https%3A%2F%2Fmedia.tenor.com%2F37odVJNnxHEAAAPo%2Fdominos-dominos-pizza.mp4', + }); + + const times = [0.012667, 1.212667, 1.246, 0.012666]; + for (let i = 0; i < times.length; i++) { + const frame = await extractor.getFrameAtTime(times[i]); + expect(Math.floor(extractor.ptsToTime(frame.pts))).to.equal(Math.floor(times[i])); + } + }); + it('can get the first 10 frames', async() => { // Arrange const extractor = await BeamcoderExtractor.create({