Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 4ff0b4e

Browse files
committed
Update ffmpeg.js
1 parent fe28bd1 commit 4ff0b4e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

wasm/ffmpeg.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Module.onRuntimeInitialized = () => {
66
Module.FS.writeFile('flame.avi', data);
77

88
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'];
1010
const argsPtr = Module._malloc(args.length * Uint32Array.BYTES_PER_ELEMENT);
1111
args.forEach((s, idx) => {
1212
const buf = Module._malloc(s.length + 1);
@@ -17,13 +17,17 @@ Module.onRuntimeInitialized = () => {
1717

1818
/*
1919
* 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.
2121
*/
2222
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+
}
2731
}
2832
}, 500);
2933
};

0 commit comments

Comments
 (0)