]> git.sesse.net Git - casparcg/blobdiff - modules/ffmpeg/producer/ffmpeg_producer.cpp
* Working server startup in Linux
[casparcg] / modules / ffmpeg / producer / ffmpeg_producer.cpp
index 6f41f6c6e8399eff2ace00f8c8ed415f401e3bd2..faa9bf847f5c686413cc19e2ed391e6c753aaa03 100644 (file)
-/*\r
-* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
-*\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
-*\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 "ffmpeg_producer.h"\r
-\r
-#include "../ffmpeg_error.h"\r
-\r
-#include "muxer/frame_muxer.h"\r
-#include "input/input.h"\r
-#include "util/util.h"\r
-#include "audio/audio_decoder.h"\r
-#include "video/video_decoder.h"\r
-\r
-#include <common/env.h>\r
-#include <common/log.h>\r
-#include <common/utility/param.h>\r
-#include <common/diagnostics/graph.h>\r
-\r
-#include <core/video_format.h>\r
-#include <core/producer/frame_producer.h>\r
-#include <core/producer/frame/frame_factory.h>\r
-#include <core/producer/frame/basic_frame.h>\r
-#include <core/producer/frame/frame_transform.h>\r
-\r
-#include <boost/algorithm/string.hpp>\r
-#include <common/assert.h>\r
-#include <boost/assign.hpp>\r
-#include <boost/timer.hpp>\r
-#include <boost/foreach.hpp>\r
-#include <boost/filesystem.hpp>\r
-#include <boost/range/algorithm/find_if.hpp>\r
-#include <boost/range/algorithm/find.hpp>\r
-#include <boost/property_tree/ptree.hpp>\r
-#include <boost/regex.hpp>\r
-#include <boost/thread/future.hpp>\r
-\r
-#include <tbb/parallel_invoke.h>\r
-\r
-#include <limits>\r
-#include <memory>\r
-#include <queue>\r
-\r
-namespace caspar { namespace ffmpeg {\r
-                               \r
-struct ffmpeg_producer : public core::frame_producer\r
-{\r
-       const std::wstring                                                                                      filename_;\r
-       \r
-       const safe_ptr<diagnostics::graph>                                                      graph_;\r
-       boost::timer                                                                                            frame_timer_;\r
-                                       \r
-       const safe_ptr<core::frame_factory>                                                     frame_factory_;\r
-       const core::video_format_desc                                                           format_desc_;\r
-\r
-       input                                                                                                           input_; \r
-       std::unique_ptr<video_decoder>                                                          video_decoder_;\r
-       std::unique_ptr<audio_decoder>                                                          audio_decoder_; \r
-       std::unique_ptr<frame_muxer>                                                            muxer_;\r
-\r
-       const double                                                                                            fps_;\r
-       const uint32_t                                                                                          start_;\r
-       const uint32_t                                                                                          length_;\r
-\r
-       safe_ptr<core::basic_frame>                                                                     last_frame_;\r
-       \r
-       std::queue<std::pair<safe_ptr<core::basic_frame>, uint32_t>>    frame_buffer_;\r
-\r
-       int64_t                                                                                                         frame_number_;\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, const std::wstring& filter, bool loop, uint32_t start, uint32_t length) \r
-               : filename_(filename)\r
-               , frame_factory_(frame_factory)         \r
-               , format_desc_(frame_factory->get_video_format_desc())\r
-               , input_(graph_, filename_, loop, start, length)\r
-               , fps_(read_fps(*input_.context(), format_desc_.fps))\r
-               , start_(start)\r
-               , length_(length)\r
-               , last_frame_(core::basic_frame::empty())\r
-               , frame_number_(0)\r
-       {\r
-               graph_->set_color("frame-time", diagnostics::color(0.1f, 1.0f, 0.1f));\r
-               graph_->set_color("underflow", diagnostics::color(0.6f, 0.3f, 0.9f));   \r
-               diagnostics::register_graph(graph_);\r
-               \r
-               try\r
-               {\r
-                       video_decoder_.reset(new video_decoder(input_.context()));\r
-                       CASPAR_LOG(info) << print() << L" " << video_decoder_->print();\r
-               }\r
-               catch(averror_stream_not_found&)\r
-               {\r
-                       //CASPAR_LOG(warning) << print() << " No video-stream found. Running without video.";   \r
-               }\r
-               catch(...)\r
-               {\r
-                       CASPAR_LOG_CURRENT_EXCEPTION();\r
-                       CASPAR_LOG(warning) << print() << "Failed to open video-stream. Running without video.";        \r
-               }\r
-\r
-               try\r
-               {\r
-                       audio_decoder_.reset(new audio_decoder(input_.context(), frame_factory->get_video_format_desc()));\r
-                       CASPAR_LOG(info) << print() << L" " << audio_decoder_->print();\r
-               }\r
-               catch(averror_stream_not_found&)\r
-               {\r
-                       //CASPAR_LOG(warning) << print() << " No audio-stream found. Running without audio.";   \r
-               }\r
-               catch(...)\r
-               {\r
-                       CASPAR_LOG_CURRENT_EXCEPTION();\r
-                       CASPAR_LOG(warning) << print() << " Failed to open audio-stream. Running without audio.";               \r
-               }       \r
-\r
-               if(!video_decoder_ && !audio_decoder_)\r
-                       BOOST_THROW_EXCEPTION(averror_stream_not_found() << msg_info("No streams found"));\r
-\r
-               muxer_.reset(new frame_muxer(fps_, frame_factory, filter));\r
-       }\r
-\r
-       // frame_producer\r
-       \r
-       virtual safe_ptr<core::basic_frame> receive(int flags) override\r
-       {               \r
-               frame_timer_.restart();\r
-                               \r
-               for(int n = 0; n < 16 && frame_buffer_.size() < 2; ++n)\r
-                       try_decode_frame(flags);\r
-               \r
-               graph_->set_value("frame-time", frame_timer_.elapsed()*format_desc_.fps*0.5);\r
-                               \r
-               if(frame_buffer_.empty() && input_.eof())\r
-                       return disable_audio(last_frame());\r
-\r
-               if(frame_buffer_.empty())\r
-               {\r
-                       graph_->set_tag("underflow");   \r
-                       return core::basic_frame::late();                       \r
-               }\r
-               \r
-               auto frame = frame_buffer_.front(); \r
-               frame_buffer_.pop();\r
-               \r
-               ++frame_number_;\r
-               file_frame_number_ = frame.second;\r
-\r
-               graph_->set_text(print());\r
-\r
-               return last_frame_ = frame.first;\r
-       }\r
-\r
-       virtual safe_ptr<core::basic_frame> last_frame() const override\r
-       {\r
-               return last_frame_;\r
-       }\r
-\r
-       virtual uint32_t nb_frames() const override\r
-       {\r
-               if(input_.loop())\r
-                       return std::numeric_limits<uint32_t>::max();\r
-\r
-               uint32_t nb_frames = file_nb_frames();\r
-\r
-               nb_frames = std::min(length_, nb_frames);\r
-               nb_frames = muxer_->calc_nb_frames(nb_frames);\r
-               \r
-               return nb_frames > start_ ? nb_frames - start_ : 0;\r
-       }\r
-\r
-       uint32_t file_nb_frames() const\r
-       {\r
-               uint32_t file_nb_frames = 0;\r
-               file_nb_frames = std::max(file_nb_frames, video_decoder_ ? video_decoder_->nb_frames() : 0);\r
-               file_nb_frames = std::max(file_nb_frames, audio_decoder_ ? audio_decoder_->nb_frames() : 0);\r
-               return file_nb_frames;\r
-       }\r
-       \r
-       virtual boost::unique_future<std::wstring> call(const std::wstring& param) override\r
-       {\r
-               boost::promise<std::wstring> promise;\r
-               promise.set_value(do_call(param));\r
-               return promise.get_future();\r
-       }\r
-                               \r
-       virtual std::wstring print() const override\r
-       {\r
-               return L"ffmpeg[" + boost::filesystem::path(filename_).filename().wstring() + L"|" \r
-                                                 + print_mode() + L"|" \r
-                                                 + boost::lexical_cast<std::wstring>(file_frame_number_) + L"/" + boost::lexical_cast<std::wstring>(file_nb_frames()) + L"]";\r
-       }\r
-\r
-       boost::property_tree::wptree info() const override\r
-       {\r
-               boost::property_tree::wptree info;\r
-               info.add(L"type",                               L"ffmpeg-producer");\r
-               info.add(L"filename",                   filename_);\r
-               info.add(L"width",                              video_decoder_ ? video_decoder_->width() : 0);\r
-               info.add(L"height",                             video_decoder_ ? video_decoder_->height() : 0);\r
-               info.add(L"progressive",                video_decoder_ ? video_decoder_->is_progressive() : false);\r
-               info.add(L"fps",                                fps_);\r
-               info.add(L"loop",                               input_.loop());\r
-               info.add(L"frame-number",               frame_number_);\r
-               auto nb_frames2 = nb_frames();\r
-               info.add(L"nb-frames",                  nb_frames2 == std::numeric_limits<int64_t>::max() ? -1 : nb_frames2);\r
-               info.add(L"file-frame-number",  file_frame_number_);\r
-               info.add(L"file-nb-frames",             file_nb_frames());\r
-               return info;\r
-       }\r
-\r
-       // ffmpeg_producer\r
-\r
-       std::wstring print_mode() const\r
-       {\r
-               return video_decoder_ ? ffmpeg::print_mode(video_decoder_->width(), video_decoder_->height(), fps_, !video_decoder_->is_progressive()) : L"";\r
-       }\r
-                                       \r
-       std::wstring do_call(const std::wstring& param)\r
-       {\r
-               static const boost::wregex loop_exp(L"LOOP\\s*(?<VALUE>\\d?)?", boost::regex::icase);\r
-               static const boost::wregex seek_exp(L"SEEK\\s+(?<VALUE>\\d+)", boost::regex::icase);\r
-               \r
-               boost::wsmatch what;\r
-               if(boost::regex_match(param, what, loop_exp))\r
-               {\r
-                       if(!what["VALUE"].str().empty())\r
-                               input_.loop(boost::lexical_cast<bool>(what["VALUE"].str()));\r
-                       return boost::lexical_cast<std::wstring>(input_.loop());\r
-               }\r
-               if(boost::regex_match(param, what, seek_exp))\r
-               {\r
-                       input_.seek(boost::lexical_cast<uint32_t>(what["VALUE"].str()));\r
-                       return L"";\r
-               }\r
-\r
-               BOOST_THROW_EXCEPTION(invalid_argument());\r
-       }\r
-\r
-       void try_decode_frame(int flags)\r
-       {\r
-               std::shared_ptr<AVPacket> pkt;\r
-\r
-               for(int n = 0; n < 32 && ((video_decoder_ && !video_decoder_->ready()) || (audio_decoder_ && !audio_decoder_->ready())) && input_.try_pop(pkt); ++n)\r
-               {\r
-                       if(video_decoder_)\r
-                               video_decoder_->push(pkt);\r
-                       if(audio_decoder_)\r
-                               audio_decoder_->push(pkt);\r
-               }\r
-               \r
-               std::shared_ptr<AVFrame>                        video;\r
-               std::shared_ptr<core::audio_buffer> audio;\r
-\r
-               tbb::parallel_invoke(\r
-               [&]\r
-               {\r
-                       if(!muxer_->video_ready() && video_decoder_)    \r
-                               video = video_decoder_->poll(); \r
-               },\r
-               [&]\r
-               {               \r
-                       if(!muxer_->audio_ready() && audio_decoder_)            \r
-                               audio = audio_decoder_->poll();         \r
-               });\r
-               \r
-               muxer_->push(video, flags);\r
-               muxer_->push(audio);\r
-\r
-               if(!audio_decoder_)\r
-               {\r
-                       if(video == flush_video())\r
-                               muxer_->push(flush_audio());\r
-                       else if(!muxer_->audio_ready())\r
-                               muxer_->push(empty_audio());\r
-               }\r
-\r
-               if(!video_decoder_)\r
-               {\r
-                       if(audio == flush_audio())\r
-                               muxer_->push(flush_video(), 0);\r
-                       else if(!muxer_->video_ready())\r
-                               muxer_->push(empty_video(), 0);\r
-               }\r
-               \r
-               uint32_t file_frame_number = 0;\r
-               file_frame_number = std::max(file_frame_number, video_decoder_ ? video_decoder_->file_frame_number() : 0);\r
-               //file_frame_number = std::max(file_frame_number, audio_decoder_ ? audio_decoder_->file_frame_number() : 0);\r
-\r
-               for(auto frame = muxer_->poll(); frame; frame = muxer_->poll())\r
-                       frame_buffer_.push(std::make_pair(make_safe_ptr(frame), file_frame_number));\r
-       }\r
-};\r
-\r
-safe_ptr<core::frame_producer> create_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::vector<std::wstring>& params)\r
-{              \r
-       auto filename = probe_stem(env::media_folder() + L"\\" + params.at(0));\r
-\r
-       if(filename.empty())\r
-               return core::frame_producer::empty();\r
-       \r
-       auto loop               = boost::range::find(params, L"LOOP") != params.end();\r
-       auto start              = get_param(L"SEEK", params, static_cast<uint32_t>(0));\r
-       auto length             = get_param(L"LENGTH", params, std::numeric_limits<uint32_t>::max());\r
-       auto filter_str = get_param(L"FILTER", params, L"");    \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
-       return create_producer_destroy_proxy(make_safe<ffmpeg_producer>(frame_factory, filename, filter_str, loop, start, length));\r
-}\r
-\r
-}}
\ No newline at end of file
+/*
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
+*
+* This file is part of CasparCG (www.casparcg.com).
+*
+* CasparCG is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* CasparCG is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
+*
+* Author: Robert Nagy, ronag89@gmail.com
+*/
+
+#include "../StdAfx.h"
+
+#include "ffmpeg_producer.h"
+
+#include "../ffmpeg_error.h"
+
+#include "muxer/frame_muxer.h"
+#include "input/input.h"
+#include "util/util.h"
+#include "audio/audio_decoder.h"
+#include "video/video_decoder.h"
+
+#include <common/env.h>
+#include <common/log.h>
+#include <common/param.h>
+#include <common/diagnostics/graph.h>
+#include <common/future.h>
+
+#include <core/video_format.h>
+#include <core/producer/frame_producer.h>
+#include <core/frame/frame_factory.h>
+#include <core/frame/draw_frame.h>
+#include <core/frame/frame_transform.h>
+#include <core/monitor/monitor.h>
+
+#include <boost/algorithm/string.hpp>
+#include <common/assert.h>
+#include <boost/timer.hpp>
+#include <boost/filesystem.hpp>
+#include <boost/property_tree/ptree.hpp>
+#include <boost/regex.hpp>
+#include <boost/thread/future.hpp>
+
+#include <tbb/parallel_invoke.h>
+
+#include <limits>
+#include <memory>
+#include <queue>
+
+namespace caspar { namespace ffmpeg {
+
+std::wstring get_relative_or_original(
+               const std::wstring& filename,
+               const boost::filesystem::wpath& relative_to)
+{
+       boost::filesystem::wpath file(filename);
+       auto result = file.filename().wstring();
+
+       boost::filesystem::wpath current_path = file;
+
+       while (true)
+       {
+               current_path = current_path.parent_path();
+
+               if (boost::filesystem::equivalent(current_path, relative_to))
+                       break;
+
+               if (current_path.empty())
+                       return filename;
+
+               result = current_path.filename().wstring() + L"/" + result;
+       }
+
+       return result;
+}
+
+struct ffmpeg_producer : public core::frame_producer_base
+{
+       spl::shared_ptr<core::monitor::subject>                 monitor_subject_;
+       const std::wstring                                                              filename_;
+       const std::wstring                                                              path_relative_to_media_ = get_relative_or_original(filename_, env::media_folder());
+       
+       const spl::shared_ptr<diagnostics::graph>               graph_;
+                                       
+       const spl::shared_ptr<core::frame_factory>              frame_factory_;
+       const core::video_format_desc                                   format_desc_;
+
+       input                                                                                   input_; 
+
+       const double                                                                    fps_                                    = read_fps(input_.context(), format_desc_.fps);
+       const uint32_t                                                                  start_;
+               
+       std::unique_ptr<video_decoder>                                  video_decoder_;
+       std::unique_ptr<audio_decoder>                                  audio_decoder_; 
+       frame_muxer                                                                             muxer_;
+       core::constraints                                                               constraints_;
+       
+       core::draw_frame                                                                last_frame_                             = core::draw_frame::empty();
+
+       boost::optional<uint32_t>                                               seek_target_;
+       
+public:
+       explicit ffmpeg_producer(const spl::shared_ptr<core::frame_factory>& frame_factory, 
+                                                        const core::video_format_desc& format_desc, 
+                                                        const std::wstring& filename, 
+                                                        const std::wstring& filter, 
+                                                        bool loop, 
+                                                        uint32_t start, 
+                                                        uint32_t length) 
+               : filename_(filename)
+               , frame_factory_(frame_factory)         
+               , format_desc_(format_desc)
+               , input_(graph_, filename_, loop, start, length)
+               , fps_(read_fps(input_.context(), format_desc_.fps))
+               , muxer_(fps_, frame_factory, format_desc_, filter)
+               , start_(start)
+       {
+               graph_->set_color("frame-time", diagnostics::color(0.1f, 1.0f, 0.1f));
+               graph_->set_color("underflow", diagnostics::color(0.6f, 0.3f, 0.9f));   
+               diagnostics::register_graph(graph_);
+               
+
+               try
+               {
+                       video_decoder_.reset(new video_decoder(input_));
+                       video_decoder_->monitor_output().attach_parent(monitor_subject_);
+                       constraints_.width.set(video_decoder_->width());
+                       constraints_.height.set(video_decoder_->height());
+                       
+                       CASPAR_LOG(info) << print() << L" " << video_decoder_->print();
+               }
+               catch(averror_stream_not_found&)
+               {
+                       //CASPAR_LOG(warning) << print() << " No video-stream found. Running without video.";   
+               }
+               catch(...)
+               {
+                       CASPAR_LOG_CURRENT_EXCEPTION();
+                       CASPAR_LOG(warning) << print() << "Failed to open video-stream. Running without video.";        
+               }
+
+               try
+               {
+                       audio_decoder_ .reset(new audio_decoder(input_, format_desc_));
+                       audio_decoder_->monitor_output().attach_parent(monitor_subject_);
+                       
+                       CASPAR_LOG(info) << print() << L" " << audio_decoder_->print();
+               }
+               catch(averror_stream_not_found&)
+               {
+                       //CASPAR_LOG(warning) << print() << " No audio-stream found. Running without audio.";   
+               }
+               catch(...)
+               {
+                       CASPAR_LOG_CURRENT_EXCEPTION();
+                       CASPAR_LOG(warning) << print() << " Failed to open audio-stream. Running without audio.";               
+               }       
+               
+               decode_next_frame();
+
+               CASPAR_LOG(info) << print() << L" Initialized";
+       }
+
+       // frame_producer
+       
+       core::draw_frame receive_impl() override
+       {                               
+               auto frame = core::draw_frame::late();          
+               
+               boost::timer frame_timer;
+               
+               end_seek();
+                               
+               decode_next_frame();
+               
+               if(!muxer_.empty())
+               {
+                       last_frame_ = frame = std::move(muxer_.front());
+                       muxer_.pop();   
+               }
+               else                            
+                       graph_->set_tag("underflow");
+                                                                       
+               graph_->set_value("frame-time", frame_timer.elapsed()*format_desc_.fps*0.5);
+               *monitor_subject_
+                               << core::monitor::message("/profiler/time")     % frame_timer.elapsed() % (1.0/format_desc_.fps);                       
+               *monitor_subject_
+                               << core::monitor::message("/file/time")         % (file_frame_number()/fps_) 
+                                                                                                                       % (file_nb_frames()/fps_)
+                               << core::monitor::message("/file/frame")        % static_cast<int32_t>(file_frame_number())
+                                                                                                                       % static_cast<int32_t>(file_nb_frames())
+                               << core::monitor::message("/file/fps")          % fps_
+                               << core::monitor::message("/file/path")         % path_relative_to_media_
+                               << core::monitor::message("/loop")                      % input_.loop();
+                                               
+               return frame;
+       }
+
+       core::draw_frame last_frame() override
+       {
+               end_seek();
+               return core::draw_frame::still(last_frame_);
+       }
+
+       core::constraints& pixel_constraints() override
+       {
+               return constraints_;
+       }
+
+       uint32_t nb_frames() const override
+       {
+               if(input_.loop())
+                       return std::numeric_limits<uint32_t>::max();
+
+               uint32_t nb_frames = file_nb_frames();
+
+               nb_frames = std::min(input_.length(), nb_frames);
+               nb_frames = muxer_.calc_nb_frames(nb_frames);
+               
+               return nb_frames > start_ ? nb_frames - start_ : 0;
+       }
+
+       uint32_t file_nb_frames() const
+       {
+               uint32_t file_nb_frames = 0;
+               file_nb_frames = std::max(file_nb_frames, video_decoder_ ? video_decoder_->nb_frames() : 0);
+               file_nb_frames = std::max(file_nb_frames, audio_decoder_ ? audio_decoder_->nb_frames() : 0);
+               return file_nb_frames;
+       }
+
+       uint32_t file_frame_number() const
+       {
+               return video_decoder_ ? video_decoder_->file_frame_number() : 0;
+       }
+               
+       std::future<std::wstring> call(const std::vector<std::wstring>& params) override
+       {
+               static const boost::wregex loop_exp(LR"(LOOP\s*(?<VALUE>\d?)?)", boost::regex::icase);
+               static const boost::wregex seek_exp(LR"(SEEK\s+(?<VALUE>\d+))", boost::regex::icase);
+               static const boost::wregex length_exp(LR"(LENGTH\s+(?<VALUE>\d+)?)", boost::regex::icase);
+               static const boost::wregex start_exp(LR"(START\\s+(?<VALUE>\\d+)?)", boost::regex::icase);
+
+               auto param = boost::algorithm::join(params, L" ");
+               
+               std::wstring result;
+                       
+               boost::wsmatch what;
+               if(boost::regex_match(param, what, loop_exp))
+               {
+                       auto value = what["VALUE"].str();
+                       if(!value.empty())
+                               input_.loop(boost::lexical_cast<bool>(value));
+                       result = boost::lexical_cast<std::wstring>(loop());
+               }
+               else if(boost::regex_match(param, what, seek_exp))
+               {
+                       auto value = what["VALUE"].str();
+                       seek(boost::lexical_cast<uint32_t>(value));
+               }
+               else if(boost::regex_match(param, what, length_exp))
+               {
+                       auto value = what["VALUE"].str();
+                       if(!value.empty())
+                               length(boost::lexical_cast<uint32_t>(value));                   
+                       result = boost::lexical_cast<std::wstring>(length());
+               }
+               else if(boost::regex_match(param, what, start_exp))
+               {
+                       auto value = what["VALUE"].str();
+                       if(!value.empty())
+                               start(boost::lexical_cast<uint32_t>(value));
+                       result = boost::lexical_cast<std::wstring>(start());
+               }
+               else
+                       CASPAR_THROW_EXCEPTION(invalid_argument());
+
+               return make_ready_future(std::move(result));
+       }
+                               
+       std::wstring print() const override
+       {
+               return L"ffmpeg[" + boost::filesystem::path(filename_).filename().wstring() + L"|" 
+                                                 + print_mode() + L"|" 
+                                                 + boost::lexical_cast<std::wstring>(file_frame_number()) + L"/" + boost::lexical_cast<std::wstring>(file_nb_frames()) + L"]";
+       }
+
+       std::wstring name() const override
+       {
+               return L"ffmpeg";
+       }
+
+       boost::property_tree::wptree info() const override
+       {
+               boost::property_tree::wptree info;
+               info.add(L"type",                               L"ffmpeg");
+               info.add(L"filename",                   filename_);
+               info.add(L"width",                              video_decoder_ ? video_decoder_->width() : 0);
+               info.add(L"height",                             video_decoder_ ? video_decoder_->height() : 0);
+               info.add(L"progressive",                video_decoder_ ? video_decoder_->is_progressive() : 0);
+               info.add(L"fps",                                fps_);
+               info.add(L"loop",                               input_.loop());
+               info.add(L"frame-number",               frame_number());
+               auto nb_frames2 = nb_frames();
+               info.add(L"nb-frames",                  nb_frames2 == std::numeric_limits<int64_t>::max() ? -1 : nb_frames2);
+               info.add(L"file-frame-number",  file_frame_number());
+               info.add(L"file-nb-frames",             file_nb_frames());
+               return info;
+       }
+       
+       core::monitor::subject& monitor_output()
+       {
+               return *monitor_subject_;
+       }
+
+       // ffmpeg_producer
+       
+       void end_seek()
+       {
+               for(int n = 0; n < 8 && (last_frame_ == core::draw_frame::empty() || (seek_target_ && file_frame_number() != *seek_target_+2)); ++n)
+               {
+                       decode_next_frame();
+                       if(!muxer_.empty())
+                       {
+                               last_frame_ = muxer_.front();
+                               seek_target_.reset();
+                       }
+               }
+       }
+
+       void loop(bool value)
+       {
+               input_.loop(value);
+       }
+
+       bool loop() const
+       {
+               return input_.loop();
+       }
+
+       void length(uint32_t value)
+       {
+               input_.length(value);
+       }
+
+       uint32_t length()
+       {
+               return input_.length();
+       }
+       
+       void start(uint32_t value)
+       {
+               input_.start(value);
+       }
+
+       uint32_t start()
+       {
+               return input_.start();
+       }
+
+       void seek(uint32_t target)
+       {               
+               seek_target_ = std::min(target, file_nb_frames());
+
+               input_.seek(*seek_target_);
+               muxer_.clear();
+       }
+
+       std::wstring print_mode() const
+       {
+               return ffmpeg::print_mode(video_decoder_ ? video_decoder_->width() : 0, 
+                       video_decoder_ ? video_decoder_->height() : 0, 
+                       fps_, 
+                       video_decoder_ ? !video_decoder_->is_progressive() : false);
+       }
+                       
+       void decode_next_frame()
+       {
+               for(int n = 0; n < 8 && muxer_.empty(); ++n)
+               {                               
+                       if(!muxer_.video_ready())
+                               muxer_.push_video(video_decoder_ ? (*video_decoder_)() : create_frame());
+                       if(!muxer_.audio_ready())
+                               muxer_.push_audio(audio_decoder_ ? (*audio_decoder_)() : create_frame());
+               }
+               graph_->set_text(print());
+       }
+};
+
+spl::shared_ptr<core::frame_producer> create_producer(const spl::shared_ptr<core::frame_factory>& frame_factory, const core::video_format_desc& format_desc, const std::vector<std::wstring>& params)
+{              
+       auto filename = probe_stem(env::media_folder() + L"/" + params.at(0));
+
+       if(filename.empty())
+               return core::frame_producer::empty();
+       
+       bool loop               = contains_param(L"LOOP", params);
+       auto start              = get_param(L"START", params, get_param(L"SEEK", params, static_cast<uint32_t>(0)));
+       auto length             = get_param(L"LENGTH", params, std::numeric_limits<uint32_t>::max());
+       auto filter_str = get_param(L"FILTER", params, L"");    
+       
+       return create_destroy_proxy(spl::make_shared_ptr(std::make_shared<ffmpeg_producer>(frame_factory, format_desc, filename, filter_str, loop, start, length)));
+}
+
+}}