mattdesl / canvas-sketch

[beta] A framework for making generative artwork in JavaScript and the browser.
MIT License
5.03k stars 394 forks source link

Unable to save streams #133

Closed tomssem closed 2 years ago

tomssem commented 2 years ago

Every time I try to save a stream of frames (with out without the --stream option, and if set to gif or not) I get a TypeError along the lines of:

/usr/local/lib/node_modules/canvas-sketch-cli/src/middleware.js:189
            if (mimeType && mimeType !== currentStream.encoding) {
                                                       ^

TypeError: Cannot read property 'encoding' of null
    at /usr/local/lib/node_modules/canvas-sketch-cli/src/middleware.js:189:56
    at /usr/local/lib/node_modules/canvas-sketch-cli/node_modules/mkdirp/index.js:49:26
    at FSReqCallback.oncomplete (fs.js:159:5)

The exact property that is null can be different, another example being:

/usr/local/lib/node_modules/canvas-sketch-cli/src/middleware.js:198
                  currentStream.writeBufferFrame(buf)

TypeError: Cannot read property 'writeBufferFrame' of null
GusHebblewhite commented 2 years ago

I'm getting the same issue. Win 11.

GusHebblewhite commented 2 years ago

Tried to actually find the bug but it's above my JS paygrade - in essence handleStreamEnd gets called in between usingStream being defined and currentStream being used in the if statement, so in that time currentStream is set to null.

mattdesl commented 2 years ago

Thanks! Gonna look into this. I haven't noticed any errors on my end so a bit tricky for me to debug. Can you be sure you are on the latest version of both canvas-sketch and canvas-sketch-cli ?

# install latest CLI locally or globally depending on what you use
npm install canvas-sketch-cli@latest --global

# install latest API locally into your repo
npm install canvas-sketch@latest --save
cumenez commented 2 years ago

Hi, I have the same issue, I have the latest version of both canvas-sketch and canvas-sketch-cli, when i stop the stream it give me the error, and save the stream on download although I specified the ouput path.

david-huck commented 2 years ago

+1, i get the same error message as OP

Dot-Rhs commented 2 years ago

I've recently hit this issue, I don't have a fix but I have a workaround I can't really explain, at least it works in my case.

I've gone to middleware.js, line 189 and just logged currentStream before the conditional. I can save video's now although there is just a terminal full of logs now, if I remove the log the error returns.

Does anyone with more experience have an insight into why that would happen?

chetankumar commented 2 years ago

I finally figured it out. Just as @Dot-Rhs pointed out, the trouble is in line number 189. I think that section was added very recently to stop some incompatible encoding from being saved. I just commented out the below code around # 189.

// if (mimeType && mimeType !== currentStream.encoding) { // reject(new Error('Error: Currently only single-image exports in image/png or image/jpeg format is supported with MP4 streaming')); // }

Only caveat, you need to remember that for an mp4 stream, the encoding in the options should be 'image/png' or 'image/jpeg'. The above section of code "enforced" that. Trouble is, it enforced that without checking if the stream is null.

mattdesl commented 2 years ago

I believe this should now be fixed in latest. Please update like so:

(if you've installed the CLI globally previously)

npm install canvas-sketch-cli@latest --global

Or locally:

npm install canvas-sketch-cli@latest --save-dev

Let me know if any issues persist.

vahlcode commented 2 years ago

I'm still facing same problem here.

There was a problem starting the stream export

vahlcode commented 2 years ago

Worked after installing locally.