]> git.sesse.net Git - casparcg/blob - modules/ffmpeg/producer/ffmpeg_producer.cpp
Merge pull request #145 from cambell-prince/ffmpeg-dshowparams
[casparcg] / modules / ffmpeg / producer / ffmpeg_producer.cpp
1 /*\r
2 * Copyright 2013 Sveriges Television AB http://casparcg.com/\r
3 *\r
4 * This file is part of CasparCG (www.casparcg.com).\r
5 *\r
6 * CasparCG is free software: you can redistribute it and/or modify\r
7 * it under the terms of the GNU General Public License as published by\r
8 * the Free Software Foundation, either version 3 of the License, or\r
9 * (at your option) any later version.\r
10 *\r
11 * CasparCG is distributed in the hope that it will be useful,\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14 * GNU General Public License for more details.\r
15 *\r
16 * You should have received a copy of the GNU General Public License\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
18 *\r
19 * Author: Robert Nagy, ronag89@gmail.com\r
20 */\r
21 \r
22 #include "../stdafx.h"\r
23 \r
24 #include "ffmpeg_producer.h"\r
25 \r
26 #include "../ffmpeg.h"\r
27 #include "../ffmpeg_error.h"\r
28 #include "../ffmpeg_params.h"\r
29 \r
30 #include "muxer/frame_muxer.h"\r
31 #include "input/input.h"\r
32 #include "util/util.h"\r
33 #include "audio/audio_decoder.h"\r
34 #include "video/video_decoder.h"\r
35 \r
36 #include <common/env.h>\r
37 #include <common/utility/assert.h>\r
38 #include <common/diagnostics/graph.h>\r
39 \r
40 #include <core/monitor/monitor.h>\r
41 #include <core/video_format.h>\r
42 #include <core/parameters/parameters.h>\r
43 #include <core/producer/frame_producer.h>\r
44 #include <core/producer/frame/frame_factory.h>\r
45 #include <core/producer/frame/basic_frame.h>\r
46 #include <core/producer/frame/frame_transform.h>\r
47 \r
48 #include <boost/algorithm/string.hpp>\r
49 #include <boost/assign.hpp>\r
50 #include <boost/timer.hpp>\r
51 #include <boost/foreach.hpp>\r
52 #include <boost/filesystem.hpp>\r
53 #include <boost/range/algorithm/find_if.hpp>\r
54 #include <boost/range/algorithm/find.hpp>\r
55 #include <boost/regex.hpp>\r
56 \r
57 #include <tbb/parallel_invoke.h>\r
58 \r
59 #include <limits>\r
60 #include <memory>\r
61 #include <queue>\r
62 \r
63 namespace caspar { namespace ffmpeg {\r
64 \r
65 std::wstring get_relative_or_original(\r
66                 const std::wstring& filename,\r
67                 const boost::filesystem::wpath& relative_to)\r
68 {\r
69         boost::filesystem::wpath file(filename);\r
70         auto result = file.filename();\r
71 \r
72         boost::filesystem::wpath current_path = file;\r
73 \r
74         while (true)\r
75         {\r
76                 current_path = current_path.parent_path();\r
77 \r
78                 if (boost::filesystem::equivalent(current_path, relative_to))\r
79                         break;\r
80 \r
81                 if (current_path.empty())\r
82                         return filename;\r
83 \r
84                 result = current_path.filename() + L"/" + result;\r
85         }\r
86 \r
87         return result;\r
88 }\r
89                                 \r
90 struct ffmpeg_producer : public core::frame_producer\r
91 {\r
92         core::monitor::subject                                                                          monitor_subject_;\r
93         const std::wstring                                                                                      filename_;\r
94         const std::wstring                                                                                      path_relative_to_media_;\r
95 \r
96         FFMPEG_Resource                                                                                         resource_type_;\r
97         \r
98         const safe_ptr<diagnostics::graph>                                                      graph_;\r
99         boost::timer                                                                                            frame_timer_;\r
100                                         \r
101         const safe_ptr<core::frame_factory>                                                     frame_factory_;\r
102         const core::video_format_desc                                                           format_desc_;\r
103 \r
104         std::shared_ptr<void>                                                                           initial_logger_disabler_;\r
105 \r
106         input                                                                                                           input_; \r
107         std::unique_ptr<video_decoder>                                                          video_decoder_;\r
108         std::unique_ptr<audio_decoder>                                                          audio_decoder_; \r
109         std::unique_ptr<frame_muxer>                                                            muxer_;\r
110 \r
111         const double                                                                                            fps_;\r
112         const uint32_t                                                                                          start_;\r
113         const uint32_t                                                                                          length_;\r
114         const bool                                                                                                      thumbnail_mode_;\r
115 \r
116         safe_ptr<core::basic_frame>                                                                     last_frame_;\r
117         \r
118         std::queue<std::pair<safe_ptr<core::basic_frame>, size_t>>      frame_buffer_;\r
119 \r
120         int64_t                                                                                                         frame_number_;\r
121         uint32_t                                                                                                        file_frame_number_;\r
122                 \r
123 public:\r
124         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
125                 : filename_(filename)\r
126                 , path_relative_to_media_(get_relative_or_original(filename, env::media_folder()))\r
127                 , resource_type_(resource_type)\r
128                 , frame_factory_(frame_factory)         \r
129                 , format_desc_(frame_factory->get_video_format_desc())\r
130                 , initial_logger_disabler_(temporary_disable_logging_for_thread(thumbnail_mode))\r
131                 , input_(graph_, filename_, resource_type, loop, start, length, thumbnail_mode, vid_params)\r
132                 , fps_(read_fps(*input_.context(), format_desc_.fps))\r
133                 , start_(start)\r
134                 , length_(length)\r
135                 , thumbnail_mode_(thumbnail_mode)\r
136                 , last_frame_(core::basic_frame::empty())\r
137                 , frame_number_(0)\r
138         {\r
139                 graph_->set_color("frame-time", diagnostics::color(0.1f, 1.0f, 0.1f));\r
140                 graph_->set_color("underflow", diagnostics::color(0.6f, 0.3f, 0.9f));   \r
141                 diagnostics::register_graph(graph_);\r
142         \r
143                 try\r
144                 {\r
145                         video_decoder_.reset(new video_decoder(input_.context()));\r
146                         if (!thumbnail_mode_)\r
147                                 CASPAR_LOG(info) << print() << L" " << video_decoder_->print();\r
148                 }\r
149                 catch(averror_stream_not_found&)\r
150                 {\r
151                         //CASPAR_LOG(warning) << print() << " No video-stream found. Running without video.";   \r
152                 }\r
153                 catch(...)\r
154                 {\r
155                         if (!thumbnail_mode_)\r
156                         {\r
157                                 CASPAR_LOG_CURRENT_EXCEPTION();\r
158                                 CASPAR_LOG(warning) << print() << "Failed to open video-stream. Running without video.";        \r
159                         }\r
160                 }\r
161 \r
162                 core::channel_layout audio_channel_layout = core::default_channel_layout_repository().get_by_name(L"STEREO");\r
163 \r
164                 if (!thumbnail_mode_)\r
165                 {\r
166                         try\r
167                         {\r
168                                 audio_decoder_.reset(new audio_decoder(input_.context(), frame_factory->get_video_format_desc(), custom_channel_order));\r
169                                 audio_channel_layout = audio_decoder_->channel_layout();\r
170                                 CASPAR_LOG(info) << print() << L" " << audio_decoder_->print();\r
171                         }\r
172                         catch(averror_stream_not_found&)\r
173                         {\r
174                                 //CASPAR_LOG(warning) << print() << " No audio-stream found. Running without audio.";   \r
175                         }\r
176                         catch(...)\r
177                         {\r
178                                 CASPAR_LOG_CURRENT_EXCEPTION();\r
179                                 CASPAR_LOG(warning) << print() << " Failed to open audio-stream. Running without audio.";               \r
180                         }\r
181                 }\r
182 \r
183                 if(!video_decoder_ && !audio_decoder_)\r
184                         BOOST_THROW_EXCEPTION(averror_stream_not_found() << msg_info("No streams found"));\r
185 \r
186                 muxer_.reset(new frame_muxer(fps_, frame_factory, thumbnail_mode_, audio_channel_layout, filter));\r
187         }\r
188 \r
189         // frame_producer\r
190         \r
191         virtual safe_ptr<core::basic_frame> receive(int hints) override\r
192         {\r
193                 return render_frame(hints).first;\r
194         }\r
195 \r
196         virtual safe_ptr<core::basic_frame> last_frame() const override\r
197         {\r
198                 return disable_audio(last_frame_);\r
199         }\r
200 \r
201         std::pair<safe_ptr<core::basic_frame>, uint32_t> render_frame(int hints)\r
202         {               \r
203                 frame_timer_.restart();\r
204                 auto disable_logging = temporary_disable_logging_for_thread(thumbnail_mode_);\r
205                                 \r
206                 for(int n = 0; n < 16 && frame_buffer_.size() < 2; ++n)\r
207                         try_decode_frame(hints);\r
208                 \r
209                 graph_->set_value("frame-time", frame_timer_.elapsed()*format_desc_.fps*0.5);\r
210 \r
211                 if (frame_buffer_.empty())\r
212                 {\r
213                         if (input_.eof())\r
214                         {\r
215                                 send_osc();\r
216                                 return std::make_pair(last_frame(), -1);\r
217                         }\r
218                         else if (resource_type_ == FFMPEG_FILE)\r
219                         {\r
220                                 graph_->set_tag("underflow");  \r
221                                 send_osc();\r
222                                 return std::make_pair(core::basic_frame::late(), -1);     \r
223                         }\r
224                         else\r
225                         {\r
226                                 send_osc();\r
227                                 return std::make_pair(last_frame(), -1);\r
228                         }\r
229                 }\r
230                 \r
231                 auto frame = frame_buffer_.front(); \r
232                 frame_buffer_.pop();\r
233                 \r
234                 ++frame_number_;\r
235                 file_frame_number_ = frame.second;\r
236 \r
237                 graph_->set_text(print());\r
238 \r
239                 last_frame_ = frame.first;\r
240 \r
241                 send_osc();\r
242 \r
243                 return frame;\r
244         }\r
245 \r
246         void send_osc()\r
247         {\r
248                 monitor_subject_        << core::monitor::message("/profiler/time")             % frame_timer_.elapsed() % (1.0/format_desc_.fps);                      \r
249                                                                 \r
250                 monitor_subject_        << core::monitor::message("/file/time")                 % (file_frame_number()/fps_) \r
251                                                                                                                                                         % (file_nb_frames()/fps_)\r
252                                                         << core::monitor::message("/file/frame")                        % static_cast<int32_t>(file_frame_number())\r
253                                                                                                                                                         % static_cast<int32_t>(file_nb_frames())\r
254                                                         << core::monitor::message("/file/fps")                  % fps_\r
255                                                         << core::monitor::message("/file/path")                 % path_relative_to_media_\r
256                                                         << core::monitor::message("/loop")                              % input_.loop();\r
257         }\r
258         \r
259         safe_ptr<core::basic_frame> render_specific_frame(uint32_t file_position, int hints)\r
260         {\r
261                 // Some trial and error and undeterministic stuff here\r
262                 static const int NUM_RETRIES = 32;\r
263                 \r
264                 if (file_position > 0) // Assume frames are requested in sequential order,\r
265                                            // therefore no seeking should be necessary for the first frame.\r
266                 {\r
267                         input_.seek(file_position > 1 ? file_position - 2: file_position).get();\r
268                         boost::this_thread::sleep(boost::posix_time::milliseconds(40));\r
269                 }\r
270 \r
271                 for (int i = 0; i < NUM_RETRIES; ++i)\r
272                 {\r
273                         boost::this_thread::sleep(boost::posix_time::milliseconds(40));\r
274                 \r
275                         auto frame = render_frame(hints);\r
276 \r
277                         if (frame.second == std::numeric_limits<uint32_t>::max())\r
278                         {\r
279                                 // Retry\r
280                                 continue;\r
281                         }\r
282                         else if (frame.second == file_position + 1 || frame.second == file_position)\r
283                                 return frame.first;\r
284                         else if (frame.second > file_position + 1)\r
285                         {\r
286                                 CASPAR_LOG(trace) << print() << L" " << frame.second << L" received, wanted " << file_position + 1;\r
287                                 int64_t adjusted_seek = file_position - (frame.second - file_position + 1);\r
288 \r
289                                 if (adjusted_seek > 1 && file_position > 0)\r
290                                 {\r
291                                         CASPAR_LOG(trace) << print() << L" adjusting to " << adjusted_seek;\r
292                                         input_.seek(static_cast<uint32_t>(adjusted_seek) - 1).get();\r
293                                         boost::this_thread::sleep(boost::posix_time::milliseconds(40));\r
294                                 }\r
295                                 else\r
296                                         return frame.first;\r
297                         }\r
298                 }\r
299 \r
300                 CASPAR_LOG(trace) << print() << " Giving up finding frame at " << file_position;\r
301                 return core::basic_frame::empty();\r
302         }\r
303 \r
304         virtual safe_ptr<core::basic_frame> create_thumbnail_frame() override\r
305         {\r
306                 auto disable_logging = temporary_disable_logging_for_thread(thumbnail_mode_);\r
307                 auto total_frames = nb_frames();\r
308                 auto grid = env::properties().get(L"configuration.thumbnails.video-grid", 2);\r
309 \r
310                 if (grid < 1)\r
311                 {\r
312                         CASPAR_LOG(error) << L"configuration/thumbnails/video-grid cannot be less than 1";\r
313                         BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("configuration/thumbnails/video-grid cannot be less than 1"));\r
314                 }\r
315 \r
316                 if (grid == 1)\r
317                 {\r
318                         return render_specific_frame(total_frames / 2, 0/*DEINTERLACE_HINT*/);\r
319                 }\r
320 \r
321                 auto num_snapshots = grid * grid;\r
322 \r
323                 std::vector<safe_ptr<core::basic_frame>> frames;\r
324 \r
325                 for (int i = 0; i < num_snapshots; ++i)\r
326                 {\r
327                         int x = i % grid;\r
328                         int y = i / grid;\r
329                         int desired_frame;\r
330                         \r
331                         if (i == 0)\r
332                                 desired_frame = 0; // first\r
333                         else if (i == num_snapshots - 1)\r
334                                 desired_frame = total_frames - 1; // last\r
335                         else\r
336                                 // evenly distributed across the file.\r
337                                 desired_frame = total_frames * i / (num_snapshots - 1);\r
338 \r
339                         auto frame = render_specific_frame(desired_frame, 0/*DEINTERLACE_HINT*/);\r
340                         frame->get_frame_transform().fill_scale[0] = 1.0 / static_cast<double>(grid);\r
341                         frame->get_frame_transform().fill_scale[1] = 1.0 / static_cast<double>(grid);\r
342                         frame->get_frame_transform().fill_translation[0] = 1.0 / static_cast<double>(grid) * x;\r
343                         frame->get_frame_transform().fill_translation[1] = 1.0 / static_cast<double>(grid) * y;\r
344 \r
345                         frames.push_back(frame);\r
346                 }\r
347 \r
348                 return make_safe<core::basic_frame>(frames);\r
349         }\r
350         \r
351         uint32_t file_frame_number() const\r
352         {\r
353                 return video_decoder_ ? video_decoder_->file_frame_number() : 0;\r
354         }\r
355 \r
356         virtual uint32_t nb_frames() const override\r
357         {\r
358                 //if(input_.loop())\r
359                 if(resource_type_ == FFMPEG_DEVICE || resource_type_ == FFMPEG_STREAM || input_.loop()) \r
360                         return std::numeric_limits<uint32_t>::max();\r
361 \r
362                 uint32_t nb_frames = file_nb_frames();\r
363 \r
364                 nb_frames = std::min(length_, nb_frames);\r
365                 nb_frames = muxer_->calc_nb_frames(nb_frames);\r
366                 \r
367                 return nb_frames > start_ ? nb_frames - start_ : 0;\r
368         }\r
369 \r
370         uint32_t file_nb_frames() const\r
371         {\r
372                 uint32_t file_nb_frames = 0;\r
373                 file_nb_frames = std::max(file_nb_frames, video_decoder_ ? video_decoder_->nb_frames() : 0);\r
374                 file_nb_frames = std::max(file_nb_frames, audio_decoder_ ? audio_decoder_->nb_frames() : 0);\r
375                 return file_nb_frames;\r
376         }\r
377         \r
378         virtual boost::unique_future<std::wstring> call(const std::wstring& param) override\r
379         {\r
380                 boost::promise<std::wstring> promise;\r
381                 promise.set_value(do_call(param));\r
382                 return promise.get_future();\r
383         }\r
384                                 \r
385         virtual std::wstring print() const override\r
386         {\r
387                 return L"ffmpeg[" + boost::filesystem::wpath(filename_).filename() + L"|" \r
388                                                   + print_mode() + L"|" \r
389                                                   + boost::lexical_cast<std::wstring>(file_frame_number_) + L"/" + boost::lexical_cast<std::wstring>(file_nb_frames()) + L"]";\r
390         }\r
391 \r
392         boost::property_tree::wptree info() const override\r
393         {\r
394                 boost::property_tree::wptree info;\r
395                 info.add(L"type",                               L"ffmpeg-producer");\r
396                 info.add(L"filename",                   filename_);\r
397                 info.add(L"width",                              video_decoder_ ? video_decoder_->width() : 0);\r
398                 info.add(L"height",                             video_decoder_ ? video_decoder_->height() : 0);\r
399                 info.add(L"progressive",                video_decoder_ ? video_decoder_->is_progressive() : false);\r
400                 info.add(L"fps",                                fps_);\r
401                 info.add(L"loop",                               input_.loop());\r
402                 info.add(L"frame-number",               frame_number_);\r
403                 auto nb_frames2 = nb_frames();\r
404                 info.add(L"nb-frames",                  nb_frames2 == std::numeric_limits<int64_t>::max() ? -1 : nb_frames2);\r
405                 info.add(L"file-frame-number",  file_frame_number_);\r
406                 info.add(L"file-nb-frames",             file_nb_frames());\r
407                 return info;\r
408         }\r
409 \r
410         // ffmpeg_producer\r
411 \r
412         std::wstring print_mode() const\r
413         {\r
414                 return video_decoder_ ? ffmpeg::print_mode(video_decoder_->width(), video_decoder_->height(), fps_, !video_decoder_->is_progressive()) : L"";\r
415         }\r
416                                         \r
417         std::wstring do_call(const std::wstring& param)\r
418         {\r
419                 static const boost::wregex loop_exp(L"LOOP\\s*(?<VALUE>\\d?)?", boost::regex::icase);\r
420                 static const boost::wregex seek_exp(L"SEEK\\s+(?<VALUE>\\d+)", boost::regex::icase);\r
421                 \r
422                 boost::wsmatch what;\r
423                 if(boost::regex_match(param, what, loop_exp))\r
424                 {\r
425                         if(!what["VALUE"].str().empty())\r
426                                 input_.loop(boost::lexical_cast<bool>(what["VALUE"].str()));\r
427                         return boost::lexical_cast<std::wstring>(input_.loop());\r
428                 }\r
429                 if(boost::regex_match(param, what, seek_exp))\r
430                 {\r
431                         input_.seek(boost::lexical_cast<uint32_t>(what["VALUE"].str()));\r
432                         return L"";\r
433                 }\r
434 \r
435                 BOOST_THROW_EXCEPTION(invalid_argument());\r
436         }\r
437 \r
438         void try_decode_frame(int hints)\r
439         {\r
440                 std::shared_ptr<AVPacket> pkt;\r
441 \r
442                 for(int n = 0; n < 32 && ((video_decoder_ && !video_decoder_->ready()) || (audio_decoder_ && !audio_decoder_->ready())) && input_.try_pop(pkt); ++n)\r
443                 {\r
444                         if(video_decoder_)\r
445                                 video_decoder_->push(pkt);\r
446                         if(audio_decoder_)\r
447                                 audio_decoder_->push(pkt);\r
448                 }\r
449                 \r
450                 std::shared_ptr<AVFrame>                        video;\r
451                 std::shared_ptr<core::audio_buffer> audio;\r
452 \r
453                 tbb::parallel_invoke(\r
454                 [&]\r
455                 {\r
456                         if(!muxer_->video_ready() && video_decoder_)    \r
457                                 video = video_decoder_->poll(); \r
458                 },\r
459                 [&]\r
460                 {               \r
461                         if(!muxer_->audio_ready() && audio_decoder_)            \r
462                                 audio = audio_decoder_->poll();         \r
463                 });\r
464                 \r
465                 muxer_->push(video, hints);\r
466                 muxer_->push(audio);\r
467 \r
468                 if(!audio_decoder_)\r
469                 {\r
470                         if(video == flush_video())\r
471                                 muxer_->push(flush_audio());\r
472                         else if(!muxer_->audio_ready())\r
473                                 muxer_->push(empty_audio());\r
474                 }\r
475 \r
476                 if(!video_decoder_)\r
477                 {\r
478                         if(audio == flush_audio())\r
479                                 muxer_->push(flush_video(), 0);\r
480                         else if(!muxer_->video_ready())\r
481                                 muxer_->push(empty_video(), 0);\r
482                 }\r
483                 \r
484                 size_t file_frame_number = 0;\r
485                 file_frame_number = std::max(file_frame_number, video_decoder_ ? video_decoder_->file_frame_number() : 0);\r
486                 //file_frame_number = std::max(file_frame_number, audio_decoder_ ? audio_decoder_->file_frame_number() : 0);\r
487 \r
488                 for(auto frame = muxer_->poll(); frame; frame = muxer_->poll())\r
489                         frame_buffer_.push(std::make_pair(make_safe_ptr(frame), file_frame_number));\r
490         }\r
491 \r
492         core::monitor::source& monitor_output()\r
493         {\r
494                 return monitor_subject_;\r
495         }\r
496 };\r
497 \r
498 safe_ptr<core::frame_producer> create_producer(\r
499                 const safe_ptr<core::frame_factory>& frame_factory,\r
500                 const core::parameters& params)\r
501 {               \r
502         static const std::vector<std::wstring> invalid_exts = boost::assign::list_of(L".png")(L".tga")(L".bmp")(L".jpg")(L".jpeg")(L".gif")(L".tiff")(L".tif")(L".jp2")(L".jpx")(L".j2k")(L".j2c")(L".swf")(L".ct");\r
503 \r
504         // Infer the resource type from the resource_name\r
505         auto resource_type = FFMPEG_FILE;\r
506         auto tokens = core::parameters::protocol_split(params.at_original(0));\r
507         auto filename = params.at_original(0);\r
508         if (!tokens[0].empty())\r
509         {\r
510                 if (tokens[0] == L"dshow")\r
511                 {\r
512                         // Camera\r
513                         resource_type = FFMPEG_DEVICE;\r
514                         filename = tokens[1];\r
515                 } else\r
516                 {\r
517                         // Stream\r
518                         resource_type = FFMPEG_STREAM;\r
519                         filename = params.at_original(0);\r
520                 }\r
521         } else\r
522         {\r
523                 // File\r
524                 resource_type = FFMPEG_FILE;\r
525                 filename = env::media_folder() + L"\\" + tokens[1];\r
526                 if(!boost::filesystem::exists(filename))\r
527                         filename = probe_stem(filename);\r
528 \r
529                 //TODO fix these?\r
530                 //vid_params->loop       = params.has(L"LOOP");\r
531                 //vid_params->start     = params.get(L"SEEK", static_cast<uint32_t>(0));\r
532         }\r
533 \r
534         if(filename.empty())\r
535                 return core::frame_producer::empty();\r
536         \r
537         auto loop               = params.has(L"LOOP");\r
538         auto start              = params.get(L"SEEK", static_cast<uint32_t>(0));\r
539         auto length             = params.get(L"LENGTH", std::numeric_limits<uint32_t>::max());\r
540         auto filter_str = params.get(L"FILTER", L"");   \r
541         auto custom_channel_order       = params.get(L"CHANNEL_LAYOUT", L"");\r
542 \r
543         boost::replace_all(filter_str, L"DEINTERLACE", L"YADIF=0:-1");\r
544         boost::replace_all(filter_str, L"DEINTERLACE_BOB", L"YADIF=1:-1");\r
545         \r
546         ffmpeg_producer_params vid_params;\r
547         bool haveFFMPEGStartIndicator = false;\r
548         for (size_t i = 0; i < params.size() - 1; ++i)\r
549         {\r
550                 if (!haveFFMPEGStartIndicator && params[i] == L"--")\r
551                 {\r
552                         haveFFMPEGStartIndicator = true;\r
553                         continue;\r
554                 }\r
555                 if (haveFFMPEGStartIndicator)\r
556                 {\r
557                         auto name = narrow(params.at_original(i++)).substr(1);\r
558                         auto value = narrow(params.at_original(i));\r
559                         vid_params.options.push_back(option(name, value));\r
560                 }\r
561         }\r
562 \r
563         \r
564         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
565 }\r
566 \r
567 safe_ptr<core::frame_producer> create_thumbnail_producer(\r
568                 const safe_ptr<core::frame_factory>& frame_factory,\r
569                 const core::parameters& params)\r
570 {               \r
571         static const std::vector<std::wstring> invalid_exts = boost::assign::list_of\r
572                         (L".png")(L".tga")(L".bmp")(L".jpg")(L".jpeg")(L".gif")(L".tiff")(L".tif")(L".jp2")(L".jpx")(L".j2k")(L".j2c")(L".swf")(L".ct")\r
573                         (L".wav")(L".mp3"); // audio shall not have thumbnails\r
574         auto filename = probe_stem(env::media_folder() + L"\\" + params.at_original(0), invalid_exts);\r
575 \r
576         if(filename.empty())\r
577                 return core::frame_producer::empty();\r
578         \r
579         auto loop               = false;\r
580         auto start              = 0;\r
581         auto length             = std::numeric_limits<uint32_t>::max();\r
582         auto filter_str = L"";\r
583 \r
584         ffmpeg_producer_params vid_params;\r
585         return make_safe<ffmpeg_producer>(frame_factory, filename, FFMPEG_FILE, filter_str, loop, start, length, true, L"", vid_params);\r
586 }\r
587 \r
588 }}