@@ -924,8 +924,13 @@ int AvFormatDecoder::OpenFile(RingBuffer *rbuffer, bool novideo,
924924
925925 fmt->flags &= ~AVFMT_NOFILE;
926926
927- if (!ringBuffer->isDVD () && !livetv)
927+ if (!ringBuffer->isDVD () && !ringBuffer->isBD () && !livetv)
928+ {
928929 av_estimate_timings (ic, 0 );
930+ // generate timings based on the video stream to avoid bogus ffmpeg
931+ // values for duration and bitrate
932+ av_update_stream_timings_video (ic);
933+ }
929934
930935 // Scan for the initial A/V streams
931936 ret = ScanStreams (novideo);
@@ -4951,4 +4956,59 @@ static int dts_decode_header(uint8_t *indata_ptr, int *rate,
49514956 return fsize;
49524957}
49534958
4959+ void AvFormatDecoder::av_update_stream_timings_video (AVFormatContext *ic)
4960+ {
4961+ int64_t start_time, start_time1, end_time, end_time1;
4962+ int64_t duration, duration1;
4963+ AVStream *st = NULL ;
4964+
4965+ start_time = INT64_MAX;
4966+ end_time = INT64_MIN;
4967+
4968+ for (uint i = 0 ; i < ic->nb_streams ; i++)
4969+ {
4970+ AVStream *st1 = ic->streams [i];
4971+ if (st1 && st1->codec ->codec_type == CODEC_TYPE_VIDEO)
4972+ {
4973+ st = st1;
4974+ break ;
4975+ }
4976+ }
4977+ if (!st)
4978+ return ;
4979+
4980+ duration = INT64_MIN;
4981+ if (st->start_time != (int64_t )AV_NOPTS_VALUE && st->time_base .den ) {
4982+ start_time1= av_rescale_q (st->start_time , st->time_base , AV_TIME_BASE_Q);
4983+ if (start_time1 < start_time)
4984+ start_time = start_time1;
4985+ if (st->duration != (int64_t )AV_NOPTS_VALUE) {
4986+ end_time1 = start_time1
4987+ + av_rescale_q (st->duration , st->time_base , AV_TIME_BASE_Q);
4988+ if (end_time1 > end_time)
4989+ end_time = end_time1;
4990+ }
4991+ }
4992+ if (st->duration != (int64_t )AV_NOPTS_VALUE) {
4993+ duration1 = av_rescale_q (st->duration , st->time_base , AV_TIME_BASE_Q);
4994+ if (duration1 > duration)
4995+ duration = duration1;
4996+ }
4997+ if (start_time != INT64_MAX) {
4998+ ic->start_time = start_time;
4999+ if (end_time != INT64_MIN) {
5000+ if (end_time - start_time > duration)
5001+ duration = end_time - start_time;
5002+ }
5003+ }
5004+ if (duration != INT64_MIN) {
5005+ ic->duration = duration;
5006+ if (ic->file_size > 0 ) {
5007+ /* compute the bitrate */
5008+ ic->bit_rate = (double )ic->file_size * 8.0 * AV_TIME_BASE /
5009+ (double )ic->duration ;
5010+ }
5011+ }
5012+ }
5013+
49545014/* vim: set expandtab tabstop=4 shiftwidth=4: */
0 commit comments