Skip to content

Commit 415b883

Browse files
committed
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.
1 parent 2d85d70 commit 415b883

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

mythtv/libs/libmythtv/avformatdecoder.cpp

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: */

mythtv/libs/libmythtv/avformatdecoder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ class AvFormatDecoder : public DecoderBase
232232
bool GenerateDummyVideoFrame(void);
233233
bool HasVideo(const AVFormatContext *ic);
234234
float normalized_fps(AVStream *stream, AVCodecContext *enc);
235+
void av_update_stream_timings_video(AVFormatContext *ic);
235236

236237
private:
237238
PrivateDecoder *private_dec;

0 commit comments

Comments
 (0)