@marcuth/movie.js 0.0.1 → 0.1.1
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.
package/dist/clips/clip.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { Path } from "../utils/resolve-path";
|
|
1
2
|
import { RenderContext } from "../render-context";
|
|
2
3
|
import { FFmpegInput } from "../ffmpeg-input";
|
|
3
4
|
import { Clip } from "./clip";
|
|
4
|
-
import { Path } from "../utils/resolve-path";
|
|
5
5
|
export type ImageClipOptions<RenderData> = {
|
|
6
6
|
path: Path<RenderData>;
|
|
7
7
|
width?: number;
|
|
@@ -9,6 +9,11 @@ export type ImageClipOptions<RenderData> = {
|
|
|
9
9
|
duration: number;
|
|
10
10
|
fadeIn?: number;
|
|
11
11
|
fadeOut?: number;
|
|
12
|
+
scroll?: {
|
|
13
|
+
axis?: "auto" | "x" | "y";
|
|
14
|
+
direction?: "forward" | "backward";
|
|
15
|
+
easing?: "linear" | "easeIn" | "easeOut" | "easeInOut";
|
|
16
|
+
};
|
|
12
17
|
};
|
|
13
18
|
export declare class ImageClip<RenderData> extends Clip<RenderData> {
|
|
14
19
|
readonly duration: number;
|
|
@@ -17,7 +22,12 @@ export declare class ImageClip<RenderData> extends Clip<RenderData> {
|
|
|
17
22
|
readonly fadeOut?: number;
|
|
18
23
|
readonly width?: number;
|
|
19
24
|
readonly height?: number;
|
|
20
|
-
|
|
25
|
+
readonly scroll?: {
|
|
26
|
+
axis?: "auto" | "x" | "y";
|
|
27
|
+
direction?: "forward" | "backward";
|
|
28
|
+
easing?: "linear" | "easeIn" | "easeOut" | "easeInOut";
|
|
29
|
+
};
|
|
30
|
+
constructor({ duration, path, width, height, fadeIn, fadeOut, scroll }: ImageClipOptions<RenderData>);
|
|
21
31
|
protected getInput(path: string, inputIndex: number, fps: number): FFmpegInput;
|
|
22
32
|
build(data: RenderData, context: RenderContext): void;
|
|
23
33
|
}
|
package/dist/clips/image-clip.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ImageClip = void 0;
|
|
4
|
-
const clip_1 = require("./clip");
|
|
5
4
|
const resolve_path_1 = require("../utils/resolve-path");
|
|
5
|
+
const clip_1 = require("./clip");
|
|
6
|
+
const get_eased_expression_1 = require("../utils/get-eased-expression");
|
|
6
7
|
class ImageClip extends clip_1.Clip {
|
|
7
|
-
constructor({ duration, path, width, height, fadeIn, fadeOut }) {
|
|
8
|
+
constructor({ duration, path, width, height, fadeIn, fadeOut, scroll }) {
|
|
8
9
|
super();
|
|
9
10
|
this.duration = duration;
|
|
10
11
|
this.path = path;
|
|
@@ -12,6 +13,7 @@ class ImageClip extends clip_1.Clip {
|
|
|
12
13
|
this.fadeOut = fadeOut;
|
|
13
14
|
this.width = width;
|
|
14
15
|
this.height = height;
|
|
16
|
+
this.scroll = scroll;
|
|
15
17
|
}
|
|
16
18
|
getInput(path, inputIndex, fps) {
|
|
17
19
|
return {
|
|
@@ -30,7 +32,7 @@ class ImageClip extends clip_1.Clip {
|
|
|
30
32
|
};
|
|
31
33
|
}
|
|
32
34
|
build(data, context) {
|
|
33
|
-
var _a, _b;
|
|
35
|
+
var _a, _b, _c, _d, _e;
|
|
34
36
|
const path = (0, resolve_path_1.resolvePath)({ path: this.path, data: data, index: context.clipIndex });
|
|
35
37
|
const input = this.getInput(path, context.inputIndex, context.fps);
|
|
36
38
|
let currentVideoOutput = input.aliases.video;
|
|
@@ -60,6 +62,30 @@ class ImageClip extends clip_1.Clip {
|
|
|
60
62
|
});
|
|
61
63
|
currentVideoOutput = scaleOutput;
|
|
62
64
|
}
|
|
65
|
+
if (this.scroll) {
|
|
66
|
+
const cropOutput = `crop${context.inputIndex}`;
|
|
67
|
+
const easing = (_c = this.scroll.easing) !== null && _c !== void 0 ? _c : "linear";
|
|
68
|
+
const totalFrames = this.duration * context.fps;
|
|
69
|
+
const p = (0, get_eased_expression_1.getEasedExpression)(`min(n/${totalFrames},1)`, easing);
|
|
70
|
+
const xExpr = this.scroll.axis === "x" && this.width
|
|
71
|
+
? `if(gt(iw,${this.width}),min((iw-${this.width})*(${p}),iw-${this.width}),0)`
|
|
72
|
+
: "0";
|
|
73
|
+
const yExpr = this.scroll.axis === "y" && this.height
|
|
74
|
+
? `if(gt(ih,${this.height}),min((ih-${this.height})*(${p}),ih-${this.height}),0)`
|
|
75
|
+
: "0";
|
|
76
|
+
context.filters.push({
|
|
77
|
+
filter: "crop",
|
|
78
|
+
options: {
|
|
79
|
+
w: (_d = this.width) !== null && _d !== void 0 ? _d : "iw",
|
|
80
|
+
h: (_e = this.height) !== null && _e !== void 0 ? _e : "ih",
|
|
81
|
+
x: xExpr,
|
|
82
|
+
y: yExpr
|
|
83
|
+
},
|
|
84
|
+
inputs: currentVideoOutput,
|
|
85
|
+
outputs: cropOutput
|
|
86
|
+
});
|
|
87
|
+
currentVideoOutput = cropOutput;
|
|
88
|
+
}
|
|
63
89
|
if (this.fadeIn && this.fadeIn > 0) {
|
|
64
90
|
const fadeInOutput = `fadeIn${context.inputIndex}`;
|
|
65
91
|
context.filters.push({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getEasedExpression(expr: string, easing: "linear" | "easeIn" | "easeOut" | "easeInOut"): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEasedExpression = getEasedExpression;
|
|
4
|
+
function getEasedExpression(expr, easing) {
|
|
5
|
+
switch (easing) {
|
|
6
|
+
case "easeIn":
|
|
7
|
+
return `${expr}*${expr}`;
|
|
8
|
+
case "easeOut":
|
|
9
|
+
return `1-(1-${expr})*(1-${expr})`;
|
|
10
|
+
case "easeInOut":
|
|
11
|
+
return `(1-cos(PI*${expr}))/2`;
|
|
12
|
+
default:
|
|
13
|
+
return expr;
|
|
14
|
+
}
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marcuth/movie.js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Video template builder",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -32,4 +32,4 @@
|
|
|
32
32
|
"cli-progress": "^3.12.0",
|
|
33
33
|
"fluent-ffmpeg": "^2.1.3"
|
|
34
34
|
}
|
|
35
|
-
}
|
|
35
|
+
}
|