chuckfairy / node-webcam

Nodejs Cross Platform Webcam usage
MIT License
193 stars 51 forks source link

Is it possible to use this without saving a file? #60

Open TheLogan opened 2 years ago

TheLogan commented 2 years ago

I've tried playing around with saveShots, output and callbackReturn, but non of them seem to allow me to stop the saving of the photo as a file. I really only need the photo in memory though, so it's just unnecessary overhead for me.

Oman395 commented 2 years ago

As far as I can tell, there isn't-- I think that the issue is that the way it gets the data is by running a command to save an image, then getting that images data-- here's a bit of a workaround that I find works, just delete the file that gets saved immediately. A bit annoying, but eh

const nw = require('node-webcam');
const fs = require('fs');

let cam = nw.create({
    callbackReturn: 'buffer'
});

cam.capture('delete', (err, data) => {
    if (err) {
        console.log(err);
    } else {
        // Data is buffer w/ image
        fs.unlinkSync('delete.jpg');
    }
});
paulash commented 1 year ago

ah dang, this is bad limitation as write/reads off a drive are obviously much slower then memory, wish the buffer option just returned the buffer without saving, kinda makes it pointless to even have the callback controls.