Opened 7 years ago

Closed 5 years ago

Last modified 5 years ago

#6368 closed defect (fixed)

audio_preload broken

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


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

comment:1 by Carl Eugen Hoyos, 7 years ago

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.

comment:2 by mkver, 5 years ago

Resolution: fixed
Status: newclosed

comment:3 by Carl Eugen Hoyos, 5 years ago

Keywords: audio_preload removed
Note: See TracTickets for help on using tickets.