1- API
2- ===
1+ # API
32
43- [ createWorker()] ( #create-worker )
54 - [ Worker.load] ( #worker-load )
1413---
1514
1615<a name =" create-worker " ></a >
16+
1717## createWorker(options): Worker
1818
1919createWorker is a factory function that creates a ffmpeg worker, a worker is basically a Web Worker in browser and Child Process in Node.
@@ -27,17 +27,18 @@ createWorker is a factory function that creates a ffmpeg worker, a worker is bas
2727 - ` logger ` a function to log the progress, a quick example is ` m => console.log(m) `
2828 - ` progress ` a function to trace the progress, a quick example is ` p => console.log(p) `
2929
30-
3130** Examples:**
3231
3332``` javascript
3433const { createWorker } = FFmpeg;
3534const worker = createWorker ({
36- corePath: ' ./node_modules/@ffmpeg/core/ffmpeg-core.js' ,
37- logger : m => console .log (m),
35+ corePath: " ./node_modules/@ffmpeg/core/ffmpeg-core.js" ,
36+ logger : m => console .log (m)
3837});
3938```
39+
4040<a name =" worker-load " ></a >
41+
4142### Worker.load(jobId): Promise
4243
4344Worker.load() loads ffmpeg-core.js script (download from remote if not presented), it makes Web Worker/Child Process ready for next action.
@@ -55,6 +56,7 @@ Worker.load() loads ffmpeg-core.js script (download from remote if not presented
5556```
5657
5758<a name =" worker-write " ></a >
59+
5860### Worker.write(path, data): Promise
5961
6062Worker.write() writes data to specific path in Emscripten file system, it is an essential step before doing any other tasks.
@@ -68,11 +70,15 @@ Worker.write() writes data to specific path in Emscripten file system, it is an
6870
6971``` javascript
7072(async () => {
71- await worker .write (' flame.avi' , ' http://localhost:3000/tests/assets/flame.avi' );
73+ await worker .write (
74+ " flame.avi" ,
75+ " http://localhost:3000/tests/assets/flame.avi"
76+ );
7277})();
7378```
7479
7580<a name =" worker-writeText " ></a >
81+
7682### Worker.writeText(path, text): Promise
7783
7884Worker.write() writes text data to specific path in Emscripten file system.
@@ -86,11 +92,12 @@ Worker.write() writes text data to specific path in Emscripten file system.
8692
8793``` javascript
8894(async () => {
89- await worker .write (' sub.srt' , ' ...' );
95+ await worker .write (" sub.srt" , " ..." );
9096})();
9197```
9298
9399<a name =" worker-read " ></a >
100+
94101### Worker.read(path, del): Promise
95102
96103Worker.read() reads data from file system, often used to get output data after specific task.
@@ -104,11 +111,12 @@ Worker.read() reads data from file system, often used to get output data after s
104111
105112``` javascript
106113(async () => {
107- const { data } = await worker .read (' output.mp4' );
114+ const { data } = await worker .read (" output.mp4" );
108115})();
109116```
110117
111118<a name =" worker-remove " ></a >
119+
112120### Worker.remove(path): Promise
113121
114122Worker.remove() removes files in file system, it will be better to delete unused files if you need to run ffmpeg.js multiple times.
@@ -121,11 +129,12 @@ Worker.remove() removes files in file system, it will be better to delete unused
121129
122130``` javascript
123131(async () => {
124- await worker .remove (' output.mp4' );
132+ await worker .remove (" output.mp4" );
125133})();
126134```
127135
128136<a name =" worker-transcode " ></a >
137+
129138### Worker.transcode(inputPath, outputPath, options, del, jobId): Promise
130139
131140Worker.transcode() transcode a video file to another format.
@@ -142,11 +151,12 @@ Worker.transcode() transcode a video file to another format.
142151
143152``` javascript
144153(async () => {
145- await worker .transcode (' flame.avi' , ' output.mp4' , ' -s 1920x1080' );
154+ await worker .transcode (" flame.avi" , " output.mp4" , " -s 1920x1080" );
146155})();
147156```
148157
149158<a name =" worker-trim " ></a >
159+
150160### Worker.trim(inputPath, outputPath, from, to, options, del, jobId): Promise
151161
152162Worker.trim() trims video to specific interval.
@@ -165,11 +175,34 @@ Worker.trim() trims video to specific interval.
165175
166176``` javascript
167177(async () => {
168- await worker .trim (' flame.avi' , ' output.mp4' , 1 , 2 );
178+ await worker .trim (" flame.avi" , " output.mp4" , 1 , 2 );
179+ })();
180+ ```
181+
182+ <a name =" worker-concatDemuxer " ></a >
183+
184+ ### Worker.concatDemuxer(inputPaths, outputPath, options, del, jobId): Promise
185+
186+ Worker.concatDemuxer() concatenates multiple videos using concatDemuxer. This method won't encode the videos again. But it has its limitations. See [ Concat demuxer Wiki] ( https://trac.ffmpeg.org/wiki/Concatenate )
187+
188+ ** Arguments:**
189+
190+ - ` inputPaths ` input file paths as an Array, the input files should be written through Worker.write()
191+ - ` outputPath ` output file path, can be read with Worker.read() later
192+ - ` options ` a string to add extra arguments to ffmpeg
193+ - ` del ` a boolean to determine whether to delete input file after the task is done, default: true
194+ - ` jobId ` check Worker.load()
195+
196+ ** Examples:**
197+
198+ ``` javascript
199+ (async () => {
200+ await worker .trim ([" flame-1.avi" , " flame-2.avi" ], " output.mp4" );
169201})();
170202```
171203
172204<a name =" worker-run " ></a >
205+
173206### Worker.run(args, options, jobId): Promise
174207
175208Worker.run() is similar to FFmpeg cli tool, aims to provide maximum flexiblity for users.
@@ -184,6 +217,9 @@ Worker.run() is similar to FFmpeg cli tool, aims to provide maximum flexiblity f
184217
185218``` javascript
186219(async () => {
187- await worker .run (' -i /data/flame.avi -s 1920x1080 output.mp4' , { inputPath: ' flame.avi' , outputPath: ' output.mp4' });
220+ await worker .run (" -i /data/flame.avi -s 1920x1080 output.mp4" , {
221+ inputPath: " flame.avi" ,
222+ outputPath: " output.mp4"
223+ });
188224})();
189225```
0 commit comments