Streampunk / beamcoder

Node.js native bindings to FFmpeg.
GNU General Public License v3.0
399 stars 76 forks source link

Muxing aac from pcm into mp4 file #57

Closed felicemarra closed 3 years ago

felicemarra commented 3 years ago

I'm trying to make a mp4 from raw video yuv frames and pcm_f32l as input. Video it's ok but audio doesn't work. Silence.

` let encParamsVideo = { name: 'h264_nvenc', width: 1280, height: 720, bit_rate: 20000000, time_base: [1, 30], framerate: [30, 1], gop_size: 10, max_b_frames: 0, pix_fmt: 'yuv420p', }; let encParamsAudio = {

    name: 'aac',
    time_base: [1, 48000],
    sample_fmt: 'fltp',
    sample_rate: 48000,
    bit_rate: 48000,
    channel_layout: 'mono',
    channels: 1

};

let encoderVideo = await beamcoder.encoder(encParamsVideo);
let encoderAudio = await beamcoder.encoder(encParamsAudio);

encoderAudio.priv_data = { preset: 'LC' };

const muxer = beamcoder.muxer({ format_name: 'mp4' });

let vstr = muxer.newStream({
    name: 'h264_nvenc',
    time_base: [1, 90000],
    interleaved: false
});
Object.assign(vstr.codecpar, {
    width: 1280,
    height: 720,
    format: 'yuv420p',
    bit_rate: 20000000
});

let astr = muxer.newStream({
    name: 'aac',
    time_base: [1, 48000],
    interleaved: false
});
Object.assign(astr.codecpar, {
    name: 'aac',
    sample_rate: 48000,
    format: 'fltp',
    frame_size: 1024,
    channels: 1,
    channel_layout: 'mono',
    bit_rate: 48000,
    bits_per_sample: 32
});

`

audio frame structure

let destFrameAudio = beamcoder.frame({ channels: 1, nb_samples: 1024, format: 'fltp', channel_layout: 'mono', sample_rate: 48000, }).alloc();

than... if I try to use ffprobe "profile" field is unknown and bit rate is very high.. 75777075... something is wrong...

index=1 codec_name=aac codec_long_name=AAC (Advanced Audio Coding) profile=unknown codec_type=audio codec_time_base=1/48000 codec_tag_string=mp4a codec_tag=0x6134706d sample_fmt=fltp sample_rate=48000 channels=2 channel_layout=stereo bits_per_sample=0 id=N/A r_frame_rate=0/0 avg_frame_rate=0/0 time_base=1/48000 start_pts=4464 start_time=0.093000 duration_ts=476 duration=0.009917 bit_rate=75777075 max_bit_rate=75777075 bits_per_raw_sample=N/A nb_frames=476 nb_read_frames=N/A nb_read_packets=N/A

What can I do?

scriptorian commented 3 years ago

I believe that the bit_rate property should be in bits - so 4 (float32) * 8 (bits per byte) times bigger. Also the bits_per_sample property should be a bits_per_coded_sample property. In my testing I appear to have used interleaved: true - it would worth trying that. I hope that helps.

felicemarra commented 3 years ago

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();

metawrap-dev commented 2 years ago

I have the same issue :(