I’m trying to use MediaRecorder to record a video stream, and I send a video chunk every second to server, and use createWriteStream to write to the file, but the video only plays the first second and stops, any help in this would be really appreciated!
This is my code for frontend:
const video = document.querySelector("#video");
const stream = video.captureStream();
let recorder = new MediaRecorder(stream);
recorder.ondataavailable = async (e) => {
const fd = new FormData()
fd.append("body", e.data)
axios.post('url', fd)
};
recorder.start(1500);
And this is what I am using on backend:
const busboy = Busboy({ headers: request.headers });
let fields: any = {};
busboy.on("field", (field: string, val: any) => {
fields[field] = val;
});
busboy.end(request.rawBody);
const fileStream = fs.createWriteStream(
`tmp.webm`,
{ flags: "a" }
);
fileStream.write(request.body);