@@ -17,17 +17,19 @@ a ~31 MB ffmpeg-core.wasm.
17
17
// import { FFmpeg } from '@ffmpeg/ffmpeg';
18
18
// import { fetchFile } from '@ffmpeg/util';
19
19
function () {
20
- const baseURL = ' https://unpkg.com/@ffmpeg/[email protected] /dist/umd'
21
20
const [loaded , setLoaded ] = useState (false );
22
21
const ffmpegRef = useRef (new FFmpeg ());
23
22
const videoRef = useRef (null );
24
23
const messageRef = useRef (null );
25
24
26
25
const load = async () => {
26
+ const baseURL = ' https://unpkg.com/@ffmpeg/[email protected] /dist/umd'
27
27
const ffmpeg = ffmpegRef .current ;
28
28
ffmpeg .on (" log" , ({ message }) => {
29
29
messageRef .current .innerHTML = message;
30
30
});
31
+ // toBlobURL is used to bypass CORS issue, urls with the same
32
+ // domain can be used directly.
31
33
await ffmpeg .load ({
32
34
coreURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.js` ),
33
35
wasmURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.wasm` ),
@@ -138,11 +140,17 @@ function() {
138
140
const messageRef = useRef (null );
139
141
140
142
const load = async () => {
143
+ const baseURL = ' https://unpkg.com/@ffmpeg/[email protected] /dist/umd'
141
144
const ffmpeg = ffmpegRef .current ;
142
145
ffmpeg .on (" log" , ({ message }) => {
143
146
messageRef .current .innerHTML = message;
144
147
});
145
- await ffmpeg .load ();
148
+ // toBlobURL is used to bypass CORS issue, urls with the same
149
+ // domain can be used directly.
150
+ await ffmpeg .load ({
151
+ coreURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.js` ),
152
+ wasmURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.wasm` ),
153
+ });
146
154
setLoaded (true );
147
155
}
148
156
@@ -186,12 +194,18 @@ function() {
186
194
const messageRef = useRef (null );
187
195
188
196
const load = async () => {
197
+ const baseURL = ' https://unpkg.com/@ffmpeg/[email protected] /dist/umd'
189
198
const ffmpeg = ffmpegRef .current ;
190
199
// Listen to progress event instead of log.
191
200
ffmpeg .on (" progress" , ({ progress }) => {
192
201
messageRef .current .innerHTML = ` ${ progress * 100 } %` ;
193
202
});
194
- await ffmpeg .load ();
203
+ // toBlobURL is used to bypass CORS issue, urls with the same
204
+ // domain can be used directly.
205
+ await ffmpeg .load ({
206
+ coreURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.js` ),
207
+ wasmURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.wasm` ),
208
+ });
195
209
setLoaded (true );
196
210
}
197
211
0 commit comments