\r
#include "ffmpeg_producer.h"\r
\r
-#include "../ffmpeg_error.h"\r
#include "../ffmpeg.h"\r
-#include "ffmpeg_params.h"\r
+#include "../ffmpeg_error.h"\r
+#include "../ffmpeg_params.h"\r
\r
#include "muxer/frame_muxer.h"\r
#include "input/input.h"\r
uint32_t file_frame_number_;\r
\r
public:\r
- explicit ffmpeg_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::wstring& filename, FFMPEG_Resource resource_type, const std::wstring& filter, bool loop, uint32_t start, uint32_t length, bool thumbnail_mode, const std::wstring& custom_channel_order, const ffmpeg_params& vid_params)\r
+ explicit ffmpeg_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::wstring& filename, FFMPEG_Resource resource_type, const std::wstring& filter, bool loop, uint32_t start, uint32_t length, bool thumbnail_mode, const std::wstring& custom_channel_order, const ffmpeg_producer_params& vid_params)\r
: filename_(filename)\r
, path_relative_to_media_(get_relative_or_original(filename, env::media_folder()))\r
, resource_type_(resource_type)\r
filename = probe_stem(filename);\r
\r
//TODO fix these?\r
- //ffmpeg_params->loop = params.has(L"LOOP");\r
- //ffmpeg_params->start = params.get(L"SEEK", static_cast<uint32_t>(0));\r
+ //vid_params->loop = params.has(L"LOOP");\r
+ //vid_params->start = params.get(L"SEEK", static_cast<uint32_t>(0));\r
}\r
\r
if(filename.empty())\r
\r
boost::replace_all(filter_str, L"DEINTERLACE", L"YADIF=0:-1");\r
boost::replace_all(filter_str, L"DEINTERLACE_BOB", L"YADIF=1:-1");\r
+ \r
+ ffmpeg_producer_params vid_params;\r
+ bool haveFFMPEGStartIndicator = false;\r
+ for (size_t i = 0; i < params.size() - 1; ++i)\r
+ {\r
+ if (!haveFFMPEGStartIndicator && params[i] == L"--")\r
+ {\r
+ haveFFMPEGStartIndicator = true;\r
+ continue;\r
+ }\r
+ if (haveFFMPEGStartIndicator)\r
+ {\r
+ auto name = narrow(params.at_original(i)).substr(1);\r
+ auto value = narrow(params.at_original(i + 1));\r
+ vid_params.options.push_back(option(name, value));\r
+ }\r
+ }\r
\r
- ffmpeg_params vid_params;\r
- vid_params.size_str = params.get(L"SIZE", L"");\r
- vid_params.pixel_format = params.get(L"PIXFMT", L"");\r
- vid_params.frame_rate = params.get(L"FRAMERATE", L"");\r
\r
return create_producer_destroy_proxy(make_safe<ffmpeg_producer>(frame_factory, filename, resource_type, filter_str, loop, start, length, false, custom_channel_order, vid_params));\r
}\r
auto start = 0;\r
auto length = std::numeric_limits<uint32_t>::max();\r
auto filter_str = L"";\r
- \r
- ffmpeg_params vid_params;\r
\r
+ ffmpeg_producer_params vid_params;\r
return make_safe<ffmpeg_producer>(frame_factory, filename, FFMPEG_FILE, filter_str, loop, start, length, true, L"", vid_params);\r
}\r
\r
#include "../util/util.h"\r
#include "../util/flv.h"\r
#include "../../ffmpeg_error.h"\r
+#include "../../ffmpeg_params.h"\r
#include "../../ffmpeg.h"\r
\r
#include <core/video_format.h>\r
#pragma warning (pop)\r
#endif\r
\r
-static const size_t MAX_BUFFER_COUNT = 100;\r
-static const size_t MIN_BUFFER_COUNT = 50;\r
-static const size_t MAX_BUFFER_SIZE = 64 * 1000000;\r
+static const size_t MAX_BUFFER_COUNT = 100;\r
+static const size_t MAX_BUFFER_COUNT_RT = 3;\r
+static const size_t MIN_BUFFER_COUNT = 50;\r
+static const size_t MAX_BUFFER_SIZE = 64 * 1000000;\r
\r
namespace caspar { namespace ffmpeg {\r
\r
\r
executor executor_;\r
\r
- explicit implementation(const safe_ptr<diagnostics::graph> graph, const std::wstring& filename, FFMPEG_Resource resource_type, bool loop, uint32_t start, uint32_t length, bool thumbnail_mode, const ffmpeg_params& vid_params) \r
+ explicit implementation(const safe_ptr<diagnostics::graph> graph, const std::wstring& filename, FFMPEG_Resource resource_type, bool loop, uint32_t start, uint32_t length, bool thumbnail_mode, const ffmpeg_producer_params& vid_params) \r
: graph_(graph)\r
, format_context_(open_input(filename, resource_type, vid_params)) \r
, default_stream_index_(av_find_default_stream_index(format_context_.get()))\r
});\r
} \r
\r
- safe_ptr<AVFormatContext> open_input(const std::wstring resource_name, FFMPEG_Resource resource_type, const ffmpeg_params& vid_params)\r
- {\r
- AVFormatContext* weak_context = nullptr;\r
-\r
- switch (resource_type) {\r
- case FFMPEG_FILE:\r
- THROW_ON_ERROR2(avformat_open_input(&weak_context, narrow(resource_name).c_str(), nullptr, nullptr), resource_name);\r
- break;\r
- case FFMPEG_DEVICE: {\r
- AVDictionary* format_options = NULL;\r
- if(vid_params.size_str != L"")\r
- av_dict_set(&format_options, "video_size", narrow(vid_params.size_str).c_str(), 0); // 640x360 for 16:9\r
- if(vid_params.pixel_format != L"")\r
- av_dict_set(&format_options, "pixel_format", narrow(vid_params.pixel_format).c_str(), 0); // yuyv422 for sony\r
- av_dict_set(&format_options, "avioflags", "direct", 0);\r
-\r
- // Don't set framerate here, it is typically set to a fixed rate anyway. Better to insert a fps filter to adjust the frame rate.\r
- // Im going to try anyway for now\r
- if(vid_params.frame_rate != L"")\r
- av_dict_set(&format_options, "framerate", narrow(vid_params.frame_rate).c_str(), 0);\r
- AVInputFormat* input_format = av_find_input_format("dshow");\r
- THROW_ON_ERROR2(avformat_open_input(&weak_context, narrow(resource_name).c_str(), input_format, &format_options), resource_name);\r
- av_dict_free(&format_options);\r
- } break;\r
- case FFMPEG_STREAM:\r
- THROW_ON_ERROR2(avformat_open_input(&weak_context, narrow(resource_name).c_str(), nullptr, nullptr), resource_name);\r
- break;\r
- };\r
- safe_ptr<AVFormatContext> context(weak_context, av_close_input_file); \r
- THROW_ON_ERROR2(avformat_find_stream_info(weak_context, nullptr), resource_name);\r
- fix_meta_data(*context);\r
- return context;\r
- }\r
+ safe_ptr<AVFormatContext> open_input(const std::wstring resource_name, FFMPEG_Resource resource_type, const ffmpeg_producer_params& vid_params)\r
+ {\r
+ AVFormatContext* weak_context = nullptr;\r
+\r
+ switch (resource_type) {\r
+ case FFMPEG_FILE:\r
+ THROW_ON_ERROR2(avformat_open_input(&weak_context, narrow(resource_name).c_str(), nullptr, nullptr), resource_name);\r
+ break;\r
+ case FFMPEG_DEVICE: {\r
+ AVDictionary* format_options = NULL;\r
+ for (auto it = vid_params.options.begin(); it != vid_params.options.end(); ++it)\r
+ {\r
+ av_dict_set(&format_options, (*it).name.c_str(), (*it).value.c_str(), 0);\r
+ }\r
+ AVInputFormat* input_format = av_find_input_format("dshow");\r
+ THROW_ON_ERROR2(avformat_open_input(&weak_context, narrow(resource_name).c_str(), input_format, &format_options), resource_name);\r
+ if (format_options != nullptr)\r
+ {\r
+ std::string unsupported_tokens = "";\r
+ AVDictionaryEntry *t = NULL;\r
+ while ((t = av_dict_get(format_options, "", t, AV_DICT_IGNORE_SUFFIX)) != nullptr)\r
+ {\r
+ if (!unsupported_tokens.empty())\r
+ unsupported_tokens += ", ";\r
+ unsupported_tokens += t->key;\r
+ }\r
+ av_close_input_file(weak_context);\r
+ BOOST_THROW_EXCEPTION(ffmpeg_error() << msg_info(unsupported_tokens));\r
+ }\r
+ av_dict_free(&format_options);\r
+ } break;\r
+ case FFMPEG_STREAM: {\r
+ AVDictionary* format_options = NULL;\r
+ for (auto it = vid_params.options.begin(); it != vid_params.options.end(); ++it)\r
+ {\r
+ av_dict_set(&format_options, (*it).name.c_str(), (*it).value.c_str(), 0);\r
+ }\r
+ THROW_ON_ERROR2(avformat_open_input(&weak_context, narrow(resource_name).c_str(), nullptr, &format_options), resource_name);\r
+ if (format_options != nullptr)\r
+ {\r
+ std::string unsupported_tokens = "";\r
+ AVDictionaryEntry *t = NULL;\r
+ while ((t = av_dict_get(format_options, "", t, AV_DICT_IGNORE_SUFFIX)) != nullptr)\r
+ {\r
+ if (!unsupported_tokens.empty())\r
+ unsupported_tokens += ", ";\r
+ unsupported_tokens += t->key;\r
+ }\r
+ av_close_input_file(weak_context);\r
+ BOOST_THROW_EXCEPTION(ffmpeg_error() << msg_info(unsupported_tokens));\r
+ }\r
+ av_dict_free(&format_options);\r
+ } break;\r
+ };\r
+ safe_ptr<AVFormatContext> context(weak_context, av_close_input_file); \r
+ THROW_ON_ERROR2(avformat_find_stream_info(weak_context, nullptr), resource_name);\r
+ fix_meta_data(*context);\r
+ return context;\r
+ }\r
\r
void fix_meta_data(AVFormatContext& context)\r
{\r
}\r
};\r
\r
-input::input(const safe_ptr<diagnostics::graph>& graph, const std::wstring& filename, FFMPEG_Resource resource_type, bool loop, uint32_t start, uint32_t length, bool thumbnail_mode, const ffmpeg_params& vid_params) \r
+input::input(const safe_ptr<diagnostics::graph>& graph, const std::wstring& filename, FFMPEG_Resource resource_type, bool loop, uint32_t start, uint32_t length, bool thumbnail_mode, const ffmpeg_producer_params& vid_params) \r
: impl_(new implementation(graph, filename, resource_type, loop, start, length, thumbnail_mode, vid_params)){}\r
bool input::eof() const {return !impl_->executor_.is_running();}\r
bool input::try_pop(std::shared_ptr<AVPacket>& packet){return impl_->try_pop(packet);}\r