[Libav-user] audio_preload broken

Alexander Shumsky alex3d at netup.ru
Fri Apr 21 11:08:53 EEST 2017


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:
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;
}


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



More information about the Libav-user mailing list