-
Notifications
You must be signed in to change notification settings - Fork 1
/
framefusion.ts
73 lines (60 loc) · 1.77 KB
/
framefusion.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import type { ImageData } from './src/types';
import { BeamcoderExtractor } from './src/backends/beamcoder.js';
export type Frame = {
pts: number;
data: Array<Buffer>;
width: number;
height: number;
};
export type InterpolateMode = 'fast' | 'high-quality';
export type ExtractorArgs = {
inputFileOrUrl?: string;
outputFile?: string;
threadCount?: number;
endTime?: number;
interpolateFps?: number;
interpolateMode?: InterpolateMode;
// ffmpeg: https://ffmpeg.org/doxygen/trunk/pixfmt_8h.html#a9a8e335cf3be472042bc9f0cf80cd4c5
// gstreamer: https://gstreamer.freedesktop.org/documentation/video/video-format.html?gi-language=c#GstVideoFormat
};
export interface Extractor {
// There is also a static "create" method, but typescript does not like it.
// create(args: ExtractorArgs): Promise<Extractor>;
init(_args: ExtractorArgs): Promise<void>;
get duration(): number;
get width(): number;
get height(): number;
getFrameAtTime(targetTime: number): Promise<Frame>;
getImageDataAtTime(targetTime: number): Promise<ImageData>;
dispose(): Promise<void>;
}
//
// - Debugging -
//
// It can be useful to test code directly here and run it with:
//
// yarn run dev
//
// Or, with chrome/vs code debugging:
//
// yarn run debug
//
// And then visit chrome:///inspect, you should see an entry for this script.
//
// 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();
//
export { BeamcoderExtractor };