Skip to content

Commit a7acb7b

Browse files
committed
avformatdecoder: improve fps detection in normalized_fps()
This should fix issues with mov style containers by using the avg_frame_rate which is set by the demuxer. NOTE: Using estimated_fps seems to always be accurate for everything except matroska and mov. It appears that ffmpeg takes into account the codec and container fps when generating estimated_fps. Also, XBMC uses estimated_fps for everything except matroska. We should probably do the same. Fixes #10300. (cherry picked from commit 6c22eda)
1 parent a6727fc commit a7acb7b

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

mythtv/libs/libmythtv/avformatdecoder.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,50 +1079,53 @@ int AvFormatDecoder::OpenFile(RingBuffer *rbuffer, bool novideo,
10791079

10801080
float AvFormatDecoder::normalized_fps(AVStream *stream, AVCodecContext *enc)
10811081
{
1082-
float fps, avg_fps, stream_fps, container_fps, estimated_fps;
1083-
avg_fps = stream_fps = container_fps = estimated_fps = 0.0f;
1082+
float fps, avg_fps, codec_fps, container_fps, estimated_fps;
1083+
avg_fps = codec_fps = container_fps = estimated_fps = 0.0f;
10841084

10851085
if (stream->avg_frame_rate.den && stream->avg_frame_rate.num)
10861086
avg_fps = av_q2d(stream->avg_frame_rate); // MKV default_duration
10871087

10881088
if (enc->time_base.den && enc->time_base.num) // tbc
1089-
stream_fps = 1.0f / av_q2d(enc->time_base) / enc->ticks_per_frame;
1089+
codec_fps = 1.0f / av_q2d(enc->time_base) / enc->ticks_per_frame;
10901090
// Some formats report fps waaay too high. (wrong time_base)
1091-
if (stream_fps > 121.0f && (enc->time_base.den > 10000) &&
1091+
if (codec_fps > 121.0f && (enc->time_base.den > 10000) &&
10921092
(enc->time_base.num == 1))
10931093
{
10941094
enc->time_base.num = 1001; // seems pretty standard
10951095
if (av_q2d(enc->time_base) > 0)
1096-
stream_fps = 1.0f / av_q2d(enc->time_base);
1096+
codec_fps = 1.0f / av_q2d(enc->time_base);
10971097
}
10981098
if (stream->time_base.den && stream->time_base.num) // tbn
10991099
container_fps = 1.0f / av_q2d(stream->time_base);
11001100
if (stream->r_frame_rate.den && stream->r_frame_rate.num) // tbr
11011101
estimated_fps = av_q2d(stream->r_frame_rate);
11021102

1103-
if (QString(ic->iformat->name).contains("matroska") &&
1103+
// matroska demuxer sets the default_duration to avg_frame_rate
1104+
// mov,mp4,m4a,3gp,3g2,mj2 demuxer sets avg_frame_rate
1105+
if ((QString(ic->iformat->name).contains("matroska") ||
1106+
QString(ic->iformat->name).contains("mov")) &&
11041107
avg_fps < 121.0f && avg_fps > 3.0f)
1105-
fps = avg_fps; // matroska default_duration
1106-
else if (QString(ic->iformat->name).contains("avi") &&
1108+
fps = avg_fps;
1109+
else if (QString(ic->iformat->name).contains("avi") &&
11071110
container_fps < 121.0f && container_fps > 3.0f)
11081111
fps = container_fps; // avi uses container fps for timestamps
1109-
else if (stream_fps < 121.0f && stream_fps > 3.0f)
1110-
fps = stream_fps;
1111-
else if (container_fps < 121.0f && container_fps > 3.0f)
1112+
else if (codec_fps < 121.0f && codec_fps > 3.0f)
1113+
fps = codec_fps;
1114+
else if (container_fps < 121.0f && container_fps > 3.0f)
11121115
fps = container_fps;
1113-
else if (estimated_fps < 70.0f && estimated_fps > 20.0f)
1116+
else if (estimated_fps < 121.0f && estimated_fps > 3.0f)
11141117
fps = estimated_fps;
1118+
else if (avg_fps < 121.0f && avg_fps > 3.0f)
1119+
fps = avg_fps;
11151120
else
1116-
fps = stream_fps;
1121+
fps = 30000.0f / 1001.0f; // 29.97 fps
11171122

1118-
// If it is still out of range, just assume NTSC...
1119-
fps = (fps > 121.0f) ? (30000.0f / 1001.0f) : fps;
11201123
if (fps != m_fps)
11211124
{
11221125
VERBOSE(VB_PLAYBACK, LOC +
1123-
QString("Selected FPS is %1 (avg %2 stream %3 "
1126+
QString("Selected FPS is %1 (avg %2 codec %3 "
11241127
"container %4 estimated %5)").arg(fps).arg(avg_fps)
1125-
.arg(stream_fps).arg(container_fps).arg(estimated_fps));
1128+
.arg(codec_fps).arg(container_fps).arg(estimated_fps));
11261129
m_fps = fps;
11271130
}
11281131

0 commit comments

Comments
 (0)