Code Monkey home page Code Monkey logo

Comments (8)

scriptorian avatar scriptorian commented on September 23, 2024 1

Hi,

I'm guessing that your AAC encoding problem that is causing the garbles is that the encoder requires data to be submitted as (typically) 1024 samples. In the past I have written a 'dicer' buffer to achieve this. You will find an example in beamstreams.js (Line 28 onwards) if that is any help.
As for the encoder creation crash, I have found that the AAC codec doesn't provide an array of supported profiles as normally expected and the code doesn't handle this correctly, hence the crash. I'll fix the crash in a future update but using the numeric value (1 in this case) avoids this problem and worked for me, giving the correct profile when read back from the encoder and the codecpar in the resulting muxer stream having used your creation code.
I'm afraid you will also run into the problem pointed out in #35 - I haven't done the work to support the bitstream filters.
Good luck!

from beamcoder.

ccantill avatar ccantill commented on September 23, 2024

Thanks for the hint. That dicer helps a little bit. On one stream it at least renders an audio stream that somewhat resembles the original (but with distortion). On another stream it gives me the same problems I had when I tried to transcode to AAC using the pipeline config: it starts spewing [aac @ 0x6d6fc0] Queue input is backward in time and [aac @ 0x6d6fc0] Input contains (near) NaN/+-Inf after the first couple of frames.

So then I tried adding a asetnsamples=n=1024:p=1 filter instead, which works better; the resulting frames are all 1024 samples and there are no errors with either input stream. The sound is perfect this time, but the video is still sped up.

EDIT: I found the issue with the incorrect profile in codecpar when opening the resulting file. Copying the extradata property from the encoder to the codecpar in the stream fixes it.

from beamcoder.

scriptorian avatar scriptorian commented on September 23, 2024

After my comment yesterday I tried to use my scratch mp4 maker and found the same Nan/Inf problem. I eventually tracked it down to a line of code in the dicer that presumably is getting different data with the updated version of FFmpeg. I have fixed that now and it all seems to work as expected with clean audio.
asetnsamples=n=1024:p=1 is a good choice to replace the hand rolled dicer - I hadn't found that filter when I was last playing here but I have used it successfully since.
The crash at the end is annoying. I had a brief look at the code and apart from a cryptic comment next to it I can't get much idea of what is causing it to go wrong. I had a quick look at your latest code and wondered if it could be caused by you having missed an await on the recodeAndWrite call at the end so the flush might be getting in before the last encode.

from beamcoder.

ccantill avatar ccantill commented on September 23, 2024

Yup, it's the await. Just found it too. Still looking into the video timing issue. I'm logging the pts for each packet upon writing and it seems to look fine, so I'm not sure yet what's going wrong.

from beamcoder.

ccantill avatar ccantill commented on September 23, 2024

Found the issue with the timing as well now. Apparently the timebase is forcefully set to [1,16000] by the muxer. Compensating for that fixes it. Strange that the stream resulting from muxer.newStream doesn't reflect that new timebase correctly, but hardcoding it to [1,16000] works.

from beamcoder.

scriptorian avatar scriptorian commented on September 23, 2024

Great - I'm glad its all working now.

from beamcoder.

ccantill avatar ccantill commented on September 23, 2024

Me too, thanks for the assistance!

from beamcoder.

felicemarra avatar felicemarra commented on September 23, 2024

I'm sorry.. I'm decoding aac frames from raw pcm and raw video frames. I receive the same error message "Input contains (near) NaN/+-Inf" I tried to make an example to reproduce the issue with a virgin frame of 1024 samples. If you try to run it you receive this error. Not always but often.. I don't understand what I'm doing wrong.. can you help me?

const beamcoder = require('beamcoder');

let encParamsAudio = {
name: 'aac',
time_base: [1, 48000],
sample_fmt: 'fltp',
sample_rate: 48000,
bit_rate: 192000,
channel_layout: 'stereo',
channels: 2
}

async function run() {
let encoderAudio = await beamcoder.encoder(encParamsAudio);
for (var i = 0; i < 200; i++) {
let destFrameAudio = beamcoder.frame({
channels: 2,
nb_samples: 1024,
format: 'fltp',
channel_layout: 'stereo',
sample_rate: 48000,
pkt_size: 1024 * 4 * 2
}).alloc();
let packetsAudio = await encoderAudio.encode(destFrameAudio);
}
}

run();

from beamcoder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.