Answer the question
In order to leave comments, you need to log in
How to send a Media Stream over the network and save to a file on the server?
I record video in the browser to a stream using the MediaStream and MediaRecorder classes, after which I send it to the Node.js server via WebSockets. The code looks something like this:
const stream = await navigator.mediaDevices.getUserMedia({ audio: true, video: { facingMode: "user" } });
const socket = new WebSocket("ws://127.0.0.1:3000/ws");
mediaRecorder = new MediaRecorder(stream, { mimeType: "video/mp4" });
mediaRecorder.ondataavailable = handleDataAvailable;
mediaRecorder.start(500);
function handleDataAvailable(event) {
if (event.data.size > 0) socket.send(event.data);
}
setTimeout(() => mediaRecorder.stop(), 5000);
<Buffer 00 00 01 ...>
. The question is how to combine all this data and save it into a single video file in .mp4 format? fs.writeFile()
, but through it it is impossible to combine and save all buffers. Also tried through fs.createWriteStream()
, but the final file does not open.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question