@marcuth/movie.js 0.1.2 → 0.1.3

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.
@@ -1,3 +1,4 @@
1
+ import ffmpeg from "fluent-ffmpeg";
1
2
  import { Path } from "../utils/resolve-path";
2
3
  import { RenderContext } from "../render-context";
3
4
  import { FFmpegInput } from "../ffmpeg-input";
@@ -29,5 +30,6 @@ export declare class ImageClip<RenderData> extends Clip<RenderData> {
29
30
  };
30
31
  constructor({ duration, path, width, height, fadeIn, fadeOut, scroll }: ImageClipOptions<RenderData>);
31
32
  protected getInput(path: string, inputIndex: number, fps: number): FFmpegInput;
32
- build(data: RenderData, context: RenderContext): void;
33
+ protected getMetadata(path: string): Promise<ffmpeg.FfprobeData>;
34
+ build(data: RenderData, context: RenderContext): Promise<void>;
33
35
  }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ImageClip = void 0;
4
+ const fluent_ffmpeg_1 = require("fluent-ffmpeg");
4
5
  const resolve_path_1 = require("../utils/resolve-path");
5
- const clip_1 = require("./clip");
6
6
  const easing_expr_1 = require("../utils/easing-expr");
7
+ const clip_1 = require("./clip");
7
8
  class ImageClip extends clip_1.Clip {
8
9
  constructor({ duration, path, width, height, fadeIn, fadeOut, scroll }) {
9
10
  super();
@@ -31,11 +32,17 @@ class ImageClip extends clip_1.Clip {
31
32
  ]
32
33
  };
33
34
  }
34
- build(data, context) {
35
+ getMetadata(path) {
36
+ return new Promise((resolve, reject) => {
37
+ (0, fluent_ffmpeg_1.ffprobe)(path, (err, data) => err ? reject(err) : resolve(data));
38
+ });
39
+ }
40
+ async build(data, context) {
35
41
  const path = (0, resolve_path_1.resolvePath)({ path: this.path, data: data, index: context.clipIndex });
36
42
  const input = this.getInput(path, context.inputIndex, context.fps);
37
43
  let currentVideoOutput = input.aliases.video;
38
44
  const currentAudioOutput = input.aliases.audio;
45
+ const metadata = await this.getMetadata(path);
39
46
  context.command
40
47
  .input(input.path)
41
48
  .inputOptions(input.options);
@@ -54,9 +61,12 @@ class ImageClip extends clip_1.Clip {
54
61
  const hasCanvas = this.width !== -1 || this.height !== -1;
55
62
  if (hasCanvas && this.scroll) {
56
63
  const scaleOutput = `scale${context.inputIndex}`;
57
- const { axis = "auto" } = this.scroll;
64
+ let { axis = "auto" } = this.scroll;
58
65
  let scaleOptions = null;
59
- if (axis === "y" || axis === "auto") {
66
+ if (axis === "auto") {
67
+ axis = metadata.format.width > metadata.format.height ? "x" : "y";
68
+ }
69
+ if (axis === "y") {
60
70
  scaleOptions = {
61
71
  w: this.width,
62
72
  h: -1,
@@ -69,7 +79,7 @@ class ImageClip extends clip_1.Clip {
69
79
  };
70
80
  }
71
81
  if (!scaleOptions) {
72
- throw new Error("Invalid scale options");
82
+ throw new Error("Invalid scroll axis");
73
83
  }
74
84
  context.filters.push({
75
85
  filter: "scale",
@@ -77,7 +87,14 @@ class ImageClip extends clip_1.Clip {
77
87
  inputs: currentVideoOutput,
78
88
  outputs: scaleOutput,
79
89
  });
80
- currentVideoOutput = scaleOutput;
90
+ const setsarOutput = `setsar${context.inputIndex}`;
91
+ context.filters.push({
92
+ filter: "setsar",
93
+ options: { sar: "1/1" },
94
+ inputs: scaleOutput,
95
+ outputs: setsarOutput,
96
+ });
97
+ currentVideoOutput = setsarOutput;
81
98
  }
82
99
  else if (hasCanvas && !this.scroll) {
83
100
  const scaleOutput = `scale${context.inputIndex}`;
package/dist/template.js CHANGED
@@ -53,18 +53,6 @@ class Template {
53
53
  mixFilter,
54
54
  finalAudioFilter
55
55
  ].filter((filter) => filter !== null);
56
- // console.dir({
57
- // concatFilter,
58
- // finalAudioFilter,
59
- // mixFilter,
60
- // filterComplex,
61
- // context: {
62
- // ...context,
63
- // command: "<command>"
64
- // }
65
- // }, {
66
- // depth: null
67
- // })
68
56
  command.complexFilter(filterComplex);
69
57
  command.outputOptions([
70
58
  "-map [outv]",
@@ -4,13 +4,13 @@ exports.easingExpr = easingExpr;
4
4
  function easingExpr(easing, t) {
5
5
  switch (easing) {
6
6
  case "linear":
7
- return `(${t})`; // Adicionar parênteses para garantir que a expressão seja avaliada
7
+ return `(${t})`;
8
8
  case "easeIn":
9
9
  return `pow(${t},2)`;
10
10
  case "easeOut":
11
- return `1-pow(1-(${t}),2)`; // Adicionar parênteses extras
11
+ return `1-pow(1-(${t}),2)`;
12
12
  case "easeInOut":
13
- return `if(lt(${t},0.5),2*pow(${t},2),1-2*pow(1-(${t}),2))`; // Adicionar parênteses extras
13
+ return `if(lt(${t},0.5),2*pow(${t},2),1-2*pow(1-(${t}),2))`;
14
14
  default:
15
15
  return `(${t})`;
16
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marcuth/movie.js",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Video template builder",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",