@temelj/ffmpeg 0.1.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.
- package/LICENSE +21 -0
- package/README.md +118 -0
- package/dist/args.d.mts +9 -0
- package/dist/args.d.mts.map +1 -0
- package/dist/args.mjs +71 -0
- package/dist/args.mjs.map +1 -0
- package/dist/builder.d.mts +52 -0
- package/dist/builder.d.mts.map +1 -0
- package/dist/builder.mjs +174 -0
- package/dist/builder.mjs.map +1 -0
- package/dist/filter-graph.d.mts +87 -0
- package/dist/filter-graph.d.mts.map +1 -0
- package/dist/filter-graph.mjs +206 -0
- package/dist/filter-graph.mjs.map +1 -0
- package/dist/generated/options.d.mts +493 -0
- package/dist/generated/options.d.mts.map +1 -0
- package/dist/generated/options.mjs +1 -0
- package/dist/generated/serialize.d.mts +34 -0
- package/dist/generated/serialize.d.mts.map +1 -0
- package/dist/generated/serialize.mjs +294 -0
- package/dist/generated/serialize.mjs.map +1 -0
- package/dist/mapping.d.mts +27 -0
- package/dist/mapping.d.mts.map +1 -0
- package/dist/mapping.mjs +44 -0
- package/dist/mapping.mjs.map +1 -0
- package/dist/mod.d.mts +7 -0
- package/dist/mod.mjs +5 -0
- package/dist/structured.d.mts +66 -0
- package/dist/structured.d.mts.map +1 -0
- package/dist/structured.mjs +114 -0
- package/dist/structured.mjs.map +1 -0
- package/dist/types.d.mts +26 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +1 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tin Rabzelj
|
|
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, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<h1 align="center" style="text-decoration:none;">@temelj/ffmpeg</h1>
|
|
3
|
+
<br/>
|
|
4
|
+
<p align="center">
|
|
5
|
+
Type-safe fluent builder for ffmpeg.
|
|
6
|
+
</p>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://twitter.com/tinrab" rel="nofollow"><img src="https://img.shields.io/badge/created%20by-@tinrab-1d9bf0.svg" alt="Created by Tin Rabzelj"></a>
|
|
11
|
+
<a href="https://jsr.io/@temelj/ffmpeg" rel="nofollow"><img src="https://jsr.io/badges/@temelj/ffmpeg" alt="jsr"></a>
|
|
12
|
+
<a href="https://opensource.org/licenses/MIT" rel="nofollow"><img src="https://img.shields.io/github/license/tinrab/temelj" alt="License"></a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
<div align="center">
|
|
16
|
+
<a href="https://jsr.io/@temelj/ffmpeg">jsr</a>
|
|
17
|
+
<span> • </span>
|
|
18
|
+
<a href="https://www.npmjs.com/package/@temelj/ffmpeg">npm</a>
|
|
19
|
+
<span> • </span>
|
|
20
|
+
<a href="https://github.com/tinrab/temelj/issues/new">Issues</a>
|
|
21
|
+
<span> • </span>
|
|
22
|
+
<a href="https://twitter.com/tinrab">@tinrab</a>
|
|
23
|
+
<br />
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
<br/>
|
|
27
|
+
<br/>
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
# npm
|
|
33
|
+
$ npm install @temelj/ffmpeg
|
|
34
|
+
# jsr
|
|
35
|
+
$ deno add jsr:@temelj/ffmpeg # or jsr add @temelj/ffmpeg
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
Build a simple transcode command.
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { ffmpeg } from "@temelj/ffmpeg";
|
|
44
|
+
|
|
45
|
+
const command = ffmpeg()
|
|
46
|
+
.global({ overwrite: true, loglevel: "error" })
|
|
47
|
+
.input("input.mp4", { ss: "00:01:00" })
|
|
48
|
+
.output("output.mp4", {
|
|
49
|
+
videoCodec: "libx264",
|
|
50
|
+
audioCodec: "aac",
|
|
51
|
+
videoBitrate: "2M",
|
|
52
|
+
audioBitrate: "128k",
|
|
53
|
+
pixFmt: "yuv420p",
|
|
54
|
+
movflags: "+faststart",
|
|
55
|
+
})
|
|
56
|
+
.toCommandLine();
|
|
57
|
+
|
|
58
|
+
console.log(command);
|
|
59
|
+
// -loglevel error -y -ss 00:01:00 -i input.mp4 -c:v libx264 -c:a aac -b:v 2M -b:a 128k -pix_fmt yuv420p -movflags +faststart output.mp4
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Build `filter_complex` graphs with typed labels.
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { ffmpeg, filterGraph } from "@temelj/ffmpeg";
|
|
66
|
+
|
|
67
|
+
const graph = filterGraph();
|
|
68
|
+
const video = graph.videoInput(0).hflip().scale(1280, 720).label("outv");
|
|
69
|
+
|
|
70
|
+
const args = ffmpeg()
|
|
71
|
+
.input("input.mp4")
|
|
72
|
+
.filterComplex(graph)
|
|
73
|
+
.output("output.mp4")
|
|
74
|
+
.mapLabel(video)
|
|
75
|
+
.build().args;
|
|
76
|
+
|
|
77
|
+
console.log(args);
|
|
78
|
+
// [
|
|
79
|
+
// "-filter_complex",
|
|
80
|
+
// "[0:v]hflip,scale=1280:720[outv]",
|
|
81
|
+
// "-i",
|
|
82
|
+
// "input.mp4",
|
|
83
|
+
// "-map",
|
|
84
|
+
// "[outv]",
|
|
85
|
+
// "output.mp4",
|
|
86
|
+
// ]
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Use structured metadata values and explicit escape hatches.
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import { ffmpeg, unsafe } from "@temelj/ffmpeg";
|
|
93
|
+
|
|
94
|
+
const args = ffmpeg()
|
|
95
|
+
.input("in.mp4")
|
|
96
|
+
.output("out.mp4", {
|
|
97
|
+
metadataScopes: {
|
|
98
|
+
"s:v:0": {
|
|
99
|
+
metadata: { key: "title", value: "Main Video" },
|
|
100
|
+
},
|
|
101
|
+
"c:0": {
|
|
102
|
+
mapMetadata: unsafe("0:s:0"),
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
})
|
|
106
|
+
.build().args;
|
|
107
|
+
|
|
108
|
+
console.log(args);
|
|
109
|
+
// [
|
|
110
|
+
// "-i",
|
|
111
|
+
// "in.mp4",
|
|
112
|
+
// "-metadata:s:v:0",
|
|
113
|
+
// "title=Main Video",
|
|
114
|
+
// "-map_metadata:c:0",
|
|
115
|
+
// "0:s:0",
|
|
116
|
+
// "out.mp4",
|
|
117
|
+
// ]
|
|
118
|
+
```
|
package/dist/args.d.mts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { GlobalOptions, InputOptions, OutputOptions } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/args.d.ts
|
|
4
|
+
declare function serializeGlobal(opts: GlobalOptions): string[];
|
|
5
|
+
declare function serializeInput(opts: InputOptions): string[];
|
|
6
|
+
declare function serializeOutput(opts: OutputOptions): string[];
|
|
7
|
+
//#endregion
|
|
8
|
+
export { serializeGlobal, serializeInput, serializeOutput };
|
|
9
|
+
//# sourceMappingURL=args.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.d.mts","names":[],"sources":["../src/args.ts"],"mappings":";;;iBAoIgB,eAAA,CAAgB,IAAmB,EAAb,aAAa;AAAA,iBAOnC,cAAA,CAAe,IAAkB,EAAZ,YAAY;AAAA,iBAajC,eAAA,CAAgB,IAAmB,EAAb,aAAa"}
|
package/dist/args.mjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { generatedGlobalDefs, generatedInputDefs, generatedInputStreamDefs, generatedOutputDefs, generatedOutputMetadataDefs, generatedOutputStreamDefs } from "./generated/serialize.mjs";
|
|
2
|
+
import { normalizeOutputOptions } from "./structured.mjs";
|
|
3
|
+
//#region src/args.ts
|
|
4
|
+
function appendRawValue(args, flag, value) {
|
|
5
|
+
if (typeof value === "boolean") {
|
|
6
|
+
if (value) args.push(flag);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
args.push(flag, String(value));
|
|
10
|
+
}
|
|
11
|
+
function serializeRaw(args, raw) {
|
|
12
|
+
if (!raw) return;
|
|
13
|
+
for (const [flag, value] of Object.entries(raw)) {
|
|
14
|
+
if (value === void 0 || value === null) continue;
|
|
15
|
+
if (Array.isArray(value)) {
|
|
16
|
+
for (const item of value) appendRawValue(args, flag, item);
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
appendRawValue(args, flag, value);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function appendDefinedValue(args, def, flag, value) {
|
|
23
|
+
if (value === void 0 || value === null) return;
|
|
24
|
+
if (def.isArray && Array.isArray(value)) {
|
|
25
|
+
for (const item of value) args.push(flag, typeof item === "string" ? item : String(item));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (def.isFlag) {
|
|
29
|
+
if (value) args.push(flag);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (typeof value === "string" || typeof value === "number") args.push(flag, String(value));
|
|
33
|
+
}
|
|
34
|
+
function flagWithSpecifier(flag, specifier) {
|
|
35
|
+
const fixedSpecifierMatch = flag.match(/^(-[^:]+):([A-Za-z])$/);
|
|
36
|
+
if (fixedSpecifierMatch) {
|
|
37
|
+
const [, , fixedSpecifier] = fixedSpecifierMatch;
|
|
38
|
+
if (specifier === fixedSpecifier) return flag;
|
|
39
|
+
if (specifier.startsWith(`${fixedSpecifier}:`)) return `${flag}${specifier.slice(fixedSpecifier.length)}`;
|
|
40
|
+
}
|
|
41
|
+
return `${flag}:${specifier}`;
|
|
42
|
+
}
|
|
43
|
+
function serializeScoped(args, bag, defs, getFlag = (flag, specifier) => `${flag}:${specifier}`) {
|
|
44
|
+
if (!bag) return;
|
|
45
|
+
for (const [specifier, scoped] of Object.entries(bag)) for (const [key, def] of Object.entries(defs)) appendDefinedValue(args, def, getFlag(def.flag, specifier), scoped[key]);
|
|
46
|
+
}
|
|
47
|
+
function serializeDefined(opts, defs) {
|
|
48
|
+
const args = [];
|
|
49
|
+
for (const [key, def] of Object.entries(defs)) appendDefinedValue(args, def, def.flag, opts[key]);
|
|
50
|
+
serializeRaw(args, opts.raw);
|
|
51
|
+
return args;
|
|
52
|
+
}
|
|
53
|
+
function serializeGlobal(opts) {
|
|
54
|
+
return serializeDefined(opts, generatedGlobalDefs);
|
|
55
|
+
}
|
|
56
|
+
function serializeInput(opts) {
|
|
57
|
+
const args = serializeDefined(opts, generatedInputDefs);
|
|
58
|
+
serializeScoped(args, opts.streams, generatedInputStreamDefs);
|
|
59
|
+
return args;
|
|
60
|
+
}
|
|
61
|
+
function serializeOutput(opts) {
|
|
62
|
+
const normalized = normalizeOutputOptions(opts);
|
|
63
|
+
const args = serializeDefined(normalized, generatedOutputDefs);
|
|
64
|
+
serializeScoped(args, normalized.streams, generatedOutputStreamDefs, flagWithSpecifier);
|
|
65
|
+
serializeScoped(args, normalized.metadataScopes, generatedOutputMetadataDefs);
|
|
66
|
+
return args;
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { serializeGlobal, serializeInput, serializeOutput };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=args.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.mjs","names":[],"sources":["../src/args.ts"],"sourcesContent":["import type {\n GlobalOptions,\n InputOptions,\n OutputOptions,\n RawOptionBag,\n SerializedOptionScalar,\n} from \"./types.ts\";\n\nimport {\n generatedInputDefs,\n generatedInputStreamDefs,\n generatedOutputDefs,\n generatedOutputMetadataDefs,\n generatedOutputStreamDefs,\n generatedGlobalDefs,\n} from \"./generated/serialize.ts\";\nimport { normalizeOutputOptions } from \"./structured.ts\";\n\ninterface Entry {\n flag: string;\n isFlag: boolean;\n isArray: boolean;\n}\n\ninterface ScopedOptions {\n [key: string]: unknown;\n}\n\nfunction appendRawValue(args: string[], flag: string, value: SerializedOptionScalar): void {\n if (typeof value === \"boolean\") {\n if (value) {\n args.push(flag);\n }\n return;\n }\n\n args.push(flag, String(value));\n}\n\nfunction serializeRaw(args: string[], raw: RawOptionBag | undefined): void {\n if (!raw) {\n return;\n }\n\n for (const [flag, value] of Object.entries(raw)) {\n if (value === undefined || value === null) {\n continue;\n }\n\n if (Array.isArray(value)) {\n for (const item of value as readonly SerializedOptionScalar[]) {\n appendRawValue(args, flag, item);\n }\n continue;\n }\n\n appendRawValue(args, flag, value as SerializedOptionScalar);\n }\n}\n\nfunction appendDefinedValue(args: string[], def: Entry, flag: string, value: unknown): void {\n if (value === undefined || value === null) {\n return;\n }\n\n if (def.isArray && Array.isArray(value)) {\n for (const item of value) {\n args.push(flag, typeof item === \"string\" ? item : String(item));\n }\n return;\n }\n\n if (def.isFlag) {\n if (value) {\n args.push(flag);\n }\n return;\n }\n\n if (typeof value === \"string\" || typeof value === \"number\") {\n args.push(flag, String(value));\n }\n}\n\nfunction flagWithSpecifier(flag: string, specifier: string): string {\n const fixedSpecifierMatch = flag.match(/^(-[^:]+):([A-Za-z])$/);\n if (fixedSpecifierMatch) {\n const [, , fixedSpecifier] = fixedSpecifierMatch;\n if (specifier === fixedSpecifier) {\n return flag;\n }\n if (specifier.startsWith(`${fixedSpecifier}:`)) {\n return `${flag}${specifier.slice(fixedSpecifier.length)}`;\n }\n }\n\n return `${flag}:${specifier}`;\n}\n\nfunction serializeScoped(\n args: string[],\n bag: Record<string, ScopedOptions> | undefined,\n defs: Record<string, Entry>,\n getFlag: (flag: string, specifier: string) => string = (flag, specifier) =>\n `${flag}:${specifier}`,\n): void {\n if (!bag) {\n return;\n }\n\n for (const [specifier, scoped] of Object.entries(bag)) {\n for (const [key, def] of Object.entries(defs)) {\n appendDefinedValue(args, def, getFlag(def.flag, specifier), scoped[key]);\n }\n }\n}\n\nfunction serializeDefined(\n opts: Record<string, unknown> & { raw?: RawOptionBag },\n defs: Record<string, Entry>,\n): string[] {\n const args: string[] = [];\n\n for (const [key, def] of Object.entries(defs)) {\n appendDefinedValue(args, def, def.flag, opts[key]);\n }\n\n serializeRaw(args, opts.raw);\n\n return args;\n}\n\nexport function serializeGlobal(opts: GlobalOptions): string[] {\n return serializeDefined(\n opts as Record<string, unknown> & { raw?: RawOptionBag },\n generatedGlobalDefs,\n );\n}\n\nexport function serializeInput(opts: InputOptions): string[] {\n const args = serializeDefined(\n opts as Record<string, unknown> & { raw?: RawOptionBag },\n generatedInputDefs,\n );\n serializeScoped(\n args,\n opts.streams as Record<string, ScopedOptions> | undefined,\n generatedInputStreamDefs,\n );\n return args;\n}\n\nexport function serializeOutput(opts: OutputOptions): string[] {\n const normalized = normalizeOutputOptions(\n opts as unknown as import(\"./generated/options.ts\").OutputOptions,\n );\n const args = serializeDefined(\n normalized as Record<string, unknown> & { raw?: RawOptionBag },\n generatedOutputDefs,\n );\n serializeScoped(\n args,\n normalized.streams as Record<string, ScopedOptions> | undefined,\n generatedOutputStreamDefs,\n flagWithSpecifier,\n );\n serializeScoped(\n args,\n normalized.metadataScopes as Record<string, ScopedOptions> | undefined,\n generatedOutputMetadataDefs,\n );\n return args;\n}\n"],"mappings":";;;AA4BA,SAAS,eAAe,MAAgB,MAAc,OAAqC;CACzF,IAAI,OAAO,UAAU,WAAW;EAC9B,IAAI,OACF,KAAK,KAAK,IAAI;EAEhB;CACF;CAEA,KAAK,KAAK,MAAM,OAAO,KAAK,CAAC;AAC/B;AAEA,SAAS,aAAa,MAAgB,KAAqC;CACzE,IAAI,CAAC,KACH;CAGF,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,GAAG,GAAG;EAC/C,IAAI,UAAU,KAAA,KAAa,UAAU,MACnC;EAGF,IAAI,MAAM,QAAQ,KAAK,GAAG;GACxB,KAAK,MAAM,QAAQ,OACjB,eAAe,MAAM,MAAM,IAAI;GAEjC;EACF;EAEA,eAAe,MAAM,MAAM,KAA+B;CAC5D;AACF;AAEA,SAAS,mBAAmB,MAAgB,KAAY,MAAc,OAAsB;CAC1F,IAAI,UAAU,KAAA,KAAa,UAAU,MACnC;CAGF,IAAI,IAAI,WAAW,MAAM,QAAQ,KAAK,GAAG;EACvC,KAAK,MAAM,QAAQ,OACjB,KAAK,KAAK,MAAM,OAAO,SAAS,WAAW,OAAO,OAAO,IAAI,CAAC;EAEhE;CACF;CAEA,IAAI,IAAI,QAAQ;EACd,IAAI,OACF,KAAK,KAAK,IAAI;EAEhB;CACF;CAEA,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,UAChD,KAAK,KAAK,MAAM,OAAO,KAAK,CAAC;AAEjC;AAEA,SAAS,kBAAkB,MAAc,WAA2B;CAClE,MAAM,sBAAsB,KAAK,MAAM,uBAAuB;CAC9D,IAAI,qBAAqB;EACvB,MAAM,KAAK,kBAAkB;EAC7B,IAAI,cAAc,gBAChB,OAAO;EAET,IAAI,UAAU,WAAW,GAAG,eAAe,EAAE,GAC3C,OAAO,GAAG,OAAO,UAAU,MAAM,eAAe,MAAM;CAE1D;CAEA,OAAO,GAAG,KAAK,GAAG;AACpB;AAEA,SAAS,gBACP,MACA,KACA,MACA,WAAwD,MAAM,cAC5D,GAAG,KAAK,GAAG,aACP;CACN,IAAI,CAAC,KACH;CAGF,KAAK,MAAM,CAAC,WAAW,WAAW,OAAO,QAAQ,GAAG,GAClD,KAAK,MAAM,CAAC,KAAK,QAAQ,OAAO,QAAQ,IAAI,GAC1C,mBAAmB,MAAM,KAAK,QAAQ,IAAI,MAAM,SAAS,GAAG,OAAO,IAAI;AAG7E;AAEA,SAAS,iBACP,MACA,MACU;CACV,MAAM,OAAiB,CAAC;CAExB,KAAK,MAAM,CAAC,KAAK,QAAQ,OAAO,QAAQ,IAAI,GAC1C,mBAAmB,MAAM,KAAK,IAAI,MAAM,KAAK,IAAI;CAGnD,aAAa,MAAM,KAAK,GAAG;CAE3B,OAAO;AACT;AAEA,SAAgB,gBAAgB,MAA+B;CAC7D,OAAO,iBACL,MACA,mBACF;AACF;AAEA,SAAgB,eAAe,MAA8B;CAC3D,MAAM,OAAO,iBACX,MACA,kBACF;CACA,gBACE,MACA,KAAK,SACL,wBACF;CACA,OAAO;AACT;AAEA,SAAgB,gBAAgB,MAA+B;CAC7D,MAAM,aAAa,uBACjB,IACF;CACA,MAAM,OAAO,iBACX,YACA,mBACF;CACA,gBACE,MACA,WAAW,SACX,2BACA,iBACF;CACA,gBACE,MACA,WAAW,gBACX,2BACF;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { GlobalOptions, InputOptions, OutputOptions } from "./types.mjs";
|
|
2
|
+
import { MapStreamType } from "./mapping.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/builder.d.ts
|
|
5
|
+
interface BuildResult {
|
|
6
|
+
args: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
declare class FFmpegBuilder {
|
|
9
|
+
private _global;
|
|
10
|
+
private _inputs;
|
|
11
|
+
private _outputs;
|
|
12
|
+
private _filterGraph;
|
|
13
|
+
private currentInput;
|
|
14
|
+
private currentOutput;
|
|
15
|
+
global(opts: GlobalOptions): this;
|
|
16
|
+
input(path: string, opts?: InputOptions): this;
|
|
17
|
+
seekInput(position: InputOptions["ss"]): this;
|
|
18
|
+
inputDuration(duration: InputOptions["t"]): this;
|
|
19
|
+
inputFormat(format: InputOptions["f"]): this;
|
|
20
|
+
inputOptions(opts: InputOptions): this;
|
|
21
|
+
output(path: string, opts?: OutputOptions): this;
|
|
22
|
+
videoCodec(codec: OutputOptions["videoCodec"]): this;
|
|
23
|
+
audioCodec(codec: OutputOptions["audioCodec"]): this;
|
|
24
|
+
subtitleCodec(codec: OutputOptions["subtitleCodec"]): this;
|
|
25
|
+
videoBitrate(bitrate: OutputOptions["videoBitrate"]): this;
|
|
26
|
+
audioBitrate(bitrate: OutputOptions["audioBitrate"]): this;
|
|
27
|
+
crf(value: OutputOptions["crf"]): this;
|
|
28
|
+
size(value: OutputOptions["s"]): this;
|
|
29
|
+
pixelFormat(value: OutputOptions["pixFmt"]): this;
|
|
30
|
+
videoFilter(value: OutputOptions["vf"]): this;
|
|
31
|
+
audioFilter(value: OutputOptions["af"]): this;
|
|
32
|
+
noVideo(): this;
|
|
33
|
+
noAudio(): this;
|
|
34
|
+
noSubtitle(): this;
|
|
35
|
+
outputOptions(opts: OutputOptions): this;
|
|
36
|
+
filterComplex(filter: string | {
|
|
37
|
+
toString(): string;
|
|
38
|
+
}): this;
|
|
39
|
+
map(mapTarget: string): this;
|
|
40
|
+
mapInputStream(fileIndex: number, streamType?: MapStreamType, streamIndex?: number): this;
|
|
41
|
+
mapLabel(label: string | {
|
|
42
|
+
toString(): string;
|
|
43
|
+
}): this;
|
|
44
|
+
toArgs(): readonly string[];
|
|
45
|
+
toCommandLine(): string;
|
|
46
|
+
private validate;
|
|
47
|
+
build(): BuildResult;
|
|
48
|
+
}
|
|
49
|
+
declare function ffmpeg(): FFmpegBuilder;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { BuildResult, FFmpegBuilder, ffmpeg };
|
|
52
|
+
//# sourceMappingURL=builder.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.mts","names":[],"sources":["../src/builder.ts"],"mappings":";;;;UAUiB,WAAA;EACf,IAAI;AAAA;AAAA,cAaO,aAAA;EAAA,QACH,OAAA;EAAA,QACA,OAAA;EAAA,QACA,QAAA;EAAA,QACA,YAAA;EAAA,QAEA,YAAA;EAAA,QAQA,aAAA;EAQR,MAAA,CAAO,IAAA,EAAM,aAAA;EAKb,KAAA,CAAM,IAAA,UAAc,IAAA,GAAM,YAAA;EAK1B,SAAA,CAAU,QAAA,EAAU,YAAA;EAKpB,aAAA,CAAc,QAAA,EAAU,YAAA;EAKxB,WAAA,CAAY,MAAA,EAAQ,YAAA;EAKpB,YAAA,CAAa,IAAA,EAAM,YAAA;EAKnB,MAAA,CAAO,IAAA,UAAc,IAAA,GAAM,aAAA;EAK3B,UAAA,CAAW,KAAA,EAAO,aAAA;EAKlB,UAAA,CAAW,KAAA,EAAO,aAAA;EAKlB,aAAA,CAAc,KAAA,EAAO,aAAA;EAKrB,YAAA,CAAa,OAAA,EAAS,aAAA;EAKtB,YAAA,CAAa,OAAA,EAAS,aAAA;EAKtB,GAAA,CAAI,KAAA,EAAO,aAAA;EAKX,IAAA,CAAK,KAAA,EAAO,aAAA;EAKZ,WAAA,CAAY,KAAA,EAAO,aAAA;EAKnB,WAAA,CAAY,KAAA,EAAO,aAAA;EAKnB,WAAA,CAAY,KAAA,EAAO,aAAA;EAKnB,OAAA;EAKA,OAAA;EAKA,UAAA;EAKA,aAAA,CAAc,IAAA,EAAM,aAAA;EAKpB,aAAA,CAAc,MAAA;IAAmB,QAAA;EAAA;EAMjC,GAAA,CAAI,SAAA;EAaJ,cAAA,CAAe,SAAA,UAAmB,UAAA,GAAa,aAAA,EAAe,WAAA;EAI9D,QAAA,CAAS,KAAA;IAAkB,QAAA;EAAA;EAI3B,MAAA;EAIA,aAAA;EAAA,QAKQ,QAAA;EAwBR,KAAA,IAAS,WAAA;AAAA;AAAA,iBAoBK,MAAA,IAAU,aAAa"}
|
package/dist/builder.mjs
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { serializeGlobal, serializeInput, serializeOutput } from "./args.mjs";
|
|
2
|
+
import { FilterGraph } from "./filter-graph.mjs";
|
|
3
|
+
import { mapInputStream, mapLabel } from "./mapping.mjs";
|
|
4
|
+
//#region src/builder.ts
|
|
5
|
+
var FFmpegBuilder = class {
|
|
6
|
+
_global = {};
|
|
7
|
+
_inputs = [];
|
|
8
|
+
_outputs = [];
|
|
9
|
+
_filterGraph = null;
|
|
10
|
+
currentInput() {
|
|
11
|
+
const entry = this._inputs.at(-1);
|
|
12
|
+
if (!entry) throw new Error("No input defined. Call .input(...) before mutating input options.");
|
|
13
|
+
return entry;
|
|
14
|
+
}
|
|
15
|
+
currentOutput() {
|
|
16
|
+
const entry = this._outputs.at(-1);
|
|
17
|
+
if (!entry) throw new Error("No output defined. Call .output(...) before mutating output options.");
|
|
18
|
+
return entry;
|
|
19
|
+
}
|
|
20
|
+
global(opts) {
|
|
21
|
+
Object.assign(this._global, opts);
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
input(path, opts = {}) {
|
|
25
|
+
this._inputs.push({
|
|
26
|
+
path,
|
|
27
|
+
opts
|
|
28
|
+
});
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
seekInput(position) {
|
|
32
|
+
this.currentInput().opts.ss = position;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
inputDuration(duration) {
|
|
36
|
+
this.currentInput().opts.t = duration;
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
inputFormat(format) {
|
|
40
|
+
this.currentInput().opts.f = format;
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
inputOptions(opts) {
|
|
44
|
+
Object.assign(this.currentInput().opts, opts);
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
output(path, opts = {}) {
|
|
48
|
+
this._outputs.push({
|
|
49
|
+
path,
|
|
50
|
+
opts
|
|
51
|
+
});
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
videoCodec(codec) {
|
|
55
|
+
this.currentOutput().opts.videoCodec = codec;
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
audioCodec(codec) {
|
|
59
|
+
this.currentOutput().opts.audioCodec = codec;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
subtitleCodec(codec) {
|
|
63
|
+
this.currentOutput().opts.subtitleCodec = codec;
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
videoBitrate(bitrate) {
|
|
67
|
+
this.currentOutput().opts.videoBitrate = bitrate;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
audioBitrate(bitrate) {
|
|
71
|
+
this.currentOutput().opts.audioBitrate = bitrate;
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
crf(value) {
|
|
75
|
+
this.currentOutput().opts.crf = value;
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
size(value) {
|
|
79
|
+
this.currentOutput().opts.s = value;
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
pixelFormat(value) {
|
|
83
|
+
this.currentOutput().opts.pixFmt = value;
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
videoFilter(value) {
|
|
87
|
+
this.currentOutput().opts.vf = value;
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
audioFilter(value) {
|
|
91
|
+
this.currentOutput().opts.af = value;
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
noVideo() {
|
|
95
|
+
this.currentOutput().opts.vn = true;
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
noAudio() {
|
|
99
|
+
this.currentOutput().opts.an = true;
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
noSubtitle() {
|
|
103
|
+
this.currentOutput().opts.sn = true;
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
outputOptions(opts) {
|
|
107
|
+
Object.assign(this.currentOutput().opts, opts);
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
filterComplex(filter) {
|
|
111
|
+
this._global.filterComplex = String(filter);
|
|
112
|
+
this._filterGraph = filter instanceof FilterGraph ? filter : null;
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
map(mapTarget) {
|
|
116
|
+
const output = this.currentOutput();
|
|
117
|
+
const existing = output.opts.map;
|
|
118
|
+
if (Array.isArray(existing)) existing.push(mapTarget);
|
|
119
|
+
else if (typeof existing === "string") output.opts.map = [existing, mapTarget];
|
|
120
|
+
else output.opts.map = [mapTarget];
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
mapInputStream(fileIndex, streamType, streamIndex) {
|
|
124
|
+
return this.map(mapInputStream(fileIndex, streamType, streamIndex));
|
|
125
|
+
}
|
|
126
|
+
mapLabel(label) {
|
|
127
|
+
return this.map(mapLabel(String(label)));
|
|
128
|
+
}
|
|
129
|
+
toArgs() {
|
|
130
|
+
return this.build().args;
|
|
131
|
+
}
|
|
132
|
+
toCommandLine() {
|
|
133
|
+
return this.toArgs().map(quoteShellArg).join(" ");
|
|
134
|
+
}
|
|
135
|
+
validate() {
|
|
136
|
+
if (this._outputs.length === 0 && this._inputs.length > 0) throw new Error("No output defined. Call .output(...) before build().");
|
|
137
|
+
if (!this._filterGraph) return;
|
|
138
|
+
for (const output of this._outputs) {
|
|
139
|
+
const maps = output.opts.map;
|
|
140
|
+
const values = maps === void 0 ? [] : Array.isArray(maps) ? maps : [maps];
|
|
141
|
+
for (const value of values) {
|
|
142
|
+
if (!value.startsWith("[") || !value.endsWith("]")) continue;
|
|
143
|
+
const label = value.slice(1, -1);
|
|
144
|
+
if (!this._filterGraph.hasOutputLabel(label)) throw new Error(`Mapped filter label "${label}" is not defined in the current filter graph`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
build() {
|
|
149
|
+
this.validate();
|
|
150
|
+
const args = [];
|
|
151
|
+
args.push(...serializeGlobal(this._global));
|
|
152
|
+
for (const entry of this._inputs) {
|
|
153
|
+
args.push(...serializeInput(entry.opts));
|
|
154
|
+
args.push("-i", entry.path);
|
|
155
|
+
}
|
|
156
|
+
for (const entry of this._outputs) {
|
|
157
|
+
args.push(...serializeOutput(entry.opts));
|
|
158
|
+
args.push(entry.path);
|
|
159
|
+
}
|
|
160
|
+
return { args };
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
function ffmpeg() {
|
|
164
|
+
return new FFmpegBuilder();
|
|
165
|
+
}
|
|
166
|
+
function quoteShellArg(value) {
|
|
167
|
+
if (value.length === 0) return "''";
|
|
168
|
+
if (/^[A-Za-z0-9_./:[\]-]+$/.test(value)) return value;
|
|
169
|
+
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
172
|
+
export { FFmpegBuilder, ffmpeg };
|
|
173
|
+
|
|
174
|
+
//# sourceMappingURL=builder.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.mjs","names":["serializeMapInputStream","serializeMapLabel"],"sources":["../src/builder.ts"],"sourcesContent":["import type { GlobalOptions, InputOptions, OutputOptions } from \"./types.ts\";\n\nimport { serializeGlobal, serializeInput, serializeOutput } from \"./args.ts\";\nimport { FilterGraph } from \"./filter-graph.ts\";\nimport {\n mapInputStream as serializeMapInputStream,\n mapLabel as serializeMapLabel,\n type MapStreamType,\n} from \"./mapping.ts\";\n\nexport interface BuildResult {\n args: readonly string[];\n}\n\ninterface InputEntry {\n path: string;\n opts: InputOptions;\n}\n\ninterface OutputEntry {\n path: string;\n opts: OutputOptions;\n}\n\nexport class FFmpegBuilder {\n private _global: GlobalOptions = {};\n private _inputs: InputEntry[] = [];\n private _outputs: OutputEntry[] = [];\n private _filterGraph: FilterGraph | null = null;\n\n private currentInput(): InputEntry {\n const entry = this._inputs.at(-1);\n if (!entry) {\n throw new Error(\"No input defined. Call .input(...) before mutating input options.\");\n }\n return entry;\n }\n\n private currentOutput(): OutputEntry {\n const entry = this._outputs.at(-1);\n if (!entry) {\n throw new Error(\"No output defined. Call .output(...) before mutating output options.\");\n }\n return entry;\n }\n\n global(opts: GlobalOptions): this {\n Object.assign(this._global, opts);\n return this;\n }\n\n input(path: string, opts: InputOptions = {}): this {\n this._inputs.push({ path, opts });\n return this;\n }\n\n seekInput(position: InputOptions[\"ss\"]): this {\n this.currentInput().opts.ss = position;\n return this;\n }\n\n inputDuration(duration: InputOptions[\"t\"]): this {\n this.currentInput().opts.t = duration;\n return this;\n }\n\n inputFormat(format: InputOptions[\"f\"]): this {\n this.currentInput().opts.f = format;\n return this;\n }\n\n inputOptions(opts: InputOptions): this {\n Object.assign(this.currentInput().opts, opts);\n return this;\n }\n\n output(path: string, opts: OutputOptions = {}): this {\n this._outputs.push({ path, opts });\n return this;\n }\n\n videoCodec(codec: OutputOptions[\"videoCodec\"]): this {\n this.currentOutput().opts.videoCodec = codec;\n return this;\n }\n\n audioCodec(codec: OutputOptions[\"audioCodec\"]): this {\n this.currentOutput().opts.audioCodec = codec;\n return this;\n }\n\n subtitleCodec(codec: OutputOptions[\"subtitleCodec\"]): this {\n this.currentOutput().opts.subtitleCodec = codec;\n return this;\n }\n\n videoBitrate(bitrate: OutputOptions[\"videoBitrate\"]): this {\n this.currentOutput().opts.videoBitrate = bitrate;\n return this;\n }\n\n audioBitrate(bitrate: OutputOptions[\"audioBitrate\"]): this {\n this.currentOutput().opts.audioBitrate = bitrate;\n return this;\n }\n\n crf(value: OutputOptions[\"crf\"]): this {\n this.currentOutput().opts.crf = value;\n return this;\n }\n\n size(value: OutputOptions[\"s\"]): this {\n this.currentOutput().opts.s = value;\n return this;\n }\n\n pixelFormat(value: OutputOptions[\"pixFmt\"]): this {\n this.currentOutput().opts.pixFmt = value;\n return this;\n }\n\n videoFilter(value: OutputOptions[\"vf\"]): this {\n this.currentOutput().opts.vf = value;\n return this;\n }\n\n audioFilter(value: OutputOptions[\"af\"]): this {\n this.currentOutput().opts.af = value;\n return this;\n }\n\n noVideo(): this {\n this.currentOutput().opts.vn = true;\n return this;\n }\n\n noAudio(): this {\n this.currentOutput().opts.an = true;\n return this;\n }\n\n noSubtitle(): this {\n this.currentOutput().opts.sn = true;\n return this;\n }\n\n outputOptions(opts: OutputOptions): this {\n Object.assign(this.currentOutput().opts, opts);\n return this;\n }\n\n filterComplex(filter: string | { toString(): string }): this {\n this._global.filterComplex = String(filter);\n this._filterGraph = filter instanceof FilterGraph ? filter : null;\n return this;\n }\n\n map(mapTarget: string): this {\n const output = this.currentOutput();\n const existing = output.opts.map;\n if (Array.isArray(existing)) {\n existing.push(mapTarget);\n } else if (typeof existing === \"string\") {\n output.opts.map = [existing, mapTarget];\n } else {\n output.opts.map = [mapTarget];\n }\n return this;\n }\n\n mapInputStream(fileIndex: number, streamType?: MapStreamType, streamIndex?: number): this {\n return this.map(serializeMapInputStream(fileIndex, streamType, streamIndex));\n }\n\n mapLabel(label: string | { toString(): string }): this {\n return this.map(serializeMapLabel(String(label)));\n }\n\n toArgs(): readonly string[] {\n return this.build().args;\n }\n\n toCommandLine(): string {\n const args = this.toArgs();\n return args.map(quoteShellArg).join(\" \");\n }\n\n private validate(): void {\n if (this._outputs.length === 0 && this._inputs.length > 0) {\n throw new Error(\"No output defined. Call .output(...) before build().\");\n }\n\n if (!this._filterGraph) {\n return;\n }\n\n for (const output of this._outputs) {\n const maps = output.opts.map;\n const values = maps === undefined ? [] : Array.isArray(maps) ? maps : [maps];\n for (const value of values) {\n if (!value.startsWith(\"[\") || !value.endsWith(\"]\")) continue;\n const label = value.slice(1, -1);\n if (!this._filterGraph.hasOutputLabel(label)) {\n throw new Error(\n `Mapped filter label \"${label}\" is not defined in the current filter graph`,\n );\n }\n }\n }\n }\n\n build(): BuildResult {\n this.validate();\n const args: string[] = [];\n\n args.push(...serializeGlobal(this._global));\n\n for (const entry of this._inputs) {\n args.push(...serializeInput(entry.opts));\n args.push(\"-i\", entry.path);\n }\n\n for (const entry of this._outputs) {\n args.push(...serializeOutput(entry.opts));\n args.push(entry.path);\n }\n\n return { args };\n }\n}\n\nexport function ffmpeg(): FFmpegBuilder {\n return new FFmpegBuilder();\n}\n\nfunction quoteShellArg(value: string): string {\n if (value.length === 0) {\n return \"''\";\n }\n\n if (/^[A-Za-z0-9_./:[\\]-]+$/.test(value)) {\n return value;\n }\n\n return `'${value.replace(/'/g, `'\\\\''`)}'`;\n}\n"],"mappings":";;;;AAwBA,IAAa,gBAAb,MAA2B;CACzB,UAAiC,CAAC;CAClC,UAAgC,CAAC;CACjC,WAAkC,CAAC;CACnC,eAA2C;CAE3C,eAAmC;EACjC,MAAM,QAAQ,KAAK,QAAQ,GAAG,EAAE;EAChC,IAAI,CAAC,OACH,MAAM,IAAI,MAAM,mEAAmE;EAErF,OAAO;CACT;CAEA,gBAAqC;EACnC,MAAM,QAAQ,KAAK,SAAS,GAAG,EAAE;EACjC,IAAI,CAAC,OACH,MAAM,IAAI,MAAM,sEAAsE;EAExF,OAAO;CACT;CAEA,OAAO,MAA2B;EAChC,OAAO,OAAO,KAAK,SAAS,IAAI;EAChC,OAAO;CACT;CAEA,MAAM,MAAc,OAAqB,CAAC,GAAS;EACjD,KAAK,QAAQ,KAAK;GAAE;GAAM;EAAK,CAAC;EAChC,OAAO;CACT;CAEA,UAAU,UAAoC;EAC5C,KAAK,aAAa,EAAE,KAAK,KAAK;EAC9B,O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,MAAM,MAAM,GAAG,EAAE;IAC/B,IAAI,CAAC,KAAK,aAAa,eAAe,KAAK,GACzC,MAAM,IAAI,MACR,wBAAwB,MAAM,6CAChC;GAEJ;EACF;CACF;CAEA,QAAqB;EACnB,KAAK,SAAS;EACd,MAAM,OAAiB,CAAC;EAExB,KAAK,KAAK,GAAG,gBAAgB,KAAK,OAAO,CAAC;EAE1C,KAAK,MAAM,SAAS,KAAK,SAAS;GAChC,KAAK,KAAK,GAAG,eAAe,MAAM,IAAI,CAAC;GACvC,KAAK,KAAK,MAAM,MAAM,IAAI;EAC5B;EAEA,KAAK,MAAM,SAAS,KAAK,UAAU;GACjC,KAAK,KAAK,GAAG,gBAAgB,MAAM,IAAI,CAAC;GACxC,KAAK,KAAK,MAAM,IAAI;EACtB;EAEA,OAAO,EAAE,KAAK;CAChB;AACF;AAEA,SAAgB,SAAwB;CACtC,OAAO,IAAI,cAAc;AAC3B;AAEA,SAAS,cAAc,OAAuB;CAC5C,IAAI,MAAM,WAAW,GACnB,OAAO;CAGT,IAAI,yBAAyB,KAAK,KAAK,GACrC,OAAO;CAGT,OAAO,IAAI,MAAM,QAAQ,MAAM,OAAO,EAAE;AAC1C"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
//#region src/filter-graph.d.ts
|
|
2
|
+
type FilterGraphMediaType = "video" | "audio" | "unknown";
|
|
3
|
+
type FilterScalar = string | number | boolean;
|
|
4
|
+
type FilterNamedOptions = Record<string, FilterScalar | undefined>;
|
|
5
|
+
interface FilterNodeSpec {
|
|
6
|
+
name: string;
|
|
7
|
+
positional?: readonly FilterScalar[];
|
|
8
|
+
named?: FilterNamedOptions;
|
|
9
|
+
}
|
|
10
|
+
interface TrimOptions {
|
|
11
|
+
start?: string | number;
|
|
12
|
+
end?: string | number;
|
|
13
|
+
duration?: string | number;
|
|
14
|
+
startFrame?: number;
|
|
15
|
+
endFrame?: number;
|
|
16
|
+
}
|
|
17
|
+
interface OverlayOptions {
|
|
18
|
+
x?: string | number;
|
|
19
|
+
y?: string | number;
|
|
20
|
+
eofAction?: string;
|
|
21
|
+
shortest?: boolean;
|
|
22
|
+
repeatlast?: boolean;
|
|
23
|
+
}
|
|
24
|
+
interface AmixOptions {
|
|
25
|
+
inputs?: number;
|
|
26
|
+
duration?: string;
|
|
27
|
+
dropoutTransition?: number;
|
|
28
|
+
normalize?: boolean;
|
|
29
|
+
}
|
|
30
|
+
interface ConcatOptions {
|
|
31
|
+
segments: number;
|
|
32
|
+
videoStreams?: number;
|
|
33
|
+
audioStreams?: number;
|
|
34
|
+
unsafe?: boolean;
|
|
35
|
+
}
|
|
36
|
+
declare function resetFilterGraphLabelCounter(): void;
|
|
37
|
+
declare class FilterGraphStream {
|
|
38
|
+
readonly label: string;
|
|
39
|
+
readonly mediaType: FilterGraphMediaType;
|
|
40
|
+
constructor(label: string, mediaType: FilterGraphMediaType);
|
|
41
|
+
toString(): string;
|
|
42
|
+
}
|
|
43
|
+
declare class FilterGraphChain {
|
|
44
|
+
private readonly filters;
|
|
45
|
+
private readonly graph;
|
|
46
|
+
private readonly inputs;
|
|
47
|
+
private readonly outputMediaTypes;
|
|
48
|
+
constructor(graph: FilterGraph, inputs: readonly FilterGraphStream[], outputMediaTypes: readonly FilterGraphMediaType[]);
|
|
49
|
+
raw(filter: string): this;
|
|
50
|
+
filter(name: string, positional?: readonly FilterScalar[], named?: FilterNamedOptions): this;
|
|
51
|
+
scale(width: string | number, height: string | number, named?: FilterNamedOptions): this;
|
|
52
|
+
fps(rate: string | number): this;
|
|
53
|
+
format(pixelFormat: string): this;
|
|
54
|
+
trim(options: TrimOptions): this;
|
|
55
|
+
setpts(expression: string): this;
|
|
56
|
+
asetpts(expression: string): this;
|
|
57
|
+
hflip(): this;
|
|
58
|
+
vflip(): this;
|
|
59
|
+
volume(value: string | number): this;
|
|
60
|
+
atempo(value: number): this;
|
|
61
|
+
split(...labels: string[]): FilterGraphStream[];
|
|
62
|
+
asplit(...labels: string[]): FilterGraphStream[];
|
|
63
|
+
label(label: string): FilterGraphStream;
|
|
64
|
+
labels(...labels: string[]): FilterGraphStream[];
|
|
65
|
+
autoLabel(prefix?: string): FilterGraphStream;
|
|
66
|
+
private commit;
|
|
67
|
+
}
|
|
68
|
+
declare class FilterGraph {
|
|
69
|
+
private readonly segments;
|
|
70
|
+
private readonly outputLabels;
|
|
71
|
+
addSegment(segment: string, labels: readonly string[]): void;
|
|
72
|
+
hasOutputLabel(label: string): boolean;
|
|
73
|
+
getOutputLabels(): string[];
|
|
74
|
+
input(index: number, streamType?: "v" | "a" | "s" | "d" | "t", streamIndex?: number): FilterGraphStream;
|
|
75
|
+
videoInput(index: number, streamIndex?: number): FilterGraphChain;
|
|
76
|
+
audioInput(index: number, streamIndex?: number): FilterGraphChain;
|
|
77
|
+
from(...streams: readonly FilterGraphStream[]): FilterGraphChain;
|
|
78
|
+
overlay(main: FilterGraphStream, overlay: FilterGraphStream, options?: OverlayOptions): FilterGraphChain;
|
|
79
|
+
amerge(...streams: readonly FilterGraphStream[]): FilterGraphChain;
|
|
80
|
+
amix(streams: readonly FilterGraphStream[], options?: AmixOptions): FilterGraphChain;
|
|
81
|
+
concat(streams: readonly FilterGraphStream[], options: ConcatOptions): FilterGraphChain;
|
|
82
|
+
toString(): string;
|
|
83
|
+
}
|
|
84
|
+
declare function filterGraph(): FilterGraph;
|
|
85
|
+
//#endregion
|
|
86
|
+
export { AmixOptions, ConcatOptions, FilterGraph, FilterGraphMediaType, FilterGraphStream, FilterNamedOptions, FilterNodeSpec, FilterScalar, OverlayOptions, TrimOptions, filterGraph, resetFilterGraphLabelCounter };
|
|
87
|
+
//# sourceMappingURL=filter-graph.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter-graph.d.mts","names":[],"sources":["../src/filter-graph.ts"],"mappings":";KAAY,oBAAA;AAAA,KAEA,YAAA;AAAA,KAEA,kBAAA,GAAqB,MAAM,SAAS,YAAA;AAAA,UAE/B,cAAA;EACf,IAA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