Fill DTS if all packets have been read in avformat_find_stream_info, and still has_decode_delay_been_guessed returns false.
Signed-off-by: Sasi Inguva <is...@google.com> --- libavformat/utils.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/libavformat/utils.c b/libavformat/utils.c index 5f48de1..f22309d 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -877,6 +877,7 @@ static int has_decode_delay_been_guessed(AVStream *st) avpriv_h264_has_num_reorder_frames(st->codec) == st->codec->has_b_frames) return 1; #endif + if (st->codec->has_b_frames<3) return st->nb_decoded_frames >= 7; else if (st->codec->has_b_frames<4) @@ -3165,6 +3166,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) int64_t max_stream_analyze_duration; int64_t max_subtitle_analyze_duration; int64_t probesize = ic->probesize; + int eof_reached = 0; flush_codecs = probesize > 0; @@ -3331,6 +3333,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) if (ret < 0) { /* EOF or error*/ + eof_reached = 1; break; } @@ -3454,6 +3457,40 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) count++; } + if (eof_reached && ic->internal->packet_buffer) { + int stream_index; + for (stream_index = 0; stream_index < ic->nb_streams; stream_index++) { + AVPacketList *pktl = ic->internal->packet_buffer; + int64_t pts_buffer[MAX_REORDER_DELAY+1]; + + // EOF already reached while reading the stream above. + // So continue with reoordering DTS with whatever delay we have. + int codec_delay = st->codec->has_b_frames; + + st = ic->streams[stream_index]; + + if (st->codec->codec_id != AV_CODEC_ID_H264 || + has_decode_delay_been_guessed(st)) { + continue; + } + + + for (; pktl; pktl = get_next_pkt(ic, st, pktl)) { + if (pktl->pkt.stream_index != stream_index) + continue; + + if (pktl->pkt.pts != AV_NOPTS_VALUE && codec_delay <= MAX_REORDER_DELAY) { + int j; + pts_buffer[0] = pktl->pkt.pts; + for (j = 0; j < codec_delay && pts_buffer[j] > pts_buffer[j + 1]; j++) + FFSWAP(int64_t, pts_buffer[j], pts_buffer[j + 1]); + + pktl->pkt.dts = select_from_pts_buffer(st, pts_buffer, pktl->pkt.dts); + } + } + } + } + if (flush_codecs) { AVPacket empty_pkt = { 0 }; int err = 0; -- 2.7.0.rc3.207.g0ac5344 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel