]> git.sesse.net Git - casparcg/blob - modules/ffmpeg/consumer/ffmpeg_consumer.cpp
### Mayor refactoring. Simplified frame handling and image_mixer. Separated video...
[casparcg] / modules / ffmpeg / consumer / ffmpeg_consumer.cpp
1 /*\r
2 * Copyright (c) 2011 Sveriges Television AB <info@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_error.h"\r
25 \r
26 #include "ffmpeg_consumer.h"\r
27 \r
28 #include <core/frame/frame.h>\r
29 #include <core/mixer/audio/audio_util.h>\r
30 #include <core/consumer/frame_consumer.h>\r
31 #include <core/video_format.h>\r
32 \r
33 #include <common/env.h>\r
34 #include <common/concurrency/executor.h>\r
35 #include <common/diagnostics/graph.h>\r
36 #include <common/spl/memory.h>\r
37 #include <common/utf.h>\r
38 #include <common/param.h>\r
39 \r
40 #include <boost/algorithm/string.hpp>\r
41 #include <boost/timer.hpp>\r
42 #include <boost/property_tree/ptree.hpp>\r
43 #include <boost/filesystem.hpp>\r
44 \r
45 #if defined(_MSC_VER)\r
46 #pragma warning (push)\r
47 #pragma warning (disable : 4244)\r
48 #endif\r
49 extern "C" \r
50 {\r
51         #define __STDC_CONSTANT_MACROS\r
52         #define __STDC_LIMIT_MACROS\r
53         #include <libavformat/avformat.h>\r
54         #include <libswscale/swscale.h>\r
55         #include <libavutil/opt.h>\r
56 }\r
57 #if defined(_MSC_VER)\r
58 #pragma warning (pop)\r
59 #endif\r
60 \r
61 namespace caspar { namespace ffmpeg {\r
62         \r
63 struct option\r
64 {\r
65         std::string name;\r
66         std::string value;\r
67 \r
68         option(std::string name, std::string value)\r
69                 : name(std::move(name))\r
70                 , value(std::move(value))\r
71         {\r
72         }\r
73 };\r
74         \r
75 void set_format(AVOutputFormat*& format, const std::string& value)\r
76 {\r
77         format = av_guess_format(value.c_str(), nullptr, nullptr);\r
78 \r
79         if(format == nullptr)\r
80                 BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("f"));        \r
81 }\r
82 \r
83 bool parse_format(AVOutputFormat*& format, std::vector<option>& options)\r
84 {       \r
85         auto format_it = std::find_if(options.begin(), options.end(), [](const option& o)\r
86         {\r
87                 return o.name == "f" || o.name == "format";\r
88         });\r
89 \r
90         if(format_it == options.end())\r
91                 return false;\r
92 \r
93         set_format(format, format_it->value);\r
94 \r
95         options.erase(format_it);\r
96 \r
97         return true;\r
98 }\r
99 \r
100 void set_vcodec(CodecID& vcodec, const std::string& value)\r
101 {       \r
102         vcodec = avcodec_find_encoder_by_name(value.c_str())->id;\r
103         if(vcodec == CODEC_ID_NONE)\r
104                 BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("vcodec"));\r
105 }\r
106 \r
107 bool parse_vcodec(CodecID& vcodec, std::vector<option>& options)\r
108 {\r
109         auto vcodec_it = std::find_if(options.begin(), options.end(), [](const option& o)\r
110         {\r
111                 return o.name == "vcodec";\r
112         });\r
113 \r
114         if(vcodec_it == options.end())\r
115                 return false;\r
116         \r
117         set_vcodec(vcodec, vcodec_it->value);\r
118 \r
119         options.erase(vcodec_it);\r
120 \r
121         return true;\r
122 }\r
123 \r
124 void set_pix_fmt(AVCodecContext* vcodec, const std::string& value)\r
125 {\r
126         auto pix_fmt = av_get_pix_fmt(value.c_str());\r
127         if(pix_fmt == PIX_FMT_NONE)\r
128                 BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("pix_fmt"));\r
129 \r
130         vcodec->pix_fmt = pix_fmt;\r
131 }\r
132 \r
133 bool parse_pix_fmt(AVCodecContext* vcodec, std::vector<option>& options)\r
134 {\r
135         auto pix_fmt_it = std::find_if(options.begin(), options.end(), [](const option& o)\r
136         {\r
137                 return o.name == "pix_fmt" || o.name == "pixel_format";\r
138         });\r
139         \r
140         if(pix_fmt_it == options.end())\r
141                 return false;\r
142 \r
143         set_pix_fmt(vcodec, pix_fmt_it->value);\r
144         \r
145         options.erase(pix_fmt_it);\r
146 \r
147         return true;\r
148 }\r
149 \r
150 struct ffmpeg_consumer : boost::noncopyable\r
151 {               \r
152         const std::string                                               filename_;\r
153                 \r
154         const std::shared_ptr<AVFormatContext>  oc_;\r
155         const core::video_format_desc                   format_desc_;\r
156         \r
157         const spl::shared_ptr<diagnostics::graph>               graph_;\r
158         boost::timer                                                    frame_timer_;\r
159         boost::timer                                                    write_timer_;\r
160 \r
161         executor                                                                executor_;\r
162         executor                                                                file_write_executor_;\r
163 \r
164         // Audio\r
165         std::shared_ptr<AVStream>                               audio_st_;\r
166         \r
167         // Video\r
168         std::shared_ptr<AVStream>                               video_st_;\r
169 \r
170         std::vector<uint8_t>                                    video_outbuf_;\r
171         std::vector<uint8_t>                                    picture_buf_;\r
172         std::shared_ptr<SwsContext>                             sws_;\r
173 \r
174         int64_t                                                                 frame_number_;\r
175         \r
176 public:\r
177         ffmpeg_consumer(const std::string& filename, const core::video_format_desc& format_desc, std::vector<option> options)\r
178                 : filename_(filename)\r
179                 , video_outbuf_(1920*1080*8)\r
180                 , oc_(avformat_alloc_context(), av_free)\r
181                 , format_desc_(format_desc)\r
182                 , executor_(print())\r
183                 , file_write_executor_(print() + L"/output")\r
184                 , frame_number_(0)\r
185         {\r
186                 // TODO: Ask stakeholders about case where file already exists.\r
187                 boost::filesystem::remove(boost::filesystem::path(env::media_folder() + u16(filename))); // Delete the file if it exists\r
188 \r
189                 graph_->set_color("frame-time", diagnostics::color(0.1f, 1.0f, 0.1f));\r
190                 graph_->set_color("write-time", diagnostics::color(0.5f, 0.5f, 0.1f));\r
191                 graph_->set_text(print());\r
192                 diagnostics::register_graph(graph_);\r
193 \r
194                 executor_.set_capacity(8);\r
195                 file_write_executor_.set_capacity(8);\r
196 \r
197                 oc_->oformat = av_guess_format(nullptr, filename_.c_str(), nullptr);\r
198                 if (!oc_->oformat)\r
199                         BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Could not find suitable output format."));\r
200                 \r
201                 parse_format(oc_->oformat, options);\r
202 \r
203                 auto vcodec = oc_->oformat->video_codec;\r
204                 parse_vcodec(vcodec, options);\r
205                 \r
206                 THROW_ON_ERROR2(av_set_parameters(oc_.get(), nullptr), "[ffmpeg_consumer]");\r
207 \r
208                 strcpy_s(oc_->filename, filename_.c_str());\r
209                 \r
210                 //  Add the audio and video streams using the default format codecs     and initialize the codecs .\r
211                 video_st_ = add_video_stream(vcodec, options);\r
212                 audio_st_ = add_audio_stream();\r
213                                 \r
214                 dump_format(oc_.get(), 0, filename_.c_str(), 1);\r
215                  \r
216                 // Open the output ffmpeg, if needed.\r
217                 if (!(oc_->oformat->flags & AVFMT_NOFILE)) \r
218                         THROW_ON_ERROR2(avio_open(&oc_->pb, filename_.c_str(), URL_WRONLY), "[ffmpeg_consumer]");\r
219                                 \r
220                 THROW_ON_ERROR2(av_write_header(oc_.get()), "[ffmpeg_consumer]");\r
221 \r
222                 CASPAR_LOG(info) << print() << L" Successfully Initialized.";   \r
223         }\r
224 \r
225         ~ffmpeg_consumer()\r
226         {    \r
227                 executor_.wait();\r
228                 file_write_executor_.wait();\r
229                 \r
230                 LOG_ON_ERROR2(av_write_trailer(oc_.get()), "[ffmpeg_consumer]");\r
231                 \r
232                 audio_st_.reset();\r
233                 video_st_.reset();\r
234                           \r
235                 if (!(oc_->oformat->flags & AVFMT_NOFILE)) \r
236                         LOG_ON_ERROR2(avio_close(oc_->pb), "[ffmpeg_consumer]"); // Close the output ffmpeg.\r
237 \r
238                 CASPAR_LOG(info) << print() << L" Successfully Uninitialized."; \r
239         }\r
240                         \r
241         std::wstring print() const\r
242         {\r
243                 return L"ffmpeg[" + u16(filename_) + L"]";\r
244         }\r
245 \r
246         std::shared_ptr<AVStream> add_video_stream(CodecID vcodec, std::vector<option>& options)\r
247         { \r
248                 auto st = av_new_stream(oc_.get(), 0);\r
249                 if (!st)                \r
250                         BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Could not allocate video-stream") << boost::errinfo_api_function("av_new_stream"));               \r
251 \r
252                 auto encoder = avcodec_find_encoder(vcodec);\r
253                 if (!encoder)\r
254                         BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("codec not found"));\r
255 \r
256                 auto c = st->codec;\r
257 \r
258                 avcodec_get_context_defaults3(c, encoder);\r
259                                 \r
260                 c->codec_id                     = vcodec;\r
261                 c->codec_type           = AVMEDIA_TYPE_VIDEO;\r
262                 c->width                        = format_desc_.width;\r
263                 c->height                       = format_desc_.height;\r
264                 c->time_base.den        = format_desc_.time_scale;\r
265                 c->time_base.num        = format_desc_.duration;\r
266                 c->gop_size                     = 25;\r
267                 c->flags                   |= format_desc_.field_mode == core::field_mode::progressive ? 0 : (CODEC_FLAG_INTERLACED_ME | CODEC_FLAG_INTERLACED_DCT);\r
268 \r
269                 if(c->codec_id == CODEC_ID_PRORES)\r
270                 {                       \r
271                         c->bit_rate     = format_desc_.width < 1280 ? 63*1000000 : 220*1000000;\r
272                         c->pix_fmt      = PIX_FMT_YUV422P10;\r
273                 }\r
274                 else if(c->codec_id == CODEC_ID_DNXHD)\r
275                 {\r
276                         if(format_desc_.width < 1280 || format_desc_.height < 720)\r
277                                 BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("unsupported dimension"));\r
278 \r
279                         c->bit_rate     = 220*1000000;\r
280                         c->pix_fmt      = PIX_FMT_YUV422P;\r
281                 }\r
282                 else if(c->codec_id == CODEC_ID_DVVIDEO)\r
283                 {\r
284                         c->bit_rate     = format_desc_.width < 1280 ? 50*1000000 : 100*1000000;\r
285                         c->width = format_desc_.height == 1280 ? 960  : c->width;\r
286                         \r
287                         if(format_desc_.format == core::video_format::ntsc)\r
288                                 c->pix_fmt = PIX_FMT_YUV411P;\r
289                         else if(format_desc_.format == core::video_format::pal)\r
290                                 c->pix_fmt = PIX_FMT_YUV420P;\r
291                         \r
292                         if(c->bit_rate >= 50*1000000) // dv50\r
293                                 c->pix_fmt = PIX_FMT_YUV422P;\r
294                         \r
295                         if(format_desc_.duration == 1001)                       \r
296                                 c->width = format_desc_.height == 1080 ? 1280 : c->width;                       \r
297                         else\r
298                                 c->width = format_desc_.height == 1080 ? 1440 : c->width;                       \r
299                 }\r
300                 else if(c->codec_id == CODEC_ID_H264)\r
301                 {                          \r
302                         c->pix_fmt = PIX_FMT_YUV420P;    \r
303                         if(options.empty())\r
304                         {\r
305                                 av_opt_set(c->priv_data, "preset", "ultrafast", 0);\r
306                                 av_opt_set(c->priv_data, "tune",   "fastdecode",   0);\r
307                                 av_opt_set(c->priv_data, "crf",    "5",     0);\r
308                         }\r
309                 }\r
310                 else if(c->codec_id == CODEC_ID_QTRLE)\r
311                 {\r
312                         c->pix_fmt = PIX_FMT_ARGB;\r
313                 }\r
314                 else\r
315                 {\r
316                         BOOST_THROW_EXCEPTION(invalid_argument() << msg_info("Unsupported output parameters."));\r
317                 }\r
318 \r
319                 parse_pix_fmt(c, options);\r
320                 \r
321                 c->max_b_frames = 0; // b-frames not supported.\r
322 \r
323                 BOOST_FOREACH(auto& option, options)\r
324                         THROW_ON_ERROR2(av_opt_set(c, option.name.c_str(), option.value.c_str(), AV_OPT_SEARCH_CHILDREN), "[ffmpeg_consumer]");\r
325                                 \r
326                 if(oc_->oformat->flags & AVFMT_GLOBALHEADER)\r
327                         c->flags |= CODEC_FLAG_GLOBAL_HEADER;\r
328                 \r
329                 c->thread_count = boost::thread::hardware_concurrency();\r
330                 THROW_ON_ERROR2(avcodec_open(c, encoder), "[ffmpeg_consumer]");\r
331 \r
332                 return std::shared_ptr<AVStream>(st, [](AVStream* st)\r
333                 {\r
334                         LOG_ON_ERROR2(avcodec_close(st->codec), "[ffmpeg_consumer]");\r
335                         av_freep(&st->codec);\r
336                         av_freep(&st);\r
337                 });\r
338         }\r
339         \r
340         std::shared_ptr<AVStream> add_audio_stream()\r
341         {\r
342                 auto st = av_new_stream(oc_.get(), 1);\r
343                 if(!st)\r
344                         BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Could not allocate audio-stream") << boost::errinfo_api_function("av_new_stream"));               \r
345 \r
346                 st->codec->codec_id                     = CODEC_ID_PCM_S16LE;\r
347                 st->codec->codec_type           = AVMEDIA_TYPE_AUDIO;\r
348                 st->codec->sample_rate          = 48000;\r
349                 st->codec->channels                     = 2;\r
350                 st->codec->sample_fmt           = SAMPLE_FMT_S16;\r
351                 \r
352                 if(oc_->oformat->flags & AVFMT_GLOBALHEADER)\r
353                         st->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;\r
354                 \r
355                 auto codec = avcodec_find_encoder(st->codec->codec_id);\r
356                 if (!codec)\r
357                         BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("codec not found"));\r
358 \r
359                 THROW_ON_ERROR2(avcodec_open(st->codec, codec), "[ffmpeg_consumer]");\r
360 \r
361                 return std::shared_ptr<AVStream>(st, [](AVStream* st)\r
362                 {\r
363                         LOG_ON_ERROR2(avcodec_close(st->codec), "[ffmpeg_consumer]");;\r
364                         av_freep(&st->codec);\r
365                         av_freep(&st);\r
366                 });\r
367         }\r
368 \r
369         std::shared_ptr<AVFrame> convert_video_frame(core::const_frame frame, AVCodecContext* c)\r
370         {\r
371                 if(!sws_) \r
372                 {\r
373                         sws_.reset(sws_getContext(static_cast<int>(format_desc_.width), static_cast<int>(format_desc_.height), PIX_FMT_BGRA, c->width, c->height, c->pix_fmt, SWS_BICUBIC, nullptr, nullptr, nullptr), sws_freeContext);\r
374                         if (sws_ == nullptr) \r
375                                 BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Cannot initialize the conversion context"));\r
376                 }\r
377 \r
378                 std::shared_ptr<AVFrame> av_frame(avcodec_alloc_frame(), av_free);\r
379                 avpicture_fill(reinterpret_cast<AVPicture*>(av_frame.get()), const_cast<uint8_t*>(frame.image_data().begin()), PIX_FMT_BGRA, static_cast<int>(format_desc_.width), static_cast<int>(format_desc_.height));\r
380                                 \r
381                 std::shared_ptr<AVFrame> local_av_frame(avcodec_alloc_frame(), av_free);\r
382                 picture_buf_.resize(avpicture_get_size(c->pix_fmt, static_cast<int>(format_desc_.width), static_cast<int>(format_desc_.height)));\r
383                 avpicture_fill(reinterpret_cast<AVPicture*>(local_av_frame.get()), picture_buf_.data(), c->pix_fmt, static_cast<int>(format_desc_.width), static_cast<int>(format_desc_.height));\r
384 \r
385                 sws_scale(sws_.get(), av_frame->data, av_frame->linesize, 0, c->height, local_av_frame->data, local_av_frame->linesize);\r
386 \r
387                 return local_av_frame;\r
388         }\r
389   \r
390         std::shared_ptr<AVPacket> encode_video_frame(core::const_frame frame)\r
391         { \r
392                 auto c = video_st_->codec;\r
393  \r
394                 auto av_frame = convert_video_frame(frame, c);\r
395                 av_frame->interlaced_frame      = format_desc_.field_mode != core::field_mode::progressive;\r
396                 av_frame->top_field_first       = format_desc_.field_mode == core::field_mode::upper;\r
397                 av_frame->pts                           = frame_number_++;\r
398 \r
399                 int out_size = THROW_ON_ERROR2(avcodec_encode_video(c, video_outbuf_.data(), static_cast<int>(video_outbuf_.size()), av_frame.get()), "[ffmpeg_consumer]");\r
400                 if(out_size > 0)\r
401                 {\r
402                         spl::shared_ptr<AVPacket> pkt(new AVPacket, [](AVPacket* p)\r
403                         {\r
404                                 av_free_packet(p);\r
405                                 delete p;\r
406                         });\r
407                         av_init_packet(pkt.get());\r
408  \r
409                         if (c->coded_frame->pts != AV_NOPTS_VALUE)\r
410                                 pkt->pts = av_rescale_q(c->coded_frame->pts, c->time_base, video_st_->time_base);\r
411 \r
412                         if(c->coded_frame->key_frame)\r
413                                 pkt->flags |= AV_PKT_FLAG_KEY;\r
414 \r
415                         pkt->stream_index       = video_st_->index;\r
416                         pkt->data                       = video_outbuf_.data();\r
417                         pkt->size                       = out_size;\r
418  \r
419                         av_dup_packet(pkt.get());\r
420                         return pkt;\r
421                 }       \r
422                 return nullptr;\r
423         }\r
424                 \r
425         std::shared_ptr<AVPacket> encode_audio_frame(core::const_frame frame)\r
426         {                       \r
427                 auto c = audio_st_->codec;\r
428 \r
429                 auto audio_data = core::audio_32_to_16(frame.audio_data());\r
430                 \r
431                 spl::shared_ptr<AVPacket> pkt(new AVPacket, [](AVPacket* p)\r
432                 {\r
433                         av_free_packet(p);\r
434                         delete p;\r
435                 });\r
436                 av_init_packet(pkt.get());\r
437                 \r
438                 if (c->coded_frame && c->coded_frame->pts != AV_NOPTS_VALUE)\r
439                         pkt->pts = av_rescale_q(c->coded_frame->pts, c->time_base, audio_st_->time_base);\r
440 \r
441                 pkt->flags                      |= AV_PKT_FLAG_KEY;\r
442                 pkt->stream_index       = audio_st_->index;\r
443                 pkt->size                       = static_cast<int>(audio_data.size()*2);\r
444                 pkt->data                       = reinterpret_cast<uint8_t*>(audio_data.data());\r
445                 \r
446                 av_dup_packet(pkt.get());\r
447                 return pkt;\r
448         }\r
449                  \r
450         void send(core::const_frame& frame)\r
451         {\r
452                 executor_.begin_invoke([=]\r
453                 {               \r
454                         frame_timer_.restart();\r
455 \r
456                         auto video = encode_video_frame(frame);\r
457                         auto audio = encode_audio_frame(frame);\r
458 \r
459                         graph_->set_value("frame-time", frame_timer_.elapsed()*format_desc_.fps*0.5);\r
460                         \r
461                         file_write_executor_.begin_invoke([=]\r
462                         {\r
463                                 write_timer_.restart();\r
464 \r
465                                 if(video)\r
466                                         av_write_frame(oc_.get(), video.get());\r
467                                 if(audio)\r
468                                         av_write_frame(oc_.get(), audio.get());\r
469 \r
470                                 graph_->set_value("write-time", write_timer_.elapsed()*format_desc_.fps*0.5);\r
471                         });\r
472                 });\r
473         }\r
474 };\r
475 \r
476 struct ffmpeg_consumer_proxy : public core::frame_consumer\r
477 {\r
478         const std::wstring                              filename_;\r
479         const std::vector<option>               options_;\r
480 \r
481         std::unique_ptr<ffmpeg_consumer> consumer_;\r
482 \r
483 public:\r
484 \r
485         ffmpeg_consumer_proxy(const std::wstring& filename, const std::vector<option>& options)\r
486                 : filename_(filename)\r
487                 , options_(options)\r
488         {\r
489         }\r
490         \r
491         virtual void initialize(const core::video_format_desc& format_desc, int)\r
492         {\r
493                 consumer_.reset();\r
494                 consumer_.reset(new ffmpeg_consumer(u8(filename_), format_desc, options_));\r
495         }\r
496         \r
497         virtual bool send(core::const_frame frame) override\r
498         {\r
499                 consumer_->send(frame);\r
500                 return true;\r
501         }\r
502         \r
503         virtual std::wstring print() const override\r
504         {\r
505                 return consumer_ ? consumer_->print() : L"[ffmpeg_consumer]";\r
506         }\r
507 \r
508         virtual std::wstring name() const override\r
509         {\r
510                 return L"file";\r
511         }\r
512 \r
513         virtual boost::property_tree::wptree info() const override\r
514         {\r
515                 boost::property_tree::wptree info;\r
516                 info.add(L"type", L"file");\r
517                 info.add(L"filename", filename_);\r
518                 return info;\r
519         }\r
520                 \r
521         virtual bool has_synchronization_clock() const override\r
522         {\r
523                 return false;\r
524         }\r
525 \r
526         virtual int buffer_depth() const override\r
527         {\r
528                 return 1;\r
529         }\r
530 \r
531         virtual int index() const override\r
532         {\r
533                 return 200;\r
534         }\r
535 };      \r
536 \r
537 spl::shared_ptr<core::frame_consumer> create_consumer(const std::vector<std::wstring>& params)\r
538 {\r
539         if(params.size() < 1 || params[0] != L"FILE")\r
540                 return core::frame_consumer::empty();\r
541         \r
542         auto filename   = (params.size() > 1 ? params[1] : L"");\r
543                         \r
544         std::vector<option> options;\r
545         \r
546         if(params.size() >= 3)\r
547         {\r
548                 for(auto opt_it = params.begin()+2; opt_it != params.end();)\r
549                 {\r
550                         auto name  = u8(boost::trim_copy(boost::to_lower_copy(*opt_it++))).substr(1);\r
551                         auto value = u8(boost::trim_copy(boost::to_lower_copy(*opt_it++)));\r
552                                 \r
553                         if(value == "h264")\r
554                                 value = "libx264";\r
555                         else if(value == "dvcpro")\r
556                                 value = "dvvideo";\r
557 \r
558                         options.push_back(option(name, value));\r
559                 }\r
560         }\r
561                 \r
562         return spl::make_shared<ffmpeg_consumer_proxy>(env::media_folder() + filename, options);\r
563 }\r
564 \r
565 spl::shared_ptr<core::frame_consumer> create_consumer(const boost::property_tree::wptree& ptree)\r
566 {\r
567         auto filename   = ptree.get<std::wstring>(L"path");\r
568         auto codec              = ptree.get(L"vcodec", L"libx264");\r
569 \r
570         std::vector<option> options;\r
571         options.push_back(option("vcodec", u8(codec)));\r
572         \r
573         return spl::make_shared<ffmpeg_consumer_proxy>(env::media_folder() + filename, options);\r
574 }\r
575 \r
576 }}\r