Opened 3 months ago

Last modified 3 months ago

#6368 new defect

audio_preload broken

Reported by: alex3d Owned by:
Priority: normal Component: avformat
Version: git-master Keywords: audio_preload
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

When audio_preload option is set output media stream a/v interleaving is broken because of "wrong sign issue" in interleave_compare_dts.
I'm willing to provide patch solving this issue and also enabling audio stream shift in both directions (currently audio_preload is 0-int_max).
Probably audio_preload can be renamed to something like audio_shift? (it seems no one uses audio_preload option because of this issue)

libavformat/mux.c: (master branch)

static int interleave_compare_dts(AVFormatContext *s, AVPacket *next,
                                  AVPacket *pkt)
{
    AVStream *st  = s->streams[pkt->stream_index];
    AVStream *st2 = s->streams[next->stream_index];
    int comp      = av_compare_ts(next->dts, st2->time_base, pkt->dts,
                                  st->time_base);
    if (s->audio_preload && ((st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) != (st2->codecpar->codec_type == AVMEDIA_TYPE_AUDIO))) {
        int64_t ts = av_rescale_q(pkt ->dts, st ->time_base, AV_TIME_BASE_Q) - s->audio_preload*(st ->codecpar->codec_type == AVMEDIA_TYPE_AUDIO);
        int64_t ts2= av_rescale_q(next->dts, st2->time_base, AV_TIME_BASE_Q) - s->audio_preload*(st2->codecpar->codec_type == AVMEDIA_TYPE_AUDIO);
        if (ts == ts2) {
            ts= ( pkt ->dts* st->time_base.num*AV_TIME_BASE - s->audio_preload*(int64_t)(st ->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)* st->time_base.den)*st2->time_base.den
               -( next->dts*st2->time_base.num*AV_TIME_BASE - s->audio_preload*(int64_t)(st2->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)*st2->time_base.den)* st->time_base.den;
            ts2=0;
        }
        comp= (ts>ts2) - (ts<ts2); ///////// there should be (ts2>ts) - (ts2<ts) obviously
    }

    if (comp == 0)
        return pkt->stream_index < next->stream_index;
    return comp > 0;
}


Change History (1)

comment:1 Changed 3 months ago by cehoyos

Please either explain how to reproduce the issue or send a patch made with git format-patch to the FFmpeg development mailing list where patches are reviewed.

Note: See TracTickets for help on using tickets.