]> git.sesse.net Git - casparcg/blobdiff - modules/ffmpeg/producer/input/input.cpp
Seeking fix from Robert Nagy. This needs testing!
[casparcg] / modules / ffmpeg / producer / input / input.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