@verygoodffmpeg/sdk 1.1.1 → 1.1.2
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/README.md +24 -4
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ const job = await client.run(
|
|
|
24
24
|
"input.mp4": "https://example.com/input.mp4",
|
|
25
25
|
},
|
|
26
26
|
output_files: ["output.mp4"],
|
|
27
|
-
ffmpeg_commands: ["-i input.mp4 -vf scale=1280:720 output.mp4"],
|
|
27
|
+
ffmpeg_commands: ["-i inputs/input.mp4 -vf scale=1280:720 outputs/output.mp4"],
|
|
28
28
|
},
|
|
29
29
|
{ wait: true },
|
|
30
30
|
);
|
|
@@ -56,7 +56,7 @@ const job = await client.run(
|
|
|
56
56
|
{
|
|
57
57
|
input_files: { "input.mp4": "https://example.com/input.mp4" },
|
|
58
58
|
output_files: ["output.mp4"],
|
|
59
|
-
ffmpeg_commands: ["-i input.mp4 -c:v libx264 output.mp4"],
|
|
59
|
+
ffmpeg_commands: ["-i inputs/input.mp4 -c:v libx264 outputs/output.mp4"],
|
|
60
60
|
webhook_url: "https://example.com/webhook", // optional
|
|
61
61
|
machine: "nvidia", // optional: "cpu" | "nvidia"
|
|
62
62
|
},
|
|
@@ -64,6 +64,8 @@ const job = await client.run(
|
|
|
64
64
|
);
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
+
See [Running Commands](https://verygoodffmpeg.com/docs/basics/running-commands) for how commands are executed.
|
|
68
|
+
|
|
67
69
|
### Get a job — `client.jobs.get(id)`
|
|
68
70
|
|
|
69
71
|
Fetches a single job by ID.
|
|
@@ -104,7 +106,7 @@ const url = await client.files.upload(readFileSync("input.mp4"), "video/mp4");
|
|
|
104
106
|
const job = await client.run({
|
|
105
107
|
input_files: { "input.mp4": url },
|
|
106
108
|
output_files: ["output.mp4"],
|
|
107
|
-
ffmpeg_commands: ["-i input.mp4 -vf scale=1280:720 output.mp4"],
|
|
109
|
+
ffmpeg_commands: ["-i inputs/input.mp4 -vf scale=1280:720 outputs/output.mp4"],
|
|
108
110
|
});
|
|
109
111
|
```
|
|
110
112
|
|
|
@@ -130,10 +132,28 @@ await fetch(upload_url, {
|
|
|
130
132
|
const job = await client.run({
|
|
131
133
|
input_files: { "input.mp4": download_url },
|
|
132
134
|
output_files: ["output.mp4"],
|
|
133
|
-
ffmpeg_commands: ["-i input.mp4 -vf scale=1280:720 output.mp4"],
|
|
135
|
+
ffmpeg_commands: ["-i inputs/input.mp4 -vf scale=1280:720 outputs/output.mp4"],
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Referencing files in commands
|
|
140
|
+
|
|
141
|
+
Every job runs in a workspace with two directories. Each entry in `input_files` is downloaded into `inputs` under its key name, and every file your commands write to `outputs` that is listed in `output_files` is uploaded and returned as a download URL.
|
|
142
|
+
|
|
143
|
+
Reference files with plain paths — `inputs/<name>` to read, `outputs/<name>` to write:
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
await client.run({
|
|
147
|
+
input_files: { "input.mp4": "https://example.com/video.mp4" },
|
|
148
|
+
output_files: ["output.wav"],
|
|
149
|
+
ffmpeg_commands: ["-i inputs/input.mp4 -vn outputs/output.wav"],
|
|
134
150
|
});
|
|
135
151
|
```
|
|
136
152
|
|
|
153
|
+
Paths work anywhere in the command string, including inside `-filter_complex`, and they are real paths on the worker, so the command is the same one you would run locally.
|
|
154
|
+
|
|
155
|
+
See [File Reference Styles](https://verygoodffmpeg.com/docs/advanced/file-reference-styles) for more.
|
|
156
|
+
|
|
137
157
|
## Complete examples
|
|
138
158
|
|
|
139
159
|
See the [`examples/`](./examples) folder for minimal runnable examples:
|
package/dist/index.cjs
CHANGED
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/error.ts","../src/index.ts","../src/version.ts"],"sourcesContent":["export class VGFError extends Error {\n readonly status: number;\n readonly body: string;\n\n constructor(status: number, body: string) {\n super(`VGF API error ${status}: ${body}`);\n this.name = \"VGFError\";\n this.status = status;\n this.body = body;\n }\n}\n","import { USER_AGENT } from \"./version.js\";\nimport type {\n Job,\n RunParams,\n RunOptions,\n ListJobsParams,\n PagingParams,\n TmpFile,\n} from \"./types.js\";\n\nexport type {\n Job,\n RunParams,\n RunOptions,\n ListJobsParams,\n PagingParams,\n TmpFile,\n};\nexport { VGFError } from \"./error.js\";\nexport { VERSION } from \"./version.js\";\n\nconst BASE_URL = \"https://verygoodffmpeg.com/api\";\n\nexport class VGF {\n readonly jobs: Jobs;\n readonly files: Files;\n\n private apiKey: string;\n private baseUrl: string;\n private userAgent: string;\n\n constructor(\n apiKey: string,\n options?: { baseUrl?: string; userAgentSuffix?: string },\n ) {\n if (!apiKey) throw new Error(\"API key is required\");\n this.apiKey = apiKey;\n this.baseUrl = options?.baseUrl ?? BASE_URL;\n\n // callers building on top of the SDK may append their own product token\n const suffix = options?.userAgentSuffix?.trim();\n this.userAgent = suffix ? `${USER_AGENT} ${suffix}` : USER_AGENT;\n\n this.jobs = new Jobs(this);\n this.files = new Files(this);\n }\n\n async run(params: RunParams, options: RunOptions = {}): Promise<Job> {\n const qs = options.wait ? \"?wait=true\" : \"\";\n const body = {\n input_files: params.input_files,\n output_files: params.output_files,\n ffmpeg_commands: params.ffmpeg_commands,\n webhook_url: params.webhook_url,\n machine: params.machine,\n timeout_seconds: params.timeout_seconds,\n };\n const res = await this._request<{ data: Job }>(\n \"POST\",\n `/ffmpeg${qs}`,\n body,\n );\n return res.data;\n }\n\n /** @internal */\n async _request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const res = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n \"User-Agent\": this.userAgent,\n // \"Content-Type\": \"application/json\",\n },\n body: body != null ? JSON.stringify(body) : undefined,\n });\n\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n const { VGFError } = await import(\"./error.js\");\n throw new VGFError(res.status, text);\n }\n\n return res.json() as Promise<T>;\n }\n}\n\nclass Jobs {\n constructor(private client: VGF) {}\n\n async list(\n params: ListJobsParams = {},\n ): Promise<{ data: Job[]; pagingParams: PagingParams }> {\n const qs = new URLSearchParams();\n if (params.limit != null) qs.set(\"limit\", String(params.limit));\n if (params.offset != null) qs.set(\"offset\", String(params.offset));\n const query = qs.size ? `?${qs}` : \"\";\n return this.client._request(\"GET\", `/jobs${query}`);\n }\n\n async get(id: string): Promise<Job> {\n const res = await this.client._request<{ data: Job }>(\n \"GET\",\n `/jobs/${encodeURIComponent(id)}`,\n );\n return res.data;\n }\n\n async cancel(id: string): Promise<Job> {\n const res = await this.client._request<{ data: Job }>(\n \"POST\",\n `/jobs/${encodeURIComponent(id)}/cancel`,\n );\n return res.data;\n }\n}\n\nclass Files {\n constructor(private client: VGF) {}\n\n async prepareUpload(): Promise<TmpFile> {\n const res = await this.client._request<{ data: TmpFile }>(\n \"POST\",\n \"/tmp-file\",\n );\n return res.data;\n }\n\n /**\n * Uploads a file to temporary storage and returns the download URL,\n * which can be used as an input_files value in a job.\n */\n async upload(\n data: Buffer | Blob | ReadableStream | Uint8Array,\n contentType = \"application/octet-stream\",\n ): Promise<string> {\n const { upload_url, download_url } = await this.prepareUpload();\n const res = await fetch(upload_url, {\n method: \"PUT\",\n headers: { \"Content-Type\": contentType },\n body: data as BodyInit,\n });\n if (!res.ok) {\n const { VGFError } = await import(\"./error.js\");\n throw new VGFError(res.status, `File upload failed: ${res.statusText}`);\n }\n return download_url;\n }\n}\n\nexport default VGF;\n","// Generated by scripts/generate-version.mjs. Do not edit.\n\n/**\n * Version of this SDK, mirrored from package.json at build time.\n */\nexport const VERSION = \"1.1.
|
|
1
|
+
{"version":3,"sources":["../src/error.ts","../src/index.ts","../src/version.ts"],"sourcesContent":["export class VGFError extends Error {\n readonly status: number;\n readonly body: string;\n\n constructor(status: number, body: string) {\n super(`VGF API error ${status}: ${body}`);\n this.name = \"VGFError\";\n this.status = status;\n this.body = body;\n }\n}\n","import { USER_AGENT } from \"./version.js\";\nimport type {\n Job,\n RunParams,\n RunOptions,\n ListJobsParams,\n PagingParams,\n TmpFile,\n} from \"./types.js\";\n\nexport type {\n Job,\n RunParams,\n RunOptions,\n ListJobsParams,\n PagingParams,\n TmpFile,\n};\nexport { VGFError } from \"./error.js\";\nexport { VERSION } from \"./version.js\";\n\nconst BASE_URL = \"https://verygoodffmpeg.com/api\";\n\nexport class VGF {\n readonly jobs: Jobs;\n readonly files: Files;\n\n private apiKey: string;\n private baseUrl: string;\n private userAgent: string;\n\n constructor(\n apiKey: string,\n options?: { baseUrl?: string; userAgentSuffix?: string },\n ) {\n if (!apiKey) throw new Error(\"API key is required\");\n this.apiKey = apiKey;\n this.baseUrl = options?.baseUrl ?? BASE_URL;\n\n // callers building on top of the SDK may append their own product token\n const suffix = options?.userAgentSuffix?.trim();\n this.userAgent = suffix ? `${USER_AGENT} ${suffix}` : USER_AGENT;\n\n this.jobs = new Jobs(this);\n this.files = new Files(this);\n }\n\n async run(params: RunParams, options: RunOptions = {}): Promise<Job> {\n const qs = options.wait ? \"?wait=true\" : \"\";\n const body = {\n input_files: params.input_files,\n output_files: params.output_files,\n ffmpeg_commands: params.ffmpeg_commands,\n webhook_url: params.webhook_url,\n machine: params.machine,\n timeout_seconds: params.timeout_seconds,\n };\n const res = await this._request<{ data: Job }>(\n \"POST\",\n `/ffmpeg${qs}`,\n body,\n );\n return res.data;\n }\n\n /** @internal */\n async _request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const res = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n \"User-Agent\": this.userAgent,\n // \"Content-Type\": \"application/json\",\n },\n body: body != null ? JSON.stringify(body) : undefined,\n });\n\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n const { VGFError } = await import(\"./error.js\");\n throw new VGFError(res.status, text);\n }\n\n return res.json() as Promise<T>;\n }\n}\n\nclass Jobs {\n constructor(private client: VGF) {}\n\n async list(\n params: ListJobsParams = {},\n ): Promise<{ data: Job[]; pagingParams: PagingParams }> {\n const qs = new URLSearchParams();\n if (params.limit != null) qs.set(\"limit\", String(params.limit));\n if (params.offset != null) qs.set(\"offset\", String(params.offset));\n const query = qs.size ? `?${qs}` : \"\";\n return this.client._request(\"GET\", `/jobs${query}`);\n }\n\n async get(id: string): Promise<Job> {\n const res = await this.client._request<{ data: Job }>(\n \"GET\",\n `/jobs/${encodeURIComponent(id)}`,\n );\n return res.data;\n }\n\n async cancel(id: string): Promise<Job> {\n const res = await this.client._request<{ data: Job }>(\n \"POST\",\n `/jobs/${encodeURIComponent(id)}/cancel`,\n );\n return res.data;\n }\n}\n\nclass Files {\n constructor(private client: VGF) {}\n\n async prepareUpload(): Promise<TmpFile> {\n const res = await this.client._request<{ data: TmpFile }>(\n \"POST\",\n \"/tmp-file\",\n );\n return res.data;\n }\n\n /**\n * Uploads a file to temporary storage and returns the download URL,\n * which can be used as an input_files value in a job.\n */\n async upload(\n data: Buffer | Blob | ReadableStream | Uint8Array,\n contentType = \"application/octet-stream\",\n ): Promise<string> {\n const { upload_url, download_url } = await this.prepareUpload();\n const res = await fetch(upload_url, {\n method: \"PUT\",\n headers: { \"Content-Type\": contentType },\n body: data as BodyInit,\n });\n if (!res.ok) {\n const { VGFError } = await import(\"./error.js\");\n throw new VGFError(res.status, `File upload failed: ${res.statusText}`);\n }\n return download_url;\n }\n}\n\nexport default VGF;\n","// Generated by scripts/generate-version.mjs. Do not edit.\n\n/**\n * Version of this SDK, mirrored from package.json at build time.\n */\nexport const VERSION = \"1.1.2\";\n\n/**\n * User-Agent sent with every API request.\n */\nexport const USER_AGENT = `verygoodffmpeg-sdk/${VERSION}`;\n"],"mappings":";;;;;;;;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M,QAAN,MAAY;AAAA,EACV,YAAoB,QAAa;AAAb;AAAA,EAAc;AAAA,EAAd;AAAA,EAEpB,MAAM,gBAAkC;AACtC,UAAM,MAAM,MAAM,KAAK,OAAO;AAAA,MAC5B;AAAA,MACA;AAAA,IACF;AACA,WAAO,IAAI;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,OACJ,MACA,cAAc,4BACG;AACjB,UAAM,EAAE,YAAY,aAAa,IAAI,MAAM,KAAK,cAAc;AAC9D,UAAM,MAAM,MAAM,MAAM,YAAY;AAAA,MAClC,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,YAAY;AAAA,MACvC,MAAM;AAAA,IACR,CAAC;AACD,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,EAAE,UAAAA,UAAS,IAAI,MAAM;AAC3B,YAAM,IAAIA,UAAS,IAAI,QAAQ,uBAAuB,IAAI,UAAU,EAAE;AAAA,IACxE;AACA,WAAO;AAAA,EACT;AACF;AAEA,IAAO,gBAAQ;","names":["VGFError"]}
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/version.ts","../src/index.ts"],"sourcesContent":["// Generated by scripts/generate-version.mjs. Do not edit.\n\n/**\n * Version of this SDK, mirrored from package.json at build time.\n */\nexport const VERSION = \"1.1.
|
|
1
|
+
{"version":3,"sources":["../src/version.ts","../src/index.ts"],"sourcesContent":["// Generated by scripts/generate-version.mjs. Do not edit.\n\n/**\n * Version of this SDK, mirrored from package.json at build time.\n */\nexport const VERSION = \"1.1.2\";\n\n/**\n * User-Agent sent with every API request.\n */\nexport const USER_AGENT = `verygoodffmpeg-sdk/${VERSION}`;\n","import { USER_AGENT } from \"./version.js\";\nimport type {\n Job,\n RunParams,\n RunOptions,\n ListJobsParams,\n PagingParams,\n TmpFile,\n} from \"./types.js\";\n\nexport type {\n Job,\n RunParams,\n RunOptions,\n ListJobsParams,\n PagingParams,\n TmpFile,\n};\nexport { VGFError } from \"./error.js\";\nexport { VERSION } from \"./version.js\";\n\nconst BASE_URL = \"https://verygoodffmpeg.com/api\";\n\nexport class VGF {\n readonly jobs: Jobs;\n readonly files: Files;\n\n private apiKey: string;\n private baseUrl: string;\n private userAgent: string;\n\n constructor(\n apiKey: string,\n options?: { baseUrl?: string; userAgentSuffix?: string },\n ) {\n if (!apiKey) throw new Error(\"API key is required\");\n this.apiKey = apiKey;\n this.baseUrl = options?.baseUrl ?? BASE_URL;\n\n // callers building on top of the SDK may append their own product token\n const suffix = options?.userAgentSuffix?.trim();\n this.userAgent = suffix ? `${USER_AGENT} ${suffix}` : USER_AGENT;\n\n this.jobs = new Jobs(this);\n this.files = new Files(this);\n }\n\n async run(params: RunParams, options: RunOptions = {}): Promise<Job> {\n const qs = options.wait ? \"?wait=true\" : \"\";\n const body = {\n input_files: params.input_files,\n output_files: params.output_files,\n ffmpeg_commands: params.ffmpeg_commands,\n webhook_url: params.webhook_url,\n machine: params.machine,\n timeout_seconds: params.timeout_seconds,\n };\n const res = await this._request<{ data: Job }>(\n \"POST\",\n `/ffmpeg${qs}`,\n body,\n );\n return res.data;\n }\n\n /** @internal */\n async _request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const res = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n \"User-Agent\": this.userAgent,\n // \"Content-Type\": \"application/json\",\n },\n body: body != null ? JSON.stringify(body) : undefined,\n });\n\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n const { VGFError } = await import(\"./error.js\");\n throw new VGFError(res.status, text);\n }\n\n return res.json() as Promise<T>;\n }\n}\n\nclass Jobs {\n constructor(private client: VGF) {}\n\n async list(\n params: ListJobsParams = {},\n ): Promise<{ data: Job[]; pagingParams: PagingParams }> {\n const qs = new URLSearchParams();\n if (params.limit != null) qs.set(\"limit\", String(params.limit));\n if (params.offset != null) qs.set(\"offset\", String(params.offset));\n const query = qs.size ? `?${qs}` : \"\";\n return this.client._request(\"GET\", `/jobs${query}`);\n }\n\n async get(id: string): Promise<Job> {\n const res = await this.client._request<{ data: Job }>(\n \"GET\",\n `/jobs/${encodeURIComponent(id)}`,\n );\n return res.data;\n }\n\n async cancel(id: string): Promise<Job> {\n const res = await this.client._request<{ data: Job }>(\n \"POST\",\n `/jobs/${encodeURIComponent(id)}/cancel`,\n );\n return res.data;\n }\n}\n\nclass Files {\n constructor(private client: VGF) {}\n\n async prepareUpload(): Promise<TmpFile> {\n const res = await this.client._request<{ data: TmpFile }>(\n \"POST\",\n \"/tmp-file\",\n );\n return res.data;\n }\n\n /**\n * Uploads a file to temporary storage and returns the download URL,\n * which can be used as an input_files value in a job.\n */\n async upload(\n data: Buffer | Blob | ReadableStream | Uint8Array,\n contentType = \"application/octet-stream\",\n ): Promise<string> {\n const { upload_url, download_url } = await this.prepareUpload();\n const res = await fetch(upload_url, {\n method: \"PUT\",\n headers: { \"Content-Type\": contentType },\n body: data as BodyInit,\n });\n if (!res.ok) {\n const { VGFError } = await import(\"./error.js\");\n throw new VGFError(res.status, `File upload failed: ${res.statusText}`);\n }\n return download_url;\n }\n}\n\nexport default VGF;\n"],"mappings":";;;;;AAKO,IAAM,UAAU;AAKhB,IAAM,aAAa,sBAAsB,OAAO;;;ACWvD,IAAM,WAAW;AAEV,IAAM,MAAN,MAAU;AAAA,EACN;AAAA,EACA;AAAA,EAED;AAAA,EACA;AAAA,EACA;AAAA,EAER,YACE,QACA,SACA;AACA,QAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,qBAAqB;AAClD,SAAK,SAAS;AACd,SAAK,UAAU,SAAS,WAAW;AAGnC,UAAM,SAAS,SAAS,iBAAiB,KAAK;AAC9C,SAAK,YAAY,SAAS,GAAG,UAAU,IAAI,MAAM,KAAK;AAEtD,SAAK,OAAO,IAAI,KAAK,IAAI;AACzB,SAAK,QAAQ,IAAI,MA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