Skip to content

Commit

Permalink
fix closestFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
fadri1 committed Jan 10, 2024
1 parent 1f803cd commit 5bd35ff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions framefusion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@ export interface Extractor {
//
// Example:
//
// const TEST_VIDEO = './samples/bbb10m.mp4';
// export const run = async() => {
// // Arrange
// const extractor = await BeamcoderExtractor.create({
// inputFileOrUrl: TEST_VIDEO,
// });
//
// const frame = await extractor.getImageDataAtTime(0.3);
// console.log(frame);
// extractor.dispose();
// };
//
// run();
//
const TEST_VIDEO = './samples/tmp.mp4';
export const run = async() => {
// Arrange
const extractor = await BeamcoderExtractor.create({
inputFileOrUrl: TEST_VIDEO,
});

const frame = await extractor.getImageDataAtTime(230.63333333333335);
console.log(frame);
extractor.dispose();
};

run();


export { BeamcoderExtractor };
2 changes: 1 addition & 1 deletion src/backends/beamcoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ export class BeamcoderExtractor extends BaseExtractor implements Extractor {

// The packet contains frames, but all of them have PTS larger than our a targetPTS (we looked too far)
if (!closestFrame) {
return outputFrame;
return outputFrame || (filteredFrames.reduce((nearest, current) => (Math.abs(current.pts - targetPTS) < Math.abs(nearest.pts - targetPTS) ? current : nearest), filteredFrames[0]) ?? null);
}

// store the filtered packet frames for later reuse
Expand Down

0 comments on commit 5bd35ff

Please sign in to comment.