/*\r
-* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
+* Copyright 2013 Sveriges Television AB http://casparcg.com/\r
*\r
* This file is part of CasparCG (www.casparcg.com).\r
*\r
CASPAR_ASSERT(decoded);\r
CASPAR_ASSERT(write->image_data(n).begin());\r
\r
- if(decoded_linesize != static_cast<int>(plane.width))\r
+ if(decoded_linesize != static_cast<int>(plane.linesize))\r
{\r
// Copy line by line since ffmpeg sometimes pads each line.\r
tbb::parallel_for<size_t>(0, desc.planes[n].height, [&](size_t y)\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
return is_valid_file(filename, invalid_exts);\r
}\r
\r
+bool try_get_duration(const std::wstring filename, std::int64_t& duration, boost::rational<std::int64_t>& time_base)\r
+{ \r
+ AVFormatContext* weak_context = nullptr;\r
+ if(avformat_open_input(&weak_context, narrow(filename).c_str(), nullptr, nullptr) < 0)\r
+ return false;\r
+\r
+ std::shared_ptr<AVFormatContext> context(weak_context, av_close_input_file);\r
+ \r
+ context->probesize = context->probesize / 10;\r
+ context->max_analyze_duration = context->probesize / 10;\r
+\r
+ if(avformat_find_stream_info(context.get(), nullptr) < 0)\r
+ return false;\r
+\r
+ const auto fps = read_fps(*context, 1.0);\r
+ \r
+ const auto rational_fps = boost::rational<std::int64_t>(static_cast<int>(fps * AV_TIME_BASE), AV_TIME_BASE);\r
+ \r
+ duration = boost::rational_cast<std::int64_t>(context->duration * rational_fps / AV_TIME_BASE);\r
+\r
+ if (rational_fps == 0)\r
+ return false;\r
+\r
+ time_base = 1/rational_fps;\r
+\r
+ return true;\r
+}\r
+\r
std::wstring probe_stem(const std::wstring stem, const std::vector<std::wstring>& invalid_exts)\r
{\r
auto stem2 = boost::filesystem2::wpath(stem);\r