Skip to content

Commit

Permalink
simplify the encoding test-example (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmomtchev authored Jan 2, 2024
1 parent 780eb40 commit 59b2eb4
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions test/encode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();

Expand Down

0 comments on commit 59b2eb4

Please sign in to comment.