You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Function that detects the success of the encoder process,
does cb(true) in case of succes, any other value for failure
Calling cb more than one time has no effect
encoderProcess is of type ChildProcess
Default: shown below, it isn't perfect but covers most of the cases /
isSuccessful(encoderProcess, cb) {
let started = false;
encoderProcess.stderr.setEncoding('utf8');
encoderProcess.stderr.on('data', (data) => {
/ I trust that the output is line-buffered /
const startedText = /Press ctrl-c to stop encoding/;
if(startedText.test(data)) {
cb(true);
started = true;
}
});
/ If the process start was not detected and it exited it's surely a failure */
encoderProcess.on('exit', () => {
if(!started) cb(false);
});
}
};
/* Suppose i want to use the default REST API /
const server = webcam.createHTTPStreamingServer({
/
Optional: A list of the permitted webcams, if it's specified overrides
return new Promise((accept, reject) => {
/* If doesn't seem like a video device block we will fail */
if(!webcamRegex.test(webcam)) {
reject(false);
} else {
/* ... and if the file doesn't exists */
fileExists(webcam).then(accept, reject);
}
});
}
/*
The endpoint for requesting streams of the REST api
Defaults to '/webcam' /
webcamEndpoint: '/webcam',
/
with [QueryString](https://nodejs.org/api/querystring.html#querystring_querystring_parse_str_sep_eq_options)
Note: the endpoint 'default' is used for any non-matching request
*/
additionalEndpoints: {
'/list_webcams': (req, res, reqUrl) => { res.end('...'); }
},
encoder: encoder
}).listen(8080);
/* Returns a promise that resolves to the video stream (stream.Readable) */
const videoStream = webcam.streamWebcam('/dev/video0', encoder);`
The text was updated successfully, but these errors were encountered:
TrevorBlythe
changed the title
Doesnt even work.
Doesnt even work. (the code on the npm website dont work)
May 29, 2023
The example code just straight up has a blatant syntax error.
`const webcam = require('webcam-http-streaming');
const encoder = {
/*
/
command: 'ffmpeg',
/
/
flags(webcam) {
return
-f video4linux2 -i ${webcam} -f webm -deadline realtime pipe:1
;},
/
/
mimeType: 'video/webm',
/
/
isSuccessful(encoderProcess, cb) {
let started = false;
encoderProcess.stderr.setEncoding('utf8');
encoderProcess.stderr.on('data', (data) => {
/ I trust that the output is line-buffered /
const startedText = /Press ctrl-c to stop encoding/;
if(startedText.test(data)) {
cb(true);
started = true;
}
});
/ If the process start was not detected and it exited it's surely a failure */
encoderProcess.on('exit', () => {
if(!started) cb(false);
});
}
};
/* Suppose i want to use the default REST API /
const server = webcam.createHTTPStreamingServer({
/
/
permittedWebcams: ['/dev/video0', '/dev/video1'],
/
*/
isValidWebcam(webcam) {
const webcamRegex = //dev/video[0-9]+/;
}
/*
/
webcamEndpoint: '/webcam',
/
*/
additionalEndpoints: {
'/list_webcams': (req, res, reqUrl) => { res.end('...'); }
},
encoder: encoder
}).listen(8080);
/* Returns a promise that resolves to the video stream (stream.Readable) */
const videoStream = webcam.streamWebcam('/dev/video0', encoder);`
The text was updated successfully, but these errors were encountered: