@@ -6,7 +6,7 @@ Module.onRuntimeInitialized = () => {
6
6
Module . FS . writeFile ( 'flame.avi' , data ) ;
7
7
8
8
const ffmpeg = Module . cwrap ( 'proxy_main' , 'number' , [ 'number' , 'number' ] ) ;
9
- const args = [ 'ffmpeg' , '-hide_banner' , '-i' , 'flame.avi' , 'flame.mp4' ] ;
9
+ const args = [ 'ffmpeg' , '-hide_banner' , '-report' , '- i', 'flame.avi' , 'flame.mp4' ] ;
10
10
const argsPtr = Module . _malloc ( args . length * Uint32Array . BYTES_PER_ELEMENT ) ;
11
11
args . forEach ( ( s , idx ) => {
12
12
const buf = Module . _malloc ( s . length + 1 ) ;
@@ -17,13 +17,17 @@ Module.onRuntimeInitialized = () => {
17
17
18
18
/*
19
19
* The execution of ffmpeg is not synchronized,
20
- * so we need to set a timer to wait for it completes .
20
+ * so we need to parse the log file to check if completed .
21
21
*/
22
22
const timer = setInterval ( ( ) => {
23
- if ( Module . FS . readdir ( '.' ) . find ( f => f === 'flame.mp4' ) !== - 1 ) {
24
- clearInterval ( timer ) ;
25
- const output = Module . FS . readFile ( 'flame.mp4' ) ;
26
- fs . writeFileSync ( 'flame.mp4' , output ) ;
23
+ const logFileName = Module . FS . readdir ( '.' ) . find ( name => name . endsWith ( '.log' ) ) ;
24
+ if ( typeof logFileName !== 'undefined' ) {
25
+ const log = String . fromCharCode . apply ( null , Module . FS . readFile ( logFileName ) ) ;
26
+ if ( log . includes ( "frames successfully decoded" ) ) {
27
+ clearInterval ( timer ) ;
28
+ const output = Module . FS . readFile ( 'flame.mp4' ) ;
29
+ fs . writeFileSync ( 'flame.mp4' , output ) ;
30
+ }
27
31
}
28
32
} , 500 ) ;
29
33
} ;
0 commit comments