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