From 91e7ca8c407c6772deb2a72ff8f2b08c3f3167d2 Mon Sep 17 00:00:00 2001 From: Jerome Wu Date: Thu, 5 Nov 2020 09:39:25 +0800 Subject: [PATCH] Update node.js examples --- examples/node/concatDemuxer.js | 2 +- examples/node/hstack.js | 2 +- examples/node/image2video.js | 2 +- examples/node/multiple-output.js | 5 ++--- examples/node/transcode.js | 3 +-- examples/node/trim.js | 2 +- 6 files changed, 7 insertions(+), 9 deletions(-) diff --git a/examples/node/concatDemuxer.js b/examples/node/concatDemuxer.js index b2e9efe28cc..9f8455400d1 100755 --- a/examples/node/concatDemuxer.js +++ b/examples/node/concatDemuxer.js @@ -8,6 +8,6 @@ const ffmpeg = createFFmpeg({ log: true }); ffmpeg.FS('writeFile', 'flame.avi', await fetchFile('../assets/flame.avi')); ffmpeg.FS('writeFile', 'concat_list.txt', 'file flame.avi\nfile flame.avi'); await ffmpeg.run('-f', 'concat', '-safe', '0', '-i', 'concat_list.txt', 'flame.mp4'); - fs.writeFileSync('flame.mp4', ffmpeg.FS('readFile', 'flame.mp4')); + await fs.promises.writeFile('flame.mp4', ffmpeg.FS('readFile', 'flame.mp4')); process.exit(0); })(); diff --git a/examples/node/hstack.js b/examples/node/hstack.js index ffa8b6a1d2f..ae4c760ec08 100755 --- a/examples/node/hstack.js +++ b/examples/node/hstack.js @@ -7,6 +7,6 @@ const ffmpeg = createFFmpeg({ log: true }); await ffmpeg.load(); ffmpeg.FS('writeFile', 'flame.avi', await fetchFile('../assets/flame.avi')); await ffmpeg.run('-i', 'flame.avi', '-i', 'flame.avi', '-filter_complex', 'hstack', 'flame.mp4'); - fs.writeFileSync('flame.mp4', ffmpeg.FS('readFile', 'flame.mp4')); + await fs.promises.writeFile('flame.mp4', ffmpeg.FS('readFile', 'flame.mp4')); process.exit(0); })(); diff --git a/examples/node/image2video.js b/examples/node/image2video.js index c27a7cce77b..7bf55af7761 100755 --- a/examples/node/image2video.js +++ b/examples/node/image2video.js @@ -17,6 +17,6 @@ const ffmpeg = createFFmpeg({ log: true }); const num = `00${i}`.slice(-3); await ffmpeg.FS('unlink', `tmp.${num}.png`); } - fs.writeFileSync('out.mp4', ffmpeg.FS('readFile', 'out.mp4')); + await fs.promises.writeFile('out.mp4', ffmpeg.FS('readFile', 'out.mp4')); process.exit(0); })(); diff --git a/examples/node/multiple-output.js b/examples/node/multiple-output.js index 93e5b0c78b4..70fd2f5ef01 100755 --- a/examples/node/multiple-output.js +++ b/examples/node/multiple-output.js @@ -7,9 +7,8 @@ const ffmpeg = createFFmpeg({ log: true }); await ffmpeg.load(); ffmpeg.FS('writeFile', 'flame.avi', await fetchFile('../assets/flame.avi')); await ffmpeg.run('-i', 'flame.avi', '-map', '0:v', '-r', '25', 'out_%06d.bmp'); - ffmpeg.FS('readdir', '/').filter((p) => p.endsWith('.bmp')).forEach((p) => { - fs.writeFileSync(p, ffmpeg.FS('readFile', p)); + ffmpeg.FS('readdir', '/').filter((p) => p.endsWith('.bmp')).forEach(async (p) => { + await fs.promises.writeFile(p, ffmpeg.FS('readFile', p)); }); - process.exit(0); })(); diff --git a/examples/node/transcode.js b/examples/node/transcode.js index 884b3dd643c..83fe4836604 100755 --- a/examples/node/transcode.js +++ b/examples/node/transcode.js @@ -9,7 +9,6 @@ const ffmpeg = createFFmpeg({ await ffmpeg.load(); ffmpeg.FS('writeFile', 'flame.avi', await fetchFile('../assets/flame.avi')); await ffmpeg.run('-i', 'flame.avi', 'flame.mp4'); - const data = ffmpeg.FS('readFile', 'flame.mp4'); - fs.writeFileSync('flame.mp4', Buffer.from(data)); + await fs.promises.writeFile('flame.mp4', ffmpeg.FS('readFile', 'flame.mp4')); process.exit(0); })(); diff --git a/examples/node/trim.js b/examples/node/trim.js index 61b8892380e..adfb011538f 100755 --- a/examples/node/trim.js +++ b/examples/node/trim.js @@ -7,6 +7,6 @@ const ffmpeg = createFFmpeg({ log: true }); await ffmpeg.load(); ffmpeg.FS('writeFile', 'flame.avi', await fetchFile('../assets/flame.avi')); await ffmpeg.run('-i', 'flame.avi', '-ss', '0', '-to', '1', 'flame_trim.avi'); - fs.writeFileSync('flame_trim.avi', ffmpeg.FS('readFile', 'flame_trim.avi')); + await fs.promises.writeFile('flame_trim.avi', ffmpeg.FS('readFile', 'flame_trim.avi')); process.exit(0); })();