@better-media/plugin-video-processing 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/LICENSE +21 -0
- package/dist/index.d.mts +88 -0
- package/dist/index.d.ts +88 -0
- package/dist/index.js +528 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +518 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 abenezeratnafu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
|
20
|
+
ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { PipelinePlugin } from '@better-media/core';
|
|
2
|
+
|
|
3
|
+
/** A single thumbnail to extract from the video. */
|
|
4
|
+
interface ThumbnailPreset {
|
|
5
|
+
/**
|
|
6
|
+
* Position to extract.
|
|
7
|
+
* - number: seconds from start (e.g. 5 = 5s)
|
|
8
|
+
* - string ending with "%": percentage of total duration (e.g. "10%")
|
|
9
|
+
* - other string: parsed as seconds (e.g. "5.5")
|
|
10
|
+
*/
|
|
11
|
+
at: number | string;
|
|
12
|
+
/** Output image format. Default: "jpeg". */
|
|
13
|
+
format?: "jpeg" | "png" | "webp";
|
|
14
|
+
/** Output width in pixels. Aspect ratio preserved when only one dimension is set. */
|
|
15
|
+
width?: number;
|
|
16
|
+
/** Output height in pixels. */
|
|
17
|
+
height?: number;
|
|
18
|
+
}
|
|
19
|
+
/** A single transcode target. */
|
|
20
|
+
interface TranscodePreset {
|
|
21
|
+
/** Identifier used in storage key and media_versions. Must be stable. */
|
|
22
|
+
name: string;
|
|
23
|
+
/** Output container format. */
|
|
24
|
+
format: "mp4" | "webm";
|
|
25
|
+
/** Video codec. Defaults: libx264 (mp4), libvpx-vp9 (webm). */
|
|
26
|
+
videoCodec?: string;
|
|
27
|
+
/** Audio codec. Defaults: aac (mp4), libopus (webm). */
|
|
28
|
+
audioCodec?: string;
|
|
29
|
+
/** Video bitrate, e.g. "1000k". */
|
|
30
|
+
videoBitrate?: string;
|
|
31
|
+
/** Audio bitrate, e.g. "128k". */
|
|
32
|
+
audioBitrate?: string;
|
|
33
|
+
/** Resolution as "WxH", e.g. "1280x720". Omit to keep source resolution. */
|
|
34
|
+
resolution?: string;
|
|
35
|
+
}
|
|
36
|
+
interface VideoProcessingPluginOptions {
|
|
37
|
+
/** Execution mode. Default: "background". */
|
|
38
|
+
executionMode?: "sync" | "background";
|
|
39
|
+
/**
|
|
40
|
+
* Thumbnail presets to extract.
|
|
41
|
+
* Pass `false` to disable thumbnail extraction entirely.
|
|
42
|
+
* Default: one JPEG at 10% of duration, 640px wide.
|
|
43
|
+
*/
|
|
44
|
+
thumbnails?: ThumbnailPreset[] | false;
|
|
45
|
+
/**
|
|
46
|
+
* Transcode presets to produce. Omit or pass an empty array for no transcoding.
|
|
47
|
+
* Each preset produces one output file stored as a media_versions row.
|
|
48
|
+
*/
|
|
49
|
+
transcode?: TranscodePreset[];
|
|
50
|
+
/** Only process files whose mimeType is in this list. Default: common video types. */
|
|
51
|
+
allowedMimeTypes?: string[];
|
|
52
|
+
/**
|
|
53
|
+
* Skip the plugin if the source file is larger than this (bytes).
|
|
54
|
+
* Useful for very large uploads that shouldn't block the sync path.
|
|
55
|
+
* Default: no limit.
|
|
56
|
+
*/
|
|
57
|
+
maxInputBytes?: number;
|
|
58
|
+
/** Override the ffmpeg binary path. Default: resolved from PATH. */
|
|
59
|
+
ffmpegPath?: string;
|
|
60
|
+
/** Override the ffprobe binary path. Default: resolved from PATH. */
|
|
61
|
+
ffprobePath?: string;
|
|
62
|
+
/** Storage key prefix for derivative files. Default: "processing". */
|
|
63
|
+
derivativePrefix?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Insert rows into media_versions for thumbnails and transcoded outputs.
|
|
66
|
+
* Default: true.
|
|
67
|
+
*/
|
|
68
|
+
persistMediaVersions?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Skip a thumbnail or transcode if the storage key already exists.
|
|
71
|
+
* Default: true.
|
|
72
|
+
*/
|
|
73
|
+
skipExistingDerivatives?: boolean;
|
|
74
|
+
/** Timeout for the full processing run in milliseconds. Default: 300_000 (5 min). */
|
|
75
|
+
timeoutMs?: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
declare const DEFAULT_THUMBNAIL_PRESETS: ThumbnailPreset[];
|
|
79
|
+
declare const DEFAULT_VIDEO_MIME_TYPES: string[];
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Video processing plugin: thumbnail extraction, transcoding, and metadata via ffmpeg.
|
|
83
|
+
*
|
|
84
|
+
* Requires `fluent-ffmpeg` peer dependency and the `ffmpeg`/`ffprobe` binaries in PATH.
|
|
85
|
+
*/
|
|
86
|
+
declare function videoProcessingPlugin(opts?: VideoProcessingPluginOptions): PipelinePlugin;
|
|
87
|
+
|
|
88
|
+
export { DEFAULT_THUMBNAIL_PRESETS, DEFAULT_VIDEO_MIME_TYPES, type ThumbnailPreset, type TranscodePreset, type VideoProcessingPluginOptions, videoProcessingPlugin };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { PipelinePlugin } from '@better-media/core';
|
|
2
|
+
|
|
3
|
+
/** A single thumbnail to extract from the video. */
|
|
4
|
+
interface ThumbnailPreset {
|
|
5
|
+
/**
|
|
6
|
+
* Position to extract.
|
|
7
|
+
* - number: seconds from start (e.g. 5 = 5s)
|
|
8
|
+
* - string ending with "%": percentage of total duration (e.g. "10%")
|
|
9
|
+
* - other string: parsed as seconds (e.g. "5.5")
|
|
10
|
+
*/
|
|
11
|
+
at: number | string;
|
|
12
|
+
/** Output image format. Default: "jpeg". */
|
|
13
|
+
format?: "jpeg" | "png" | "webp";
|
|
14
|
+
/** Output width in pixels. Aspect ratio preserved when only one dimension is set. */
|
|
15
|
+
width?: number;
|
|
16
|
+
/** Output height in pixels. */
|
|
17
|
+
height?: number;
|
|
18
|
+
}
|
|
19
|
+
/** A single transcode target. */
|
|
20
|
+
interface TranscodePreset {
|
|
21
|
+
/** Identifier used in storage key and media_versions. Must be stable. */
|
|
22
|
+
name: string;
|
|
23
|
+
/** Output container format. */
|
|
24
|
+
format: "mp4" | "webm";
|
|
25
|
+
/** Video codec. Defaults: libx264 (mp4), libvpx-vp9 (webm). */
|
|
26
|
+
videoCodec?: string;
|
|
27
|
+
/** Audio codec. Defaults: aac (mp4), libopus (webm). */
|
|
28
|
+
audioCodec?: string;
|
|
29
|
+
/** Video bitrate, e.g. "1000k". */
|
|
30
|
+
videoBitrate?: string;
|
|
31
|
+
/** Audio bitrate, e.g. "128k". */
|
|
32
|
+
audioBitrate?: string;
|
|
33
|
+
/** Resolution as "WxH", e.g. "1280x720". Omit to keep source resolution. */
|
|
34
|
+
resolution?: string;
|
|
35
|
+
}
|
|
36
|
+
interface VideoProcessingPluginOptions {
|
|
37
|
+
/** Execution mode. Default: "background". */
|
|
38
|
+
executionMode?: "sync" | "background";
|
|
39
|
+
/**
|
|
40
|
+
* Thumbnail presets to extract.
|
|
41
|
+
* Pass `false` to disable thumbnail extraction entirely.
|
|
42
|
+
* Default: one JPEG at 10% of duration, 640px wide.
|
|
43
|
+
*/
|
|
44
|
+
thumbnails?: ThumbnailPreset[] | false;
|
|
45
|
+
/**
|
|
46
|
+
* Transcode presets to produce. Omit or pass an empty array for no transcoding.
|
|
47
|
+
* Each preset produces one output file stored as a media_versions row.
|
|
48
|
+
*/
|
|
49
|
+
transcode?: TranscodePreset[];
|
|
50
|
+
/** Only process files whose mimeType is in this list. Default: common video types. */
|
|
51
|
+
allowedMimeTypes?: string[];
|
|
52
|
+
/**
|
|
53
|
+
* Skip the plugin if the source file is larger than this (bytes).
|
|
54
|
+
* Useful for very large uploads that shouldn't block the sync path.
|
|
55
|
+
* Default: no limit.
|
|
56
|
+
*/
|
|
57
|
+
maxInputBytes?: number;
|
|
58
|
+
/** Override the ffmpeg binary path. Default: resolved from PATH. */
|
|
59
|
+
ffmpegPath?: string;
|
|
60
|
+
/** Override the ffprobe binary path. Default: resolved from PATH. */
|
|
61
|
+
ffprobePath?: string;
|
|
62
|
+
/** Storage key prefix for derivative files. Default: "processing". */
|
|
63
|
+
derivativePrefix?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Insert rows into media_versions for thumbnails and transcoded outputs.
|
|
66
|
+
* Default: true.
|
|
67
|
+
*/
|
|
68
|
+
persistMediaVersions?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Skip a thumbnail or transcode if the storage key already exists.
|
|
71
|
+
* Default: true.
|
|
72
|
+
*/
|
|
73
|
+
skipExistingDerivatives?: boolean;
|
|
74
|
+
/** Timeout for the full processing run in milliseconds. Default: 300_000 (5 min). */
|
|
75
|
+
timeoutMs?: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
declare const DEFAULT_THUMBNAIL_PRESETS: ThumbnailPreset[];
|
|
79
|
+
declare const DEFAULT_VIDEO_MIME_TYPES: string[];
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Video processing plugin: thumbnail extraction, transcoding, and metadata via ffmpeg.
|
|
83
|
+
*
|
|
84
|
+
* Requires `fluent-ffmpeg` peer dependency and the `ffmpeg`/`ffprobe` binaries in PATH.
|
|
85
|
+
*/
|
|
86
|
+
declare function videoProcessingPlugin(opts?: VideoProcessingPluginOptions): PipelinePlugin;
|
|
87
|
+
|
|
88
|
+
export { DEFAULT_THUMBNAIL_PRESETS, DEFAULT_VIDEO_MIME_TYPES, type ThumbnailPreset, type TranscodePreset, type VideoProcessingPluginOptions, videoProcessingPlugin };
|