Skip to content

Commit

Permalink
Merge pull request #37 from Lumen5/improve-perf
Browse files Browse the repository at this point in the history
Improve performance
  • Loading branch information
antoineMoPa authored May 12, 2023
2 parents e23da4a + 35e2c4b commit a2a4d92
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lumen5/framefusion",
"version": "0.0.19",
"version": "0.0.20",
"type": "module",
"scripts": {
"docs": "typedoc framefusion.ts",
Expand Down
13 changes: 12 additions & 1 deletion src/backends/beamcoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,23 @@ export class BeamcoderExtractor extends BaseExtractor implements Extractor {
if (this.#filteredFramesPacket.length > 0) {
const closestFrame = this.#filteredFramesPacket
.flat()
.find(f => (f as Frame).pts <= targetPTS);
.find(f => (f as Frame).pts <= targetPTS) as Frame;

if (closestFrame) {
const nextFrame = this.#filteredFramesPacket
.flat()
.find(f => (f as Frame).pts > closestFrame.pts) as Frame;

VERBOSE && console.log('returning previously filtered frame with pts', (closestFrame as Frame).pts);
closestFramePTS = (closestFrame as Frame).pts;
outputFrame = closestFrame;
this.#previousTargetPTS = targetPTS;

if (nextFrame && nextFrame.pts > targetPTS) {
// We have a next frame, so we know the frame being displayed at targetPTS is the previous one,
// which corresponds to outputFrame.
return outputFrame;
}
}
}

Expand Down

0 comments on commit a2a4d92

Please sign in to comment.