From 59b2eb4aeda6fcf53eeaae8a1fb18aed5aa9e95f Mon Sep 17 00:00:00 2001 From: Momtchil Momtchev Date: Tue, 2 Jan 2024 12:11:49 +0100 Subject: [PATCH] simplify the encoding test-example (#17) --- test/encode.test.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/test/encode.test.ts b/test/encode.test.ts index 63f2fd6..38ab2c0 100644 --- a/test/encode.test.ts +++ b/test/encode.test.ts @@ -62,13 +62,7 @@ it('produce a video from stills', (done) => { let pts = 0; const write = function () { let frame; - let callback: (() => void) | undefined = undefined; do { - if (--totalFrames === 0) { - callback = () => { - videoOutput.end(); - }; - } const image = genFrame(state); const blob = new Magick.Blob; image.write(blob); @@ -78,9 +72,12 @@ it('produce a video from stills', (done) => { frame.setPts(new ffmpeg.Timestamp(pts++, timeBase)); // This is the Node.js Writable protocol - } while (videoOutput.write(frame, 'binary', callback) && totalFrames > 0); + // write until write returns false, then wait for 'drain' + } while (videoOutput.write(frame, 'binary') && --totalFrames > 0); if (totalFrames > 0) videoOutput.once('drain', write); + else + videoOutput.end(); }; write();