Is there any way to get the file size on recording? So, I can stop the recording when the it hits the maximal size allowed?
Currently there are only way to stop recording, by stop it using stop button and set the duration using "setRecordingDuration()":
function successCallback(stream) {
// RecordRTC usage goes here
var options = {
mimeType: 'audio/mp3', // or video/webm\;codecs=h264 or video/webm\;codecs=vp9
// audioBitsPerSecond: 128000,
// bufferSize: parseInt($(".media-bitrates").val()),
sampleRate: parseInt($(".media-framerates").val()),
// videoBitsPerSecond: parseInt($(".media-bitrates").val()),
bitsPerSecond: parseInt($(".media-bitrates").val()),
// bitsPerSecond: 128000 // if this line is provided, skip above two
};
varStream = stream;
recordRTC = RecordRTC(varStream, options);
audio.srcObject = varStream;
varStream.stop = function () {
this.getAudioTracks().forEach(function (track) {
track.stop();
});
};
}
From what I see from the coding, I can only get the size on stop recording, because the blob is not available during recording.
I found my own answer. Anyway this question was answered by Muaz Khan in his repiository on issue. Well it is not an issue, so I don't look up on there. Anyway, if someone looking for the answer this might help.
(function looper() {
if (!recorder) {
return;
}
var internal = recorder.getInternalRecorder();
if (internal && internal.getArrayOfBlobs) {
var blob = new Blob(internal.getArrayOfBlobs(), {
type: 'video/webm'
});
// -------------------------------------------------------------
if (blob.size > 100 * 1000) { // if blob is greater than 100 MB
recorder.stopRecording(callback); // stop recording here
return;
}
// -------------------------------------------------------------
document.querySelector('h1').innerHTML = 'Recording length: ' + bytesToSize(blob.size);
}
setTimeout(looper, 1000);
})();
you can find the answer on the link below:
https://github.com/muaz-khan/RecordRTC/issues/301
Well, this site can be down too.. ;)
anyway let's hope not. Let me provide the full the code instead. Explaining is not my best part. Working example are best explanation.
Before recording, MediaStreamRecorder should be as recorder Type. TimeSlice params should be pass. Not so sure what this do. But I guess, this parameter give the Library an info, that the blob should be slice every 1000 ms. every one second then.
recorder = RecordRTC(camera, {
recorderType: MediaStreamRecorder,
mimeType: 'video/webm',
timeSlice: 1000 // pass this parameter
});
Then put this code after. This loop function run every 1000 ms. and check the current blob size. You can check the size, show the user or stop the recording one it reachs the allowed size. You should check the filesize on the server. You can't rely on the client side script.
(function looper() {
if(!recorder) {
return;
}
var internal = recorder.getInternalRecorder();
if(internal && internal.getArrayOfBlobs) {
var blob = new Blob(internal.getArrayOfBlobs(), {
type: 'video/webm'
});
document.querySelector('h1').innerHTML = 'Recording length: ' + bytesToSize(blob.size);
}
setTimeout(looper, 1000);
})();
and the last part.
recorder.startRecording();