From b847ef40e2f9a13f54315518be45d5ff11276632 Mon Sep 17 00:00:00 2001
From: Karl Dietz <dekarl@mythtv.org>
Date: Sun, 27 Apr 2014 02:19:55 +0200
Subject: [PATCH 1/5] use av_guess_frame_rate from ffmpeg 2.2+ to replace own
guesswork
Fixes #12047
---
mythtv/libs/libmythtv/avformatdecoder.cpp | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/mythtv/libs/libmythtv/avformatdecoder.cpp b/mythtv/libs/libmythtv/avformatdecoder.cpp
index 412806c..55c9b27 100644
|
a
|
b
|
int AvFormatDecoder::OpenFile(RingBuffer *rbuffer, bool novideo,
|
| 1357 | 1357 | |
| 1358 | 1358 | float AvFormatDecoder::normalized_fps(AVStream *stream, AVCodecContext *enc) |
| 1359 | 1359 | { |
| 1360 | | float fps, avg_fps, codec_fps, container_fps, estimated_fps; |
| 1361 | | avg_fps = codec_fps = container_fps = estimated_fps = 0.0f; |
| 1362 | | |
| | 1360 | float fps, avg_fps, codec_fps, container_fps, estimated_fps, guess_fps; |
| | 1361 | avg_fps = codec_fps = container_fps = estimated_fps = guess_fps = 0.0f; |
| | 1362 | |
| | 1363 | /* |
| | 1364 | * Let ffmpeg do the guessing instead of duplicating their work. |
| | 1365 | * Only use our guess when ffmpeg doesn't come up with anything |
| | 1366 | * >3fps |
| | 1367 | */ |
| | 1368 | guess_fps = av_q2d(av_guess_frame_rate(ic, stream, NULL)); |
| | 1369 | |
| | 1370 | /* this is not a good source for FPS according to |
| | 1371 | * https://trac.bunkus.org/wiki/FAQ:WrongFrameRateDisplayed |
| | 1372 | */ |
| 1363 | 1373 | if (stream->avg_frame_rate.den && stream->avg_frame_rate.num) |
| 1364 | 1374 | avg_fps = av_q2d(stream->avg_frame_rate); // MKV default_duration |
| 1365 | 1375 | |
| … |
… |
float AvFormatDecoder::normalized_fps(AVStream *stream, AVCodecContext *enc)
|
| 1378 | 1388 | if (stream->r_frame_rate.den && stream->r_frame_rate.num) // tbr |
| 1379 | 1389 | estimated_fps = av_q2d(stream->r_frame_rate); |
| 1380 | 1390 | |
| | 1391 | if (guess_fps > 3.0f) |
| | 1392 | { |
| | 1393 | fps = guess_fps; |
| | 1394 | } |
| 1381 | 1395 | // matroska demuxer sets the default_duration to avg_frame_rate |
| 1382 | 1396 | // mov,mp4,m4a,3gp,3g2,mj2 demuxer sets avg_frame_rate |
| 1383 | | if ((QString(ic->iformat->name).contains("matroska") || |
| | 1397 | else if ((QString(ic->iformat->name).contains("matroska") || |
| 1384 | 1398 | QString(ic->iformat->name).contains("mov")) && |
| 1385 | 1399 | avg_fps < 121.0f && avg_fps > 3.0f) |
| 1386 | 1400 | fps = avg_fps; |
| … |
… |
float AvFormatDecoder::normalized_fps(AVStream *stream, AVCodecContext *enc)
|
| 1401 | 1415 | if (fps != m_fps) |
| 1402 | 1416 | { |
| 1403 | 1417 | LOG(VB_PLAYBACK, LOG_INFO, LOC + |
| 1404 | | QString("Selected FPS is %1 (avg %2 codec %3 " |
| | 1418 | QString("Selected FPS is %1 (guess %6 avg %2 codec %3 " |
| 1405 | 1419 | "container %4 estimated %5)").arg(fps).arg(avg_fps) |
| 1406 | | .arg(codec_fps).arg(container_fps).arg(estimated_fps)); |
| | 1420 | .arg(codec_fps).arg(container_fps).arg(estimated_fps) |
| | 1421 | .arg(guess_fps)); |
| 1407 | 1422 | m_fps = fps; |
| 1408 | 1423 | } |
| 1409 | 1424 | |