@@ -6,7 +6,7 @@ Learn the basics of using ffmpeg.wasm.
6
6
It is recommended to read [ Overview] ( /docs/overview ) first.
7
7
:::
8
8
9
- ## Transcode avi to mp4 video
9
+ ## Transcode webm to mp4 video
10
10
11
11
::: caution
12
12
If you are a [ vite] ( https://vitejs.dev/ ) user, use ` esm ` in ** baseURL** instead of ` umd ` :
@@ -26,23 +26,23 @@ function() {
26
26
const load = async () => {
27
27
const baseURL = ' https://unpkg.com/@ffmpeg/core@0.12.2/dist/umd'
28
28
const ffmpeg = ffmpegRef .current ;
29
- ffmpeg .on (" log" , ({ message }) => {
29
+ ffmpeg .on (' log' , ({ message }) => {
30
30
messageRef .current .innerHTML = message;
31
31
console .log (message);
32
32
});
33
33
// toBlobURL is used to bypass CORS issue, urls with the same
34
34
// domain can be used directly.
35
35
await ffmpeg .load ({
36
- coreURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.js` , " text/javascript" ),
37
- wasmURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.wasm` , " application/wasm" ),
36
+ coreURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.js` , ' text/javascript' ),
37
+ wasmURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.wasm` , ' application/wasm' ),
38
38
});
39
39
setLoaded (true );
40
40
}
41
41
42
42
const transcode = async () => {
43
43
const ffmpeg = ffmpegRef .current ;
44
- await ffmpeg .writeFile (" input.avi " , await fetchFile (' /video/video-15s.avi ' ));
45
- await ffmpeg .exec ([' -i' , ' input.avi ' , ' output.mp4' ]);
44
+ await ffmpeg .writeFile (' input.webm ' , await fetchFile (' https://raw.githubusercontent.com/ffmpegwasm/testdata/master/Big_Buck_Bunny_180_10s.webm ' ));
45
+ await ffmpeg .exec ([' -i' , ' input.webm ' , ' output.mp4' ]);
46
46
const data = await ffmpeg .readFile (' output.mp4' );
47
47
videoRef .current .src =
48
48
URL .createObjectURL (new Blob ([data .buffer ], {type: ' video/mp4' }));
@@ -52,7 +52,7 @@ function() {
52
52
? (
53
53
<>
54
54
< video ref= {videoRef} controls>< / video>< br/ >
55
- < button onClick= {transcode}> Transcode avi to mp4< / button>
55
+ < button onClick= {transcode}> Transcode webm to mp4< / button>
56
56
< p ref= {messageRef}>< / p>
57
57
< p> Open Developer Tools (Ctrl+ Shift+ I ) to View Logs< / p>
58
58
< / >
@@ -83,24 +83,24 @@ function() {
83
83
const load = async () => {
84
84
const baseURL = ' https://unpkg.com/@ffmpeg/core-mt@0.12.2/dist/umd'
85
85
const ffmpeg = ffmpegRef .current ;
86
- ffmpeg .on (" log" , ({ message }) => {
86
+ ffmpeg .on (' log' , ({ message }) => {
87
87
messageRef .current .innerHTML = message;
88
88
console .log (message);
89
89
});
90
90
// toBlobURL is used to bypass CORS issue, urls with the same
91
91
// domain can be used directly.
92
92
await ffmpeg .load ({
93
- coreURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.js` , " text/javascript" ),
94
- wasmURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.wasm` , " application/wasm" ),
95
- workerURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.worker.js` , " text/javascript" ),
93
+ coreURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.js` , ' text/javascript' ),
94
+ wasmURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.wasm` , ' application/wasm' ),
95
+ workerURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.worker.js` , ' text/javascript' ),
96
96
});
97
97
setLoaded (true );
98
98
}
99
99
100
100
const transcode = async () => {
101
101
const ffmpeg = ffmpegRef .current ;
102
- await ffmpeg .writeFile (" input.avi " , await fetchFile (' /video/video-15s.avi ' ));
103
- await ffmpeg .exec ([' -i' , ' input.avi ' , ' output.mp4' ]);
102
+ await ffmpeg .writeFile (' input.webm ' , await fetchFile (' https://raw.githubusercontent.com/ffmpegwasm/testdata/master/Big_Buck_Bunny_180_10s.webm ' ));
103
+ await ffmpeg .exec ([' -i' , ' input.webm ' , ' output.mp4' ]);
104
104
const data = await ffmpeg .readFile (' output.mp4' );
105
105
videoRef .current .src =
106
106
URL .createObjectURL (new Blob ([data .buffer ], {type: ' video/mp4' }));
@@ -110,7 +110,7 @@ function() {
110
110
? (
111
111
<>
112
112
< video ref= {videoRef} controls>< / video>< br/ >
113
- < button onClick= {transcode}> Transcode avi to mp4< / button>
113
+ < button onClick= {transcode}> Transcode webm to mp4< / button>
114
114
< p ref= {messageRef}>< / p>
115
115
< p> Open Developer Tools (Ctrl+ Shift+ I ) to View Logs< / p>
116
116
< / >
@@ -136,24 +136,24 @@ function() {
136
136
const load = async () => {
137
137
const baseURL = ' https://unpkg.com/@ffmpeg/core@0.12.2/dist/umd'
138
138
const ffmpeg = ffmpegRef .current ;
139
- ffmpeg .on (" log" , ({ message }) => {
139
+ ffmpeg .on (' log' , ({ message }) => {
140
140
messageRef .current .innerHTML = message;
141
141
console .log (message);
142
142
});
143
143
// toBlobURL is used to bypass CORS issue, urls with the same
144
144
// domain can be used directly.
145
145
await ffmpeg .load ({
146
- coreURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.js` , " text/javascript" ),
147
- wasmURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.wasm` , " application/wasm" ),
146
+ coreURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.js` , ' text/javascript' ),
147
+ wasmURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.wasm` , ' application/wasm' ),
148
148
});
149
149
setLoaded (true );
150
150
}
151
151
152
152
const transcode = async () => {
153
153
const ffmpeg = ffmpegRef .current ;
154
- await ffmpeg .writeFile (" input.avi " , await fetchFile (' /video/video-15s.avi ' ));
154
+ await ffmpeg .writeFile (' input.webm ' , await fetchFile (' https://raw.githubusercontent.com/ffmpegwasm/testdata/master/Big_Buck_Bunny_180_10s.webm ' ));
155
155
// The exec should stop after 1 second.
156
- await ffmpeg .exec ([' -i' , ' input.avi ' , ' output.mp4' ], 1000 );
156
+ await ffmpeg .exec ([' -i' , ' input.webm ' , ' output.mp4' ], 1000 );
157
157
const data = await ffmpeg .readFile (' output.mp4' );
158
158
videoRef .current .src =
159
159
URL .createObjectURL (new Blob ([data .buffer ], {type: ' video/mp4' }));
@@ -163,7 +163,7 @@ function() {
163
163
? (
164
164
<>
165
165
< video ref= {videoRef} controls>< / video>< br/ >
166
- < button onClick= {transcode}> Transcode avi to mp4< / button>
166
+ < button onClick= {transcode}> Transcode webm to mp4< / button>
167
167
< p ref= {messageRef}>< / p>
168
168
< p> Open Developer Tools (Ctrl+ Shift+ I ) to View Logs< / p>
169
169
< / >
@@ -195,22 +195,22 @@ function() {
195
195
const baseURL = ' https://unpkg.com/@ffmpeg/core@0.12.2/dist/umd'
196
196
const ffmpeg = ffmpegRef .current ;
197
197
// Listen to progress event instead of log.
198
- ffmpeg .on (" progress" , ({ progress, time }) => {
198
+ ffmpeg .on (' progress' , ({ progress, time }) => {
199
199
messageRef .current .innerHTML = ` ${ progress * 100 } % (transcoded time: ${ time / 1000000 } s)` ;
200
200
});
201
201
// toBlobURL is used to bypass CORS issue, urls with the same
202
202
// domain can be used directly.
203
203
await ffmpeg .load ({
204
- coreURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.js` , " text/javascript" ),
205
- wasmURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.wasm` , " application/wasm" ),
204
+ coreURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.js` , ' text/javascript' ),
205
+ wasmURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.wasm` , ' application/wasm' ),
206
206
});
207
207
setLoaded (true );
208
208
}
209
209
210
210
const transcode = async () => {
211
211
const ffmpeg = ffmpegRef .current ;
212
- await ffmpeg .writeFile (" input.avi " , await fetchFile (' /video/video-15s.avi ' ));
213
- await ffmpeg .exec ([' -i' , ' input.avi ' , ' output.mp4' ]);
212
+ await ffmpeg .writeFile (' input.webm ' , await fetchFile (' https://raw.githubusercontent.com/ffmpegwasm/testdata/master/Big_Buck_Bunny_180_10s.webm ' ));
213
+ await ffmpeg .exec ([' -i' , ' input.webm ' , ' output.mp4' ]);
214
214
const data = await ffmpeg .readFile (' output.mp4' );
215
215
videoRef .current .src =
216
216
URL .createObjectURL (new Blob ([data .buffer ], {type: ' video/mp4' }));
@@ -220,7 +220,7 @@ function() {
220
220
? (
221
221
<>
222
222
< video ref= {videoRef} controls>< / video>< br/ >
223
- < button onClick= {transcode}> Transcode avi to mp4< / button>
223
+ < button onClick= {transcode}> Transcode webm to mp4< / button>
224
224
< p ref= {messageRef}>< / p>
225
225
< / >
226
226
)
@@ -245,37 +245,42 @@ function() {
245
245
const load = async () => {
246
246
const baseURL = ' https://unpkg.com/@ffmpeg/core@0.12.2/dist/umd'
247
247
const ffmpeg = ffmpegRef .current ;
248
- ffmpeg .on (" log" , ({ message }) => {
248
+ ffmpeg .on (' log' , ({ message }) => {
249
249
messageRef .current .innerHTML = message;
250
250
console .log (message);
251
251
});
252
252
// toBlobURL is used to bypass CORS issue, urls with the same
253
253
// domain can be used directly.
254
254
await ffmpeg .load ({
255
- coreURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.js` , " text/javascript" ),
256
- wasmURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.wasm` , " application/wasm" ),
255
+ coreURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.js` , ' text/javascript' ),
256
+ wasmURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.wasm` , ' application/wasm' ),
257
257
});
258
258
setLoaded (true );
259
259
}
260
260
261
261
const transcode = async () => {
262
262
const ffmpeg = ffmpegRef .current ;
263
- await ffmpeg .writeFile (" input.avi " , await fetchFile (' /video/video-15s.avi ' ));
263
+ await ffmpeg .writeFile (' input.webm ' , await fetchFile (' https://raw.githubusercontent.com/ffmpegwasm/testdata/master/Big_Buck_Bunny_180_10s.webm ' ));
264
264
await ffmpeg .exec ([
265
265
' -i' ,
266
- ' input.avi ' ,
266
+ ' input.webm ' ,
267
267
' -f' ,
268
268
' segment' ,
269
269
' -segment_time' ,
270
270
' 3' ,
271
+ ' -g' ,
272
+ ' 9' ,
273
+ ' -sc_threshold' ,
274
+ ' 0' ,
275
+ ' -force_key_frames' ,
276
+ ' expr:gte(t,n_forced*9)' ,
271
277
' -reset_timestamps' ,
272
278
' 1' ,
273
279
' -map' ,
274
- ' 0:0' ,
275
- ' -an' ,
280
+ ' 0' ,
276
281
' output_%d.mp4'
277
282
]);
278
- const data = await ffmpeg .readFile (' output_2 .mp4' );
283
+ const data = await ffmpeg .readFile (' output_1 .mp4' );
279
284
videoRef .current .src =
280
285
URL .createObjectURL (new Blob ([data .buffer ], {type: ' video/mp4' }));
281
286
}
@@ -284,7 +289,7 @@ function() {
284
289
? (
285
290
<>
286
291
< video ref= {videoRef} controls>< / video>< br/ >
287
- < button onClick= {transcode}> Split video to segments of 3 sec . and plays 3rd segment< / button>
292
+ < button onClick= {transcode}> Split video to segments of 3 sec . and plays 2nd segment< / button>
288
293
< p ref= {messageRef}>< / p>
289
294
< p> Open Developer Tools (Ctrl+ Shift+ I ) to View Logs< / p>
290
295
< / >
@@ -310,26 +315,26 @@ function() {
310
315
const load = async () => {
311
316
const baseURL = ' https://unpkg.com/@ffmpeg/core@0.12.2/dist/umd'
312
317
const ffmpeg = ffmpegRef .current ;
313
- ffmpeg .on (" log" , ({ message }) => {
318
+ ffmpeg .on (' log' , ({ message }) => {
314
319
messageRef .current .innerHTML = message;
315
320
console .log (message);
316
321
});
317
322
// toBlobURL is used to bypass CORS issue, urls with the same
318
323
// domain can be used directly.
319
324
await ffmpeg .load ({
320
- coreURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.js` , " text/javascript" ),
321
- wasmURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.wasm` , " application/wasm" ),
325
+ coreURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.js` , ' text/javascript' ),
326
+ wasmURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.wasm` , ' application/wasm' ),
322
327
});
323
328
setLoaded (true );
324
329
}
325
330
326
331
const transcode = async () => {
327
332
const ffmpeg = ffmpegRef .current ;
328
- await ffmpeg .writeFile (" input.avi " , await fetchFile (' /video/video-15s.avi ' ));
329
- await ffmpeg .writeFile (" arial.ttf" , await fetchFile (' /asset /arial.ttf' ));
333
+ await ffmpeg .writeFile (' input.webm ' , await fetchFile (' https://raw.githubusercontent.com/ffmpegwasm/testdata/master/Big_Buck_Bunny_180_10s.webm ' ));
334
+ await ffmpeg .writeFile (' arial.ttf' , await fetchFile (' https://raw.githubusercontent.com/ffmpegwasm/testdata/master /arial.ttf' ));
330
335
await ffmpeg .exec ([
331
336
' -i' ,
332
- ' input.avi ' ,
337
+ ' input.webm ' ,
333
338
' -vf' ,
334
339
' drawtext=fontfile=/arial.ttf:text=\' ffmpeg.wasm\' :x=10:y=10:fontsize=24:fontcolor=white' ,
335
340
' output.mp4' ,
0 commit comments