]> git.sesse.net Git - casparcg/commitdiff
Seeking fix from Robert Nagy. This needs testing!
authorronag <ronag@live.com>
Mon, 11 Nov 2013 21:58:25 +0000 (16:58 -0500)
committerTK3 <tomkaltz@gmail.com>
Mon, 11 Nov 2013 21:58:25 +0000 (16:58 -0500)
modules/ffmpeg/producer/input/input.cpp
modules/ffmpeg/producer/util/util.cpp

index d8f5bf0df9480f42022b4783f4a36e79697e853c..8f62f748e6d1d98a4380d90a65d7c77d8008010e 100644 (file)
@@ -41,6 +41,7 @@
 #include <tbb/atomic.h>\r
 #include <tbb/recursive_mutex.h>\r
 \r
+#include <boost/rational.hpp>\r
 #include <boost/range/algorithm.hpp>\r
 #include <boost/thread/condition_variable.hpp>\r
 #include <boost/thread/mutex.hpp>\r
@@ -349,11 +350,18 @@ struct input::implementation : boost::noncopyable
                }\r
                \r
                auto stream = format_context_->streams[default_stream_index_];\r
-               auto codec  = stream->codec;\r
-               auto fixed_target = (target*stream->time_base.den*codec->time_base.num)/(stream->time_base.num*codec->time_base.den)*codec->ticks_per_frame;\r
                \r
-               THROW_ON_ERROR2(avformat_seek_file(format_context_.get(), default_stream_index_, std::numeric_limits<int64_t>::min(), fixed_target, std::numeric_limits<int64_t>::max(), 0), print());          \r
                \r
+               auto fps = read_fps(*format_context_, 0.0);\r
+                               \r
+               THROW_ON_ERROR2(avformat_seek_file(\r
+                       format_context_.get(), \r
+                       default_stream_index_, \r
+                       std::numeric_limits<int64_t>::min(),\r
+                       static_cast<int64_t>((target / fps * stream->time_base.den) / stream->time_base.num),\r
+                       std::numeric_limits<int64_t>::max(), \r
+                       0), print());\r
+\r
                auto flush_packet       = create_packet();\r
                flush_packet->data      = nullptr;\r
                flush_packet->size      = 0;\r
index b34f0e29ad922103bda94f8f50b5044b56786847..635d1e449b39325d7cb96c79c82b631cc454f72d 100644 (file)
@@ -336,7 +336,15 @@ double read_fps(AVFormatContext& context, double fail_value)
        {\r
                const auto video_context = context.streams[video_index]->codec;\r
                const auto video_stream  = context.streams[video_index];\r
-                                               \r
+                                       \r
+               auto frame_rate_time_base = video_stream->avg_frame_rate;\r
+               std::swap(frame_rate_time_base.num, frame_rate_time_base.den);\r
\r
+               if(is_sane_fps(frame_rate_time_base))\r
+               {\r
+                       return static_cast<double>(frame_rate_time_base.den) / static_cast<double>(frame_rate_time_base.num);\r
+               }\r
+\r
                AVRational time_base = video_context->time_base;\r
 \r
                if(boost::filesystem2::path(context.filename).extension() == ".flv")\r