]> git.sesse.net Git - casparcg/blobdiff - modules/ffmpeg/consumer/ffmpeg_consumer.cpp
2.0.2: - Updated get_param.
[casparcg] / modules / ffmpeg / consumer / ffmpeg_consumer.cpp
index 129d31917020140110d67112def8d05ed7a60420..2a93beac856441b32c6a231e228d286750e58dd8 100644 (file)
@@ -1,21 +1,22 @@
 /*\r
-* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
 *\r
-*  This ffmpeg is part of CasparCG.\r
+* This file is part of CasparCG (www.casparcg.com).\r
 *\r
-*    CasparCG is free software: you can redistribute it and/or modify\r
-*    it under the terms of the GNU General Public License as published by\r
-*    the Free Software Foundation, either version 3 of the License, or\r
-*    (at your option) any later version.\r
+* CasparCG is free software: you can redistribute it and/or modify\r
+* it under the terms of the GNU General Public License as published by\r
+* the Free Software Foundation, either version 3 of the License, or\r
+* (at your option) any later version.\r
 *\r
-*    CasparCG is distributed in the hope that it will be useful,\r
-*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-*    GNU General Public License for more details.\r
-\r
-*    You should have received a copy of the GNU General Public License\r
-*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+* CasparCG is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+* GNU General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU General Public License\r
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
 *\r
+* Author: Robert Nagy, ronag89@gmail.com\r
 */\r
  \r
 #include "../StdAfx.h"\r
 \r
 #include <common/concurrency/executor.h>\r
 #include <common/diagnostics/graph.h>\r
-#include <common/utility/string.h>\r
 #include <common/env.h>\r
+#include <common/utility/string.h>\r
+#include <common/utility/param.h>\r
 \r
-#include <boost/timer.hpp>\r
-#include <boost/thread/once.hpp>\r
-#include <boost/thread.hpp>\r
 #include <boost/algorithm/string.hpp>\r
+#include <boost/timer.hpp>\r
+#include <boost/property_tree/ptree.hpp>\r
 \r
 #include <tbb/cache_aligned_allocator.h>\r
 #include <tbb/parallel_invoke.h>\r
 \r
-#include <cstdio>\r
-\r
 #if defined(_MSC_VER)\r
 #pragma warning (push)\r
 #pragma warning (disable : 4244)\r
@@ -182,6 +181,7 @@ public:
                c->time_base.den        = format_desc_.time_scale;\r
                c->time_base.num        = format_desc_.duration;\r
                c->gop_size                     = 25;\r
+               c->flags                   |= format_desc_.field_mode == core::field_mode::progressive ? 0 : (CODEC_FLAG_INTERLACED_ME | CODEC_FLAG_INTERLACED_DCT);\r
 \r
                if(c->codec_id == CODEC_ID_PRORES)\r
                {                       \r
@@ -384,14 +384,14 @@ struct ffmpeg_consumer_proxy : public core::frame_consumer
 {\r
        const std::wstring      filename_;\r
        const bool                      key_only_;\r
-       const std::string       codec_;\r
-       const std::string       options_;\r
+       const std::wstring      codec_;\r
+       const std::wstring      options_;\r
 \r
        std::unique_ptr<ffmpeg_consumer> consumer_;\r
 \r
 public:\r
 \r
-       ffmpeg_consumer_proxy(const std::wstring& filename, bool key_only, const std::string codec, const std::string& options)\r
+       ffmpeg_consumer_proxy(const std::wstring& filename, bool key_only, const std::wstring codec, const std::wstring& options)\r
                : filename_(filename)\r
                , key_only_(key_only)\r
                , codec_(boost::to_lower_copy(codec))\r
@@ -402,7 +402,7 @@ public:
        virtual void initialize(const core::video_format_desc& format_desc, int)\r
        {\r
                consumer_.reset();\r
-               consumer_.reset(new ffmpeg_consumer(narrow(filename_), format_desc, codec_, options_));\r
+               consumer_.reset(new ffmpeg_consumer(narrow(filename_), format_desc, narrow(codec_), narrow(options_)));\r
        }\r
        \r
        virtual bool send(const safe_ptr<core::read_frame>& frame) override\r
@@ -415,6 +415,17 @@ public:
        {\r
                return consumer_ ? consumer_->print() : L"[ffmpeg_consumer]";\r
        }\r
+\r
+       virtual boost::property_tree::wptree info() const override\r
+       {\r
+               boost::property_tree::wptree info;\r
+               info.add(L"type", L"ffmpeg-consumer");\r
+               info.add(L"key-only", key_only_);\r
+               info.add(L"filename", filename_);\r
+               info.add(L"codec", codec_);\r
+               info.add(L"options", options_);\r
+               return info;\r
+       }\r
                \r
        virtual bool has_synchronization_clock() const override\r
        {\r
@@ -437,37 +448,30 @@ safe_ptr<core::frame_consumer> create_consumer(const std::vector<std::wstring>&
        if(params.size() < 1 || params[0] != L"FILE")\r
                return core::frame_consumer::empty();\r
        \r
-       auto filename = (params.size() > 1 ? params[1] : L"");\r
-\r
-       bool key_only = std::find(params.begin(), params.end(), L"KEY_ONLY") != params.end();\r
-\r
-       std::string codec = "libx264";\r
-       auto codec_it = std::find(params.begin(), params.end(), L"CODEC");\r
-       if(codec_it != params.end() && codec_it++ != params.end())\r
-               codec = narrow(*codec_it);\r
-\r
-       if(codec == "H264")\r
-               codec = "libx264";\r
+       auto filename   = (params.size() > 1 ? params[1] : L"");\r
+       bool key_only   = get_param(L"KEY_ONLY", params, false);\r
+       auto codec              = get_param(L"CODEC", params, L"libx264");\r
+       auto options    = get_param(L"OPTIONS", params);\r
+       \r
+       if(codec == L"H264")\r
+               codec = L"libx264";\r
 \r
-       if(codec == "DVCPRO")\r
-               codec = "dvvideo";\r
+       if(codec == L"DVCPRO")\r
+               codec = L"dvvideo";\r
 \r
-       std::string options = "";\r
-       auto options_it = std::find(params.begin(), params.end(), L"OPTIONS");\r
-       if(options_it != params.end() && options_it++ != params.end())\r
-               options = narrow(*options_it);\r
+       boost::to_lower(options);\r
 \r
-       return make_safe<ffmpeg_consumer_proxy>(env::media_folder() + filename, key_only, codec, boost::to_lower_copy(options));\r
+       return make_safe<ffmpeg_consumer_proxy>(env::media_folder() + filename, key_only, codec, options);\r
 }\r
 \r
 safe_ptr<core::frame_consumer> create_consumer(const boost::property_tree::ptree& ptree)\r
 {\r
        std::string filename = ptree.get<std::string>("path");\r
        auto key_only            = ptree.get("key-only", false);\r
-       auto codec                       = ptree.get("codec", "dnxhd");\r
+       auto codec                       = ptree.get("codec", "libx264");\r
        auto options             = ptree.get("options", "");\r
        \r
-       return make_safe<ffmpeg_consumer_proxy>(env::media_folder() + widen(filename), key_only, codec, options);\r
+       return make_safe<ffmpeg_consumer_proxy>(env::media_folder() + widen(filename), key_only, widen(codec), widen(options));\r
 }\r
 \r
 }}\r