@open-motion/encoder 0.0.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ export interface EncodeOptions {
2
+ framesDir: string;
3
+ fps: number;
4
+ outputFile: string;
5
+ audioFile?: string;
6
+ }
7
+ export declare const encodeVideo: ({ framesDir, fps, outputFile, audioFile }: EncodeOptions) => Promise<unknown>;
package/dist/index.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.encodeVideo = void 0;
7
+ const fluent_ffmpeg_1 = __importDefault(require("fluent-ffmpeg"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const encodeVideo = ({ framesDir, fps, outputFile, audioFile }) => {
10
+ return new Promise((resolve, reject) => {
11
+ const command = (0, fluent_ffmpeg_1.default)()
12
+ .input(path_1.default.join(framesDir, 'frame-%05d.png'))
13
+ .inputFPS(fps)
14
+ .outputOptions([
15
+ '-c:v libx264',
16
+ '-pix_fmt yuv420p',
17
+ '-crf 18'
18
+ ]);
19
+ if (audioFile) {
20
+ command.input(audioFile);
21
+ }
22
+ command
23
+ .on('start', (cmd) => console.log('FFmpeg started with command:', cmd))
24
+ .on('progress', (progress) => console.log('Encoding progress:', progress.percent, '%'))
25
+ .on('end', () => {
26
+ console.log('Encoding finished.');
27
+ resolve(outputFile);
28
+ })
29
+ .on('error', (err) => {
30
+ console.error('FFmpeg error:', err);
31
+ reject(err);
32
+ })
33
+ .save(outputFile);
34
+ });
35
+ };
36
+ exports.encodeVideo = encodeVideo;
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@open-motion/encoder",
3
+ "version": "0.0.1-alpha.0",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/open-motion/open-motion.git",
10
+ "directory": "packages/encoder"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "dependencies": {
19
+ "fluent-ffmpeg": "^2.1.2"
20
+ },
21
+ "scripts": {
22
+ "build": "tsc"
23
+ }
24
+ }