RecordRTC icon indicating copy to clipboard operation
RecordRTC copied to clipboard

Duration audio Infinity

Open antonio-vargas opened this issue 7 years ago • 13 comments

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)
}

antonio-vargas avatar Jun 06 '17 18:06 antonio-vargas

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

gdurga avatar Sep 05 '17 19:09 gdurga

I want to capture in mp3 format to upload it to firebase but I get error in infinite audio

antonio-vargas avatar Sep 08 '17 14:09 antonio-vargas

@gdurga can you provide a part of code how you get duration?

vladpoltorin avatar Feb 23 '18 16:02 vladpoltorin

@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

gdurga avatar Feb 23 '18 16:02 gdurga

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?

nikosgi avatar Apr 10 '18 07:04 nikosgi

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

gdurga avatar Apr 10 '18 11:04 gdurga

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

gdurga avatar Apr 10 '18 11:04 gdurga

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?

muaz-khan avatar Apr 10 '18 11:04 muaz-khan

When I record the screen using throw the recordRTC but video length is infinite. Could you please tell me what should I do?

akalana avatar May 16 '19 11:05 akalana

Did anyone get a solution?

shekar-raja avatar Aug 13 '20 07:08 shekar-raja

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.

image

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.

iamsrujal avatar Apr 05 '22 15:04 iamsrujal

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.

image

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.

iamsrujal avatar Apr 14 '22 10:04 iamsrujal

can this be used for audio recording as well?

praveenb4305 avatar Nov 06 '23 16:11 praveenb4305