File tree Expand file tree Collapse file tree 6 files changed +43
-5
lines changed Expand file tree Collapse file tree 6 files changed +43
-5
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,10 @@ Use FFmpeg directly in your browser without any backend services!!
22
22
</a >
23
23
</p >
24
24
25
+ <a href =" https://codepen.io/jeromewu/pen/NWWaMeY " target =" _blank " >
26
+ <
img alt =
" codepen " width =
" 128px " src =
" https://blog.codepen.io/wp-content/uploads/2012/06/[email protected] " >
27
+ </a >
28
+
25
29
[ Source Code] ( https://github.com/ffmpegjs/ffmpeg.js/blob/master/examples/browser/transcode.html )
26
30
27
31
---
Original file line number Diff line number Diff line change 1
1
const createJob = require ( './createJob' ) ;
2
2
const { log } = require ( './utils/log' ) ;
3
3
const getId = require ( './utils/getId' ) ;
4
+ const resolvePaths = require ( './utils/resolvePaths' ) ;
4
5
const {
5
6
defaultOptions,
6
7
spawnWorker,
@@ -17,10 +18,10 @@ module.exports = (_options = {}) => {
17
18
const {
18
19
logger,
19
20
...options
20
- } = {
21
+ } = resolvePaths ( {
21
22
...defaultOptions ,
22
23
..._options ,
23
- } ;
24
+ } ) ;
24
25
const resolves = { } ;
25
26
const rejects = { } ;
26
27
let worker = spawnWorker ( options ) ;
Original file line number Diff line number Diff line change
1
+ module . exports = ( key ) => {
2
+ const env = {
3
+ type : ( typeof window !== 'undefined' ) && ( typeof window . document !== 'undefined' ) ? 'browser' : 'node' ,
4
+ } ;
5
+
6
+ if ( typeof key === 'undefined' ) {
7
+ return env ;
8
+ }
9
+ return env [ key ] ;
10
+ } ;
Original file line number Diff line number Diff line change
1
+ const isBrowser = require ( './getEnvironment' ) ( 'type' ) === 'browser' ;
2
+ const resolveURL = isBrowser ? require ( 'resolve-url' ) : s => s ; // eslint-disable-line
3
+
4
+ module . exports = ( options ) => {
5
+ const opts = { ...options } ;
6
+ [ 'corePath' , 'workerPath' ] . forEach ( ( key ) => {
7
+ if ( typeof options [ key ] !== 'undefined' ) {
8
+ opts [ key ] = resolveURL ( opts [ key ] ) ;
9
+ }
10
+ } ) ;
11
+ return opts ;
12
+ } ;
Original file line number Diff line number Diff line change @@ -11,4 +11,5 @@ module.exports = {
11
11
? resolveURL ( `/dist/worker.dev.js?nocache=${ Math . random ( ) . toString ( 36 ) . slice ( 3 ) } ` )
12
12
: `https://unpkg.com/@ffmpeg/ffmpeg@v${ version } /dist/worker.min.js` ,
13
13
corePath : `https://unpkg.com/@ffmpeg/core@v${ dependencies [ '@ffmpeg/core' ] . substring ( 1 ) } /ffmpeg-core.js` ,
14
+ workerBlobURL : true ,
14
15
} ;
Original file line number Diff line number Diff line change 5
5
* @function create a new Worker in browser
6
6
* @access public
7
7
*/
8
- module . exports = ( { workerPath } ) => (
9
- new Worker ( workerPath )
10
- ) ;
8
+ module . exports = ( { workerPath, workerBlobURL } ) => {
9
+ let worker ;
10
+ if ( Blob && URL && workerBlobURL ) {
11
+ /* Use Blob to load cross domain worker script */
12
+ const blob = new Blob ( [ `importScripts("${ workerPath } ");` ] , {
13
+ type : 'application/javascript' ,
14
+ } ) ;
15
+ worker = new Worker ( URL . createObjectURL ( blob ) ) ;
16
+ } else {
17
+ worker = new Worker ( workerPath ) ;
18
+ }
19
+ return worker ;
20
+ } ;
You can’t perform that action at this time.
0 commit comments