zhuker/lamejs

Slow encoding

floydback opened this issue · 4 comments

You write

Fast mp3 encoder written in JavaScript. On my machine it works 20x faster than realtime
but I have a problem with it.

I have demo.mp3 file with total duration 54 sec
On my machine
time sox demo.mp3 -C 256 ~/demo2.mp3
real 0m1.557s
user 0m1.527s
sys 0m0.018s

When I use lamejs encoding spend ~50 sec and it's too much!

Now I try to use another js encoder (https://higuma.github.io/mp3-lame-encoder-js/) and it spent only ~3sec!

What I do wrong? My code:

buffer // <-- decoded with web audio api AudioBuffer
let mp3buf = [];
let mp3encoder = new lamejs.Mp3Encoder(buffer.numberOfChannels, buffer.sampleRate, 192)
mp3buf.push(mp3encoder.encodeBuffer(buffer.getChannelData(0), buffer.getChannelData(1)))
mp3buf.push(mp3encoder.flush())
let blob = new Blob(mp3buf, { type: 'audio/mp3' })

@floydback are you using the npm package? I've managed to reduce the encoding time by nearly 6 times with the help of UglifyJs.

Actually, their minified version seems to be even faster, you should use it.

I'm in the same boat right now. I have > 5 min wav file. It took me 7-8mins to convert. Can you show me how you can reduce the encoding time? I'm using React.

In firefox is much faster than in chrome. Strange.

My bad. The minified version works fast.