Closed kartikdutt18 closed 6 months ago
It's generally harmless for pts to be 0. Division by zero in handling frames or packets usually has to do with the timebase, not the timestamps, but the way you're handling the timebase appears correct... my suspicion would be that the time_base
isn't set properly by your mysterious ff_add_stream
function, or that it's not set properly by the input decoder, and somehow that lack of timebase is flowing through. Basically: take a look at some of the timebases and see if those are suspicious first.
Ah, I'll try to take a look thank you so much! For reference, this is my add_stream_method:
libav.ff_add_stream = function (
oc: number,
// eslint-disable-next-line @typescript-eslint/ban-types
codecparms: number | object,
time_base_num: number,
time_base_den: number,
) {
const st = libav.avformat_new_stream(oc, 0);
if (st === 0) throw new Error('Could not allocate stream');
const codecpar = libav.AVStream_codecpar(st);
let ret = 0;
if (typeof codecparms === 'number') {
ret = libav.avcodec_parameters_from_context(codecpar, codecparms);
} else {
ret = libav.ff_set_codecpar(codecpar, codecparms);
}
if (ret < 0) throw new Error('Could not copy the stream parameters: ' + libav.ff_error(ret));
libav.AVStream_time_base_s(st, time_base_num, time_base_den);
const pkt = libav.av_packet_alloc();
if (pkt === 0) throw new Error('Could not allocate packet');
const sti = libav.AVFormatContext_nb_streams(oc) - 1;
return [sti, pkt];
};```
I'm also using this to add another stream created by h264 codec containing the video from another source so resultant output is mp4 with audio and video from different sources.
Hi @Yahweasel, I tried logging the time base at add_stream_method for the st stream created and the time_base_num and time_base_den are correct. Also, after demuxing, the stream had a defined timebase: 1 / 28224000. Could you please take another look at this please, I've hit a roadblock and not able to figure out a way ahead
That timebase is clearly madness. You cannot have a timebase of 1/28224000. An audio file would typically have a timebase of 1/samplerate.
I cannot reproduce any issue. This file transcodes fine with both tools/ffmpeg.js
and an adapted version of 611-transcode-video.js
. I'm going to assume that you're missing some error, no aac demuxer configured or similar.
Hi @Yahweasel These are the flags I'm using and I have tried with multiple audio files the timebase is usually that high, is there something missing from this, can you please help me or point me in some direction I should decode:
--enable-protocol=data --enable-protocol=file --enable-filter=aresample --enable-decoder=aac --enable-encoder=aac --enable-libopenh264 --enable-muxer=mp4 --enable-parser=aac --enable-demuxer=mp4 --enable-demuxer=mov --enable-muxer=adts --enable-demuxer=aac --enable-decoder=libopenh264 --enable-encoder=libopenh264 --enable-filter=acompressor --enable-filter=adeclick --enable-filter=adeclip --enable-filter=aecho --enable-filter=afade --enable-filter=aformat --enable-filter=agate --enable-filter=alimiter --enable-filter=amix --enable-filter=apad --enable-filter=atempo --enable-filter=atrim --enable-filter=bandpass --enable-filter=bandreject --enable-filter=dynaudnorm --enable-filter=equalizer --enable-filter=loudnorm --enable-filter=pan --enable-filter=amix --enable-filter=volume
On calling encode frames, the below code throws an error: Runtime division by 0 in av_interleaved_frames. On debugging the issue, the pts values for packets and frame is 0. File used: https://filesamples.com/samples/audio/aac/sample3.aac (Using mp4 files work but not aac)
The pts values are 0 after we get them from ff_decode_multi, even if set the pts manually as done in flattenFrames it doesn't work.
Hi @Yahweasel, can you please help me in understanding the issue here, thank you!
Sharing code below for reference: