#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
}\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
{\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