All pastes #1951530 Raw Edit

Mine

public text v1 · immutable
#1951530 ·published 2010-09-30 03:06 UTC
rendered paste body
Index: libs/libmythtv/avformatdecoder.cpp
===================================================================
--- libs/libmythtv/avformatdecoder.cpp	(revision 26550)
+++ libs/libmythtv/avformatdecoder.cpp	(working copy)
@@ -1064,36 +1064,44 @@
     return recordingHasPositionMap;
 }
 
-static float normalized_fps(AVStream *stream, AVCodecContext *enc)
+float AvFormatDecoder::normalized_fps(AVStream *stream, AVCodecContext *enc)
 {
-    float fps = 1.0f / av_q2d(enc->time_base) / enc->ticks_per_frame;
+    float fps, stream_fps, container_fps, matroska_fps, estimated_fps, ntsc_fps;
 
+    matroska_fps = 0.0f;
+    if (QString(ic->iformat->name).contains("matroska"))
+        matroska_fps = av_q2d(stream->avg_frame_rate); // default_duration in MKV
+
+    stream_fps = 1.0f / av_q2d(enc->time_base) / enc->ticks_per_frame;
     // Some formats report fps waaay too high. (wrong time_base)
-    if (fps > 121.0f && (enc->time_base.den > 10000) &&
+    if (stream_fps > 121.0f && (enc->time_base.den > 10000) &&
         (enc->time_base.num == 1))
     {
         enc->time_base.num = 1001;  // seems pretty standard
         if (av_q2d(enc->time_base) > 0)
-            fps = 1.0f / av_q2d(enc->time_base);
+            stream_fps = 1.0f / av_q2d(enc->time_base);
     }
-    // If it's still wonky, try the container's time_base
-    if (fps > 121.0f || fps < 3.0f)
-    {
-        float tmpfps = 1.0f / av_q2d(stream->time_base);
-        if (tmpfps > 20 && tmpfps < 70)
-            fps = tmpfps;
-    }
+    container_fps = 1.0f / av_q2d(stream->time_base);
+    estimated_fps = av_q2d(stream->r_frame_rate);
+    ntsc_fps = 30000.0f / 1001.0f;
 
-    // and finally try the ffmpeg estimated rate
-    if (fps > 121.0f || fps < 3.0f)
-    {
-        float tmpfps = av_q2d(stream->r_frame_rate);
-        if (tmpfps > 20 && tmpfps < 70)
-            fps = tmpfps;
-    }
+    if (matroska_fps < 121.0f && matroska_fps > 3.0f)
+        fps = matroska_fps;
+    else if (stream_fps < 121.0f && stream_fps > 3.0f) 
+        fps = stream_fps;
+    else if (container_fps < 121.0f && container_fps > 3.0f) 
+        fps = container_fps;
+    else if (estimated_fps < 70.0f && estimated_fps > 20.0f) 
+        fps = estimated_fps;
+    else if (ntsc_fps < 121.0f)
+        fps = ntsc_fps;
+    else
+        fps = stream_fps;
 
-    // If it is still out of range, just assume NTSC...
-    fps = (fps > 121.0f) ? (30000.0f / 1001.0f) : fps;
+    VERBOSE(VB_PLAYBACK, LOC +
+            QString("Selected FPS is %1 (matroska %2 stream %3 "
+                    "container %4 estimated %5)").arg(fps).arg(matroska_fps)
+                    .arg(stream_fps).arg(container_fps).arg(estimated_fps));
     return fps;
 }
 
Index: libs/libmythtv/avformatdecoder.h
===================================================================
--- libs/libmythtv/avformatdecoder.h	(revision 26550)
+++ libs/libmythtv/avformatdecoder.h	(working copy)
@@ -232,6 +232,7 @@
 
     bool GenerateDummyVideoFrame(void);
     bool HasVideo(const AVFormatContext *ic);
+    float normalized_fps(AVStream *stream, AVCodecContext *enc);
 
   private:
     PrivateDecoder *private_dec;