summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTaylor Ralph <tralph@mythtv.org>2011-01-05 03:57:57 (GMT)
committer Taylor Ralph <tralph@mythtv.org>2011-01-05 04:09:35 (GMT)
commit415b883de3e2ca0b4559a5ac7fb9f91651883995 (patch)
tree7a4517c30b59badf3cd538a28157b33ade3ec52e
parent2d85d703f01041d709098dfd6ec24b96a6999704 (diff)
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.
-rw-r--r--mythtv/libs/libmythtv/avformatdecoder.cpp62
-rw-r--r--mythtv/libs/libmythtv/avformatdecoder.h1
2 files changed, 62 insertions, 1 deletions
diff --git a/mythtv/libs/libmythtv/avformatdecoder.cpp b/mythtv/libs/libmythtv/avformatdecoder.cpp
index 7941911..23719d1 100644
--- a/mythtv/libs/libmythtv/avformatdecoder.cpp
+++ b/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: */
diff --git a/mythtv/libs/libmythtv/avformatdecoder.h b/mythtv/libs/libmythtv/avformatdecoder.h
index 8f7e40f..0f79b66 100644
--- a/mythtv/libs/libmythtv/avformatdecoder.h
+++ b/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;