Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Backport fix for bitrate and duration detection.

This should improve ringbuffer performance for some hd-pvr and broadcast recordings where an odd stream will cause a bogus bitrate and duration.
  • Loading branch information...
commit 415b883de3e2ca0b4559a5ac7fb9f91651883995 1 parent 2d85d70
@tralph tralph authored
View
62 mythtv/libs/libmythtv/avformatdecoder.cpp
@@ -924,8 +924,13 @@ int AvFormatDecoder::OpenFile(RingBuffer *rbuffer, bool novideo,
fmt->flags &= ~AVFMT_NOFILE;
- if (!ringBuffer->isDVD() && !livetv)
+ if (!ringBuffer->isDVD() && !ringBuffer->isBD() && !livetv)
+ {
av_estimate_timings(ic, 0);
+ // generate timings based on the video stream to avoid bogus ffmpeg
+ // values for duration and bitrate
+ av_update_stream_timings_video(ic);
+ }
// Scan for the initial A/V streams
ret = ScanStreams(novideo);
@@ -4951,4 +4956,59 @@ static int dts_decode_header(uint8_t *indata_ptr, int *rate,
return fsize;
}
+void AvFormatDecoder::av_update_stream_timings_video(AVFormatContext *ic)
+{
+ int64_t start_time, start_time1, end_time, end_time1;
+ int64_t duration, duration1;
+ AVStream *st = NULL;
+
+ start_time = INT64_MAX;
+ end_time = INT64_MIN;
+
+ for (uint i = 0; i < ic->nb_streams; i++)
+ {
+ AVStream *st1 = ic->streams[i];
+ if (st1 && st1->codec->codec_type == CODEC_TYPE_VIDEO)
+ {
+ st = st1;
+ break;
+ }
+ }
+ if (!st)
+ return;
+
+ duration = INT64_MIN;
+ if (st->start_time != (int64_t)AV_NOPTS_VALUE && st->time_base.den) {
+ start_time1= av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q);
+ if (start_time1 < start_time)
+ start_time = start_time1;
+ if (st->duration != (int64_t)AV_NOPTS_VALUE) {
+ end_time1 = start_time1
+ + av_rescale_q(st->duration, st->time_base, AV_TIME_BASE_Q);
+ if (end_time1 > end_time)
+ end_time = end_time1;
+ }
+ }
+ if (st->duration != (int64_t)AV_NOPTS_VALUE) {
+ duration1 = av_rescale_q(st->duration, st->time_base, AV_TIME_BASE_Q);
+ if (duration1 > duration)
+ duration = duration1;
+ }
+ if (start_time != INT64_MAX) {
+ ic->start_time = start_time;
+ if (end_time != INT64_MIN) {
+ if (end_time - start_time > duration)
+ duration = end_time - start_time;
+ }
+ }
+ if (duration != INT64_MIN) {
+ ic->duration = duration;
+ if (ic->file_size > 0) {
+ /* compute the bitrate */
+ ic->bit_rate = (double)ic->file_size * 8.0 * AV_TIME_BASE /
+ (double)ic->duration;
+ }
+ }
+}
+
/* vim: set expandtab tabstop=4 shiftwidth=4: */
View
1  mythtv/libs/libmythtv/avformatdecoder.h
@@ -232,6 +232,7 @@ class AvFormatDecoder : public DecoderBase
bool GenerateDummyVideoFrame(void);
bool HasVideo(const AVFormatContext *ic);
float normalized_fps(AVStream *stream, AVCodecContext *enc);
+ void av_update_stream_timings_video(AVFormatContext *ic);
private:
PrivateDecoder *private_dec;
Please sign in to comment.
Something went wrong with that request. Please try again.