libavformat/utils: Treat subtitle streams as noninterleaved when 20 seconds have passed without a packet
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
@ -3220,17 +3220,41 @@ static int ff_interleave_compare_dts(AVFormatContext *s, AVPacket *next, AVPacke
|
|||||||
|
|
||||||
int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush){
|
int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush){
|
||||||
AVPacketList *pktl;
|
AVPacketList *pktl;
|
||||||
int stream_count=0;
|
int stream_count=0, noninterleaved_count=0;
|
||||||
|
int64_t delta_dts_min = INT64_MAX;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if(pkt){
|
if(pkt){
|
||||||
ff_interleave_add_packet(s, pkt, ff_interleave_compare_dts);
|
ff_interleave_add_packet(s, pkt, ff_interleave_compare_dts);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i=0; i < s->nb_streams; i++)
|
for(i=0; i < s->nb_streams; i++) {
|
||||||
stream_count+= !!s->streams[i]->last_in_packet_buffer;
|
if (s->streams[i]->last_in_packet_buffer) {
|
||||||
|
int64_t delta_dts =
|
||||||
|
av_rescale_q(s->streams[i]->last_in_packet_buffer->pkt.dts,
|
||||||
|
s->streams[i]->time_base,
|
||||||
|
AV_TIME_BASE_Q) -
|
||||||
|
av_rescale_q(s->packet_buffer->pkt.dts,
|
||||||
|
s->streams[s->packet_buffer->pkt.stream_index]->time_base,
|
||||||
|
AV_TIME_BASE_Q);
|
||||||
|
if (delta_dts < delta_dts_min)
|
||||||
|
delta_dts_min = delta_dts;
|
||||||
|
++stream_count;
|
||||||
|
} else {
|
||||||
|
if(s->streams[i]->codec->codec_type == AVMEDIA_TYPE_SUBTITLE)
|
||||||
|
++noninterleaved_count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(stream_count && (s->nb_streams == stream_count || flush)){
|
if (s->nb_streams == stream_count) {
|
||||||
|
flush = 1;
|
||||||
|
} else if (!flush &&
|
||||||
|
s->nb_streams == stream_count+noninterleaved_count &&
|
||||||
|
delta_dts_min > 20*AV_TIME_BASE) {
|
||||||
|
av_log(s, AV_LOG_DEBUG, "flushing with %d noninterleaved\n", noninterleaved_count);
|
||||||
|
flush = 1;
|
||||||
|
}
|
||||||
|
if(stream_count && flush){
|
||||||
pktl= s->packet_buffer;
|
pktl= s->packet_buffer;
|
||||||
*out= pktl->pkt;
|
*out= pktl->pkt;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user