RecordRTC
RecordRTC copied to clipboard
Duration audio Infinity
In the following function I send the URL, my problem is that the audio.duration gives me Infinity.
function recordingEndedCallback (urlBlob) {
var audio = new Audio()
audio.src = urlBlob
audio.addEventListener('loadedmetadata', () => {
console.log(audio.duration)
}, false)
}
Did you record using the MediaStreamRecorder? With the MediaStreamRecorder I got the same 'error', if I use StereoAudioRecorder everything works fine, the inconvenient is the file size
10 seconds: 350 KB with StereoAudioRecorder (numberOfAudioChannels: 1) 67 KB with MediaStreamRecorder
I want to capture in mp3 format to upload it to firebase but I get error in infinite audio
@gdurga can you provide a part of code how you get duration?
@vladpoltorin Sure! Here is the code First record the audio with the MediaStreamRecorder to reduce the file size, like this:
recorder = RecordRTC(microphone, {
recorderType: MediaStreamRecorder,
type: "audio",
bufferSize: 4096,
sampleRate: 44100,
checkForInactiveTracks: true
});
Then convert the file using ffmpeg to fix the infinite audio duration
ffmpeg -i <original_file> -c copy -fflags +genpts <fixed_duration_file>
The resulting file are pretty much the same file size of the original and it has a defined duration
Also, when I try to record video with MediaStreamRecorder or MultiStreamRecorder I get infinity duration. StereoAudioRecorder works fine, giving the duration of the audio recording and WhammyRecorder results in a valid duration also.
@gdurga Is there a way to get the original duration without using ffmpeg?
Hi @nikosgi, unfortunately the only way I found to get the duration using the MediaStreamRecorder is using ffmpeg to convert the file after the record :/ Using the StereoAudioRecorder works fine for me too but the file size will be much larger
Here is a very basic example with Django -> https://github.com/gdurga/Django-RecordRTC-example Converts the file after the upload using the python os.system
Someone mentioned this as well, however I didn't try it myself yet:
https://github.com/legokichi/ts-ebml
Can someone make it work without type-script
compilers?
When I record the screen using throw the recordRTC but video length is infinite. Could you please tell me what should I do?
Did anyone get a solution?
I have integrated below solution. (It's working fine in desktop Chrome Version 100.0.4896.75 (Official Build) (64-bit)) Still need confirmation from different OS and browser.
In order to get the duration inside recorded file we have to add ts-ebml dependency. I have used webm-duration-fix npm.
By integrating above solution it's fixed my recording duration issue but still need to test in other OS and browsers.
I have integrated below solution. (It's working fine in desktop Chrome Version 100.0.4896.75 (Official Build) (64-bit)) Still need confirmation from different OS and browser.
In order to get the duration inside recorded file we have to add ts-ebml dependency. I have used webm-duration-fix npm.
By integrating above solution it's fixed my recording duration issue but still need to test in other OS and browsers.
I did some test in android and IOS latest version by today date (14/04/2022).
It's working fine.
can this be used for audio recording as well?