Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duration audio Infinity #274

Open
antonio-vargas opened this issue Jun 6, 2017 · 14 comments
Open

Duration audio Infinity #274

antonio-vargas opened this issue Jun 6, 2017 · 14 comments

Comments

@antonio-vargas
Copy link

antonio-vargas commented Jun 6, 2017

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)
}
@gdurga
Copy link

gdurga commented Sep 5, 2017

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

@antonio-vargas
Copy link
Author

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

@vladpoltorin
Copy link

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

@gdurga
Copy link

gdurga commented Feb 23, 2018

@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

@nikosgi
Copy link

nikosgi commented Apr 10, 2018

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?

@gdurga
Copy link

gdurga commented Apr 10, 2018

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
Copy link

gdurga commented Apr 10, 2018

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

@muaz-khan
Copy link
Owner

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?

@akalana
Copy link

akalana commented May 16, 2019

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

@shekar-raja
Copy link

Did anyone get a solution?

@iamsrujal
Copy link

iamsrujal commented Apr 5, 2022

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
Copy link

iamsrujal commented Apr 14, 2022

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.

@praveenb4305
Copy link

can this be used for audio recording as well?

@fahadhassan101
Copy link

This works for me!

useEffect(() => {
    if (!audioRef.current) return
    const audioContext = new window.AudioContext()

    fetch(audioRef.current.src)
      .then(response => response.arrayBuffer())
      .then(arrayBuffer => {
        return new Promise((resolve, reject) => {
          audioContext.decodeAudioData(
            arrayBuffer,
            buffer => resolve(buffer),
            error => reject(error),
          )
        })
      })
      .then(buffer => {
        setDuration((buffer as AudioBuffer).duration)
      })
  }, [])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants