@@ -17,17 +17,19 @@ a ~31 MB ffmpeg-core.wasm.
1717// import { FFmpeg } from '@ffmpeg/ffmpeg';
1818// import { fetchFile } from '@ffmpeg/util';
1919function () {
20- const baseURL = ' https://unpkg.com/@ffmpeg/core@0.12.1/dist/umd'
2120 const [loaded , setLoaded ] = useState (false );
2221 const ffmpegRef = useRef (new FFmpeg ());
2322 const videoRef = useRef (null );
2423 const messageRef = useRef (null );
2524
2625 const load = async () => {
26+ const baseURL = ' https://unpkg.com/@ffmpeg/core@0.12.1/dist/umd'
2727 const ffmpeg = ffmpegRef .current ;
2828 ffmpeg .on (" log" , ({ message }) => {
2929 messageRef .current .innerHTML = message;
3030 });
31+ // toBlobURL is used to bypass CORS issue, urls with the same
32+ // domain can be used directly.
3133 await ffmpeg .load ({
3234 coreURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.js` ),
3335 wasmURL: await toBlobURL (` ${ baseURL} /ffmpeg-core.wasm` ),
@@ -138,11 +140,17 @@ function() {
138140 const messageRef = useRef (null );
139141
140142 const load = async () => {
143+ const baseURL = ' https://unpkg.com/@ffmpeg/core@0.12.1/dist/umd'
141144 const ffmpeg = ffmpegRef .current ;
142145 ffmpeg .on (" log" , ({ message }) => {
143146 messageRef .current .innerHTML = message;
144147 });
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+ });
146154 setLoaded (true );
147155 }
148156
@@ -186,12 +194,18 @@ function() {
186194 const messageRef = useRef (null );
187195
188196 const load = async () => {
197+ const baseURL = ' https://unpkg.com/@ffmpeg/core@0.12.1/dist/umd'
189198 const ffmpeg = ffmpegRef .current ;
190199 // Listen to progress event instead of log.
191200 ffmpeg .on (" progress" , ({ progress }) => {
192201 messageRef .current .innerHTML = ` ${ progress * 100 } %` ;
193202 });
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+ });
195209 setLoaded (true );
196210 }
197211
0 commit comments