[Libav-user] audio_preload broken

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[Libav-user] audio_preload broken

Alexander Shumsky
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)

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 ==
         int64_t ts2= av_rescale_q(next->dts, st2->time_base,
AV_TIME_BASE_Q) - s->audio_preload*(st2->codecpar->codec_type ==
         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;

С уважением, Шумский Александр
Компания NetUP

Libav-user mailing list
[hidden email]