2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG (www.casparcg.com).
\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
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
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
19 * Author: Robert Nagy, ronag89@gmail.com
\r
22 #include "../StdAfx.h"
\r
24 #include "../ffmpeg_error.h"
\r
26 #include "ffmpeg_consumer.h"
\r
28 #include "../producer/tbb_avcodec.h"
\r
30 #include <core/frame/frame.h>
\r
31 #include <core/mixer/audio/audio_util.h>
\r
32 #include <core/consumer/frame_consumer.h>
\r
33 #include <core/video_format.h>
\r
35 #include <common/array.h>
\r
36 #include <common/env.h>
\r
37 #include <common/except.h>
\r
38 #include <common/executor.h>
\r
39 #include <common/diagnostics/graph.h>
\r
40 #include <common/lock.h>
\r
41 #include <common/memory.h>
\r
42 #include <common/param.h>
\r
43 #include <common/utf.h>
\r
45 #include <boost/algorithm/string.hpp>
\r
46 #include <boost/timer.hpp>
\r
47 #include <boost/property_tree/ptree.hpp>
\r
48 #include <boost/filesystem.hpp>
\r
49 #include <boost/range/algorithm.hpp>
\r
50 #include <boost/range/algorithm_ext.hpp>
\r
51 #include <boost/lexical_cast.hpp>
\r
53 #include <tbb/spin_mutex.h>
\r
55 #if defined(_MSC_VER)
\r
56 #pragma warning (push)
\r
57 #pragma warning (disable : 4244)
\r
61 #define __STDC_CONSTANT_MACROS
\r
62 #define __STDC_LIMIT_MACROS
\r
63 #include <libavformat/avformat.h>
\r
64 #include <libswscale/swscale.h>
\r
65 #include <libavutil/opt.h>
\r
66 #include <libavutil/pixdesc.h>
\r
67 #include <libavutil/parseutils.h>
\r
68 #include <libavutil/samplefmt.h>
\r
69 #include <libswresample/swresample.h>
\r
71 #if defined(_MSC_VER)
\r
72 #pragma warning (pop)
\r
75 namespace caspar { namespace ffmpeg {
\r
77 int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
\r
79 AVClass* av_class = *(AVClass**)obj;
\r
81 if((strcmp(name, "pix_fmt") == 0 || strcmp(name, "pixel_format") == 0) && strcmp(av_class->class_name, "AVCodecContext") == 0)
\r
83 AVCodecContext* c = (AVCodecContext*)obj;
\r
84 auto pix_fmt = av_get_pix_fmt(val);
\r
85 if(pix_fmt == PIX_FMT_NONE)
\r
87 c->pix_fmt = pix_fmt;
\r
90 //if((strcmp(name, "r") == 0 || strcmp(name, "frame_rate") == 0) && strcmp(av_class->class_name, "AVCodecContext") == 0)
\r
92 // AVCodecContext* c = (AVCodecContext*)obj;
\r
94 // if(c->codec_type != AVMEDIA_TYPE_VIDEO)
\r
98 // int ret = av_parse_video_rate(&rate, val);
\r
102 // c->time_base.num = rate.den;
\r
103 // c->time_base.den = rate.num;
\r
107 return ::av_opt_set(obj, name, val, search_flags);
\r
115 option(std::string name, std::string value)
\r
116 : name(std::move(name))
\r
117 , value(std::move(value))
\r
122 struct output_format
\r
124 AVOutputFormat* format;
\r
132 output_format(const core::video_format_desc& format_desc, const std::string& filename, std::vector<option>& options)
\r
133 : format(av_guess_format(nullptr, filename.c_str(), nullptr))
\r
134 , width(format_desc.width)
\r
135 , height(format_desc.height)
\r
136 , vcodec(CODEC_ID_NONE)
\r
137 , acodec(CODEC_ID_NONE)
\r
141 boost::range::remove_erase_if(options, [&](const option& o)
\r
143 return set_opt(o.name, o.value);
\r
146 if(vcodec == CODEC_ID_NONE)
\r
147 vcodec = format->video_codec;
\r
149 if(acodec == CODEC_ID_NONE)
\r
150 acodec = format->audio_codec;
\r
152 if(vcodec == CODEC_ID_NONE)
\r
153 vcodec = CODEC_ID_H264;
\r
155 if(acodec == CODEC_ID_NONE)
\r
156 acodec = CODEC_ID_PCM_S16LE;
\r
159 bool set_opt(const std::string& name, const std::string& value)
\r
161 //if(name == "target")
\r
163 // enum { PAL, NTSC, FILM, UNKNOWN } norm = UNKNOWN;
\r
165 // if(name.find("pal-") != std::string::npos)
\r
167 // else if(name.find("ntsc-") != std::string::npos)
\r
170 // if(norm == UNKNOWN)
\r
171 // CASPAR_THROW_EXCEPTION(invalid_argument() << arg_name_info("target"));
\r
173 // if (name.find("-dv") != std::string::npos)
\r
175 // set_opt("f", "dv");
\r
176 // set_opt("s", norm == PAL ? "720x576" : "720x480");
\r
177 // //set_opt("pix_fmt", name.find("-dv50") != std::string::npos ? "yuv422p" : norm == PAL ? "yuv420p" : "yuv411p");
\r
178 // //set_opt("ar", "48000");
\r
179 // //set_opt("ac", "2");
\r
184 format = av_guess_format(value.c_str(), nullptr, nullptr);
\r
186 if(format == nullptr)
\r
187 CASPAR_THROW_EXCEPTION(invalid_argument() << arg_name_info("f"));
\r
191 else if(name == "vcodec")
\r
193 auto c = avcodec_find_encoder_by_name(value.c_str());
\r
195 CASPAR_THROW_EXCEPTION(invalid_argument() << arg_name_info("vcodec"));
\r
197 vcodec = avcodec_find_encoder_by_name(value.c_str())->id;
\r
201 else if(name == "acodec")
\r
203 auto c = avcodec_find_encoder_by_name(value.c_str());
\r
205 CASPAR_THROW_EXCEPTION(invalid_argument() << arg_name_info("acodec"));
\r
207 acodec = avcodec_find_encoder_by_name(value.c_str())->id;
\r
211 else if(name == "s")
\r
213 if(av_parse_video_size(&width, &height, value.c_str()) < 0)
\r
214 CASPAR_THROW_EXCEPTION(invalid_argument() << arg_name_info("s"));
\r
218 else if(name == "croptop")
\r
220 croptop = boost::lexical_cast<int>(value);
\r
224 else if(name == "cropbot")
\r
226 cropbot = boost::lexical_cast<int>(value);
\r
235 typedef std::vector<uint8_t, tbb::cache_aligned_allocator<uint8_t>> byte_vector;
\r
237 struct ffmpeg_consumer : boost::noncopyable
\r
239 const std::string filename_;
\r
241 const std::shared_ptr<AVFormatContext> oc_;
\r
242 const core::video_format_desc format_desc_;
\r
244 const spl::shared_ptr<diagnostics::graph> graph_;
\r
246 tbb::spin_mutex exception_mutex_;
\r
247 std::exception_ptr exception_;
\r
249 std::shared_ptr<AVStream> audio_st_;
\r
250 std::shared_ptr<AVStream> video_st_;
\r
252 byte_vector picture_buffer_;
\r
253 byte_vector audio_buffer_;
\r
254 std::shared_ptr<SwrContext> swr_;
\r
255 std::shared_ptr<SwsContext> sws_;
\r
257 int64_t frame_number_;
\r
259 output_format output_format_;
\r
261 executor executor_;
\r
263 ffmpeg_consumer(const std::string& filename, const core::video_format_desc& format_desc, std::vector<option> options)
\r
264 : filename_(filename)
\r
265 , oc_(avformat_alloc_context(), av_free)
\r
266 , format_desc_(format_desc)
\r
268 , output_format_(format_desc, filename, options)
\r
269 , executor_(print())
\r
273 // TODO: Ask stakeholders about case where file already exists.
\r
274 boost::filesystem::remove(boost::filesystem::path(env::media_folder() + u16(filename))); // Delete the file if it exists
\r
276 graph_->set_color("frame-time", diagnostics::color(0.1f, 1.0f, 0.1f));
\r
277 graph_->set_text(print());
\r
278 diagnostics::register_graph(graph_);
\r
280 executor_.set_capacity(8);
\r
282 oc_->oformat = output_format_.format;
\r
284 strcpy_s(oc_->filename, filename_.c_str());
\r
286 // Add the audio and video streams using the default format codecs and initialize the codecs.
\r
287 video_st_ = add_video_stream(options);
\r
288 audio_st_ = add_audio_stream(options);
\r
290 av_dump_format(oc_.get(), 0, filename_.c_str(), 1);
\r
292 // Open the output ffmpeg, if needed.
\r
293 if (!(oc_->oformat->flags & AVFMT_NOFILE))
\r
294 THROW_ON_ERROR2(avio_open(&oc_->pb, filename.c_str(), AVIO_FLAG_WRITE), "[ffmpeg_consumer]");
\r
296 THROW_ON_ERROR2(avformat_write_header(oc_.get(), nullptr), "[ffmpeg_consumer]");
\r
298 if(options.size() > 0)
\r
300 BOOST_FOREACH(auto& option, options)
\r
301 CASPAR_LOG(warning) << L"Invalid option: -" << u16(option.name) << L" " << u16(option.value);
\r
304 CASPAR_LOG(info) << print() << L" Successfully Initialized.";
\r
311 LOG_ON_ERROR2(av_write_trailer(oc_.get()), "[ffmpeg_consumer]");
\r
316 if (!(oc_->oformat->flags & AVFMT_NOFILE))
\r
317 LOG_ON_ERROR2(avio_close(oc_->pb), "[ffmpeg_consumer]");
\r
319 CASPAR_LOG(info) << print() << L" Successfully Uninitialized.";
\r
322 std::wstring print() const
\r
324 return L"ffmpeg[" + u16(filename_) + L"]";
\r
327 std::shared_ptr<AVStream> add_video_stream(std::vector<option>& options)
\r
329 if(output_format_.vcodec == CODEC_ID_NONE)
\r
332 auto st = av_new_stream(oc_.get(), 0);
\r
334 CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Could not allocate video-stream.") << boost::errinfo_api_function("av_new_stream"));
\r
336 auto encoder = avcodec_find_encoder(output_format_.vcodec);
\r
338 CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Codec not found."));
\r
340 auto c = st->codec;
\r
342 avcodec_get_context_defaults3(c, encoder);
\r
344 c->codec_id = output_format_.vcodec;
\r
345 c->codec_type = AVMEDIA_TYPE_VIDEO;
\r
346 c->width = output_format_.width;
\r
347 c->height = output_format_.height - output_format_.croptop - output_format_.cropbot;
\r
348 c->time_base.den = format_desc_.time_scale;
\r
349 c->time_base.num = format_desc_.duration;
\r
351 c->flags |= format_desc_.field_mode == core::field_mode::progressive ? 0 : (CODEC_FLAG_INTERLACED_ME | CODEC_FLAG_INTERLACED_DCT);
\r
352 c->pix_fmt = c->pix_fmt != PIX_FMT_NONE ? c->pix_fmt : PIX_FMT_YUV420P;
\r
354 if(c->codec_id == CODEC_ID_PRORES)
\r
356 c->bit_rate = c->width < 1280 ? 63*1000000 : 220*1000000;
\r
357 c->pix_fmt = PIX_FMT_YUV422P10;
\r
359 else if(c->codec_id == CODEC_ID_DNXHD)
\r
361 if(c->width < 1280 || c->height < 720)
\r
362 CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Unsupported video dimensions."));
\r
364 c->bit_rate = 220*1000000;
\r
365 c->pix_fmt = PIX_FMT_YUV422P;
\r
367 else if(c->codec_id == CODEC_ID_DVVIDEO)
\r
369 c->width = c->height == 1280 ? 960 : c->width;
\r
371 if(format_desc_.format == core::video_format::ntsc)
\r
372 c->pix_fmt = PIX_FMT_YUV411P;
\r
373 else if(format_desc_.format == core::video_format::pal)
\r
374 c->pix_fmt = PIX_FMT_YUV420P;
\r
376 c->pix_fmt = PIX_FMT_YUV422P;
\r
378 if(format_desc_.duration == 1001)
\r
379 c->width = c->height == 1080 ? 1280 : c->width;
\r
381 c->width = c->height == 1080 ? 1440 : c->width;
\r
383 else if(c->codec_id == CODEC_ID_H264)
\r
385 c->pix_fmt = PIX_FMT_YUV420P;
\r
386 av_opt_set(c->priv_data, "preset", "ultrafast", 0);
\r
387 av_opt_set(c->priv_data, "tune", "fastdecode", 0);
\r
388 av_opt_set(c->priv_data, "crf", "5", 0);
\r
390 else if(c->codec_id == CODEC_ID_QTRLE)
\r
392 c->pix_fmt = PIX_FMT_ARGB;
\r
395 boost::range::remove_erase_if(options, [&](const option& o)
\r
397 return o.name.at(0) != 'a' && ffmpeg::av_opt_set(c, o.name.c_str(), o.value.c_str(), AV_OPT_SEARCH_CHILDREN) > -1;
\r
400 if(output_format_.format->flags & AVFMT_GLOBALHEADER)
\r
401 c->flags |= CODEC_FLAG_GLOBAL_HEADER;
\r
403 THROW_ON_ERROR2(tbb_avcodec_open(c, encoder), "[ffmpeg_consumer]");
\r
405 return std::shared_ptr<AVStream>(st, [](AVStream* st)
\r
407 LOG_ON_ERROR2(tbb_avcodec_close(st->codec), "[ffmpeg_consumer]");
\r
408 av_freep(&st->codec);
\r
413 std::shared_ptr<AVStream> add_audio_stream(std::vector<option>& options)
\r
415 if(output_format_.acodec == CODEC_ID_NONE)
\r
418 auto st = av_new_stream(oc_.get(), 1);
\r
420 CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Could not allocate audio-stream") << boost::errinfo_api_function("av_new_stream"));
\r
422 auto encoder = avcodec_find_encoder(output_format_.acodec);
\r
424 CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("codec not found"));
\r
426 auto c = st->codec;
\r
428 avcodec_get_context_defaults3(c, encoder);
\r
430 c->codec_id = output_format_.acodec;
\r
431 c->codec_type = AVMEDIA_TYPE_AUDIO;
\r
432 c->sample_rate = 48000;
\r
434 c->sample_fmt = AV_SAMPLE_FMT_S16;
\r
435 c->time_base.num = 1;
\r
436 c->time_base.den = c->sample_rate;
\r
438 if(output_format_.vcodec == CODEC_ID_FLV1)
\r
439 c->sample_rate = 44100;
\r
441 if(output_format_.format->flags & AVFMT_GLOBALHEADER)
\r
442 c->flags |= CODEC_FLAG_GLOBAL_HEADER;
\r
444 boost::range::remove_erase_if(options, [&](const option& o)
\r
446 return ffmpeg::av_opt_set(c, o.name.c_str(), o.value.c_str(), AV_OPT_SEARCH_CHILDREN) > -1;
\r
449 THROW_ON_ERROR2(avcodec_open(c, encoder), "[ffmpeg_consumer]");
\r
451 return std::shared_ptr<AVStream>(st, [](AVStream* st)
\r
453 LOG_ON_ERROR2(avcodec_close(st->codec), "[ffmpeg_consumer]");;
\r
454 av_freep(&st->codec);
\r
459 void encode_video_frame(core::const_frame frame)
\r
464 auto enc = video_st_->codec;
\r
466 auto av_frame = convert_video(frame, enc);
\r
467 av_frame->interlaced_frame = format_desc_.field_mode != core::field_mode::progressive;
\r
468 av_frame->top_field_first = format_desc_.field_mode == core::field_mode::upper;
\r
469 av_frame->pts = frame_number_++;
\r
472 av_init_packet(&pkt);
\r
473 pkt.data = nullptr;
\r
476 int got_packet = 0;
\r
477 THROW_ON_ERROR2(avcodec_encode_video2(enc, &pkt, av_frame.get(), &got_packet), "[ffmpeg_consumer]");
\r
478 std::shared_ptr<AVPacket> guard(&pkt, av_free_packet);
\r
483 if (pkt.pts != AV_NOPTS_VALUE)
\r
484 pkt.pts = av_rescale_q(pkt.pts, enc->time_base, video_st_->time_base);
\r
485 if (pkt.dts != AV_NOPTS_VALUE)
\r
486 pkt.dts = av_rescale_q(pkt.dts, enc->time_base, video_st_->time_base);
\r
488 pkt.stream_index = video_st_->index;
\r
490 THROW_ON_ERROR2(av_interleaved_write_frame(oc_.get(), &pkt), "[ffmpeg_consumer]");
\r
493 uint64_t get_channel_layout(AVCodecContext* dec)
\r
495 auto layout = (dec->channel_layout && dec->channels == av_get_channel_layout_nb_channels(dec->channel_layout)) ? dec->channel_layout : av_get_default_channel_layout(dec->channels);
\r
499 void encode_audio_frame(core::const_frame frame)
\r
504 auto enc = audio_st_->codec;
\r
506 boost::push_back(audio_buffer_, convert_audio(frame, enc));
\r
508 auto frame_size = enc->frame_size != 0 ? enc->frame_size * enc->channels * av_get_bytes_per_sample(enc->sample_fmt) : static_cast<int>(audio_buffer_.size());
\r
510 while(audio_buffer_.size() >= frame_size)
\r
512 std::shared_ptr<AVFrame> av_frame(avcodec_alloc_frame(), av_free);
\r
513 avcodec_get_frame_defaults(av_frame.get());
\r
514 av_frame->nb_samples = frame_size / (enc->channels * av_get_bytes_per_sample(enc->sample_fmt));
\r
517 av_init_packet(&pkt);
\r
518 pkt.data = nullptr;
\r
521 THROW_ON_ERROR2(avcodec_fill_audio_frame(av_frame.get(), enc->channels, enc->sample_fmt, audio_buffer_.data(), frame_size, 1), "[ffmpeg_consumer]");
\r
523 int got_packet = 0;
\r
524 THROW_ON_ERROR2(avcodec_encode_audio2(enc, &pkt, av_frame.get(), &got_packet), "[ffmpeg_consumer]");
\r
525 std::shared_ptr<AVPacket> guard(&pkt, av_free_packet);
\r
527 audio_buffer_.erase(audio_buffer_.begin(), audio_buffer_.begin() + frame_size);
\r
532 if (pkt.pts != AV_NOPTS_VALUE)
\r
533 pkt.pts = av_rescale_q(pkt.pts, enc->time_base, audio_st_->time_base);
\r
534 if (pkt.dts != AV_NOPTS_VALUE)
\r
535 pkt.dts = av_rescale_q(pkt.dts, enc->time_base, audio_st_->time_base);
\r
536 if (pkt.duration > 0)
\r
537 pkt.duration = static_cast<int>(av_rescale_q(pkt.duration, enc->time_base, audio_st_->time_base));
\r
539 pkt.stream_index = audio_st_->index;
\r
541 THROW_ON_ERROR2(av_interleaved_write_frame(oc_.get(), &pkt), "[ffmpeg_consumer]");
\r
545 std::shared_ptr<AVFrame> convert_video(core::const_frame frame, AVCodecContext* c)
\r
549 sws_.reset(sws_getContext(format_desc_.width,
\r
550 format_desc_.height - output_format_.croptop - output_format_.cropbot,
\r
555 SWS_BICUBIC, nullptr, nullptr, nullptr),
\r
557 if (sws_ == nullptr)
\r
558 CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Cannot initialize the conversion context"));
\r
561 std::shared_ptr<AVFrame> in_frame(avcodec_alloc_frame(), av_free);
\r
563 avpicture_fill(reinterpret_cast<AVPicture*>(in_frame.get()),
\r
564 const_cast<uint8_t*>(frame.image_data().begin()),
\r
566 format_desc_.width,
\r
567 format_desc_.height - output_format_.croptop - output_format_.cropbot);
\r
569 for(int n = 0; n < 4; ++n)
\r
570 in_frame->data[n] += in_frame->linesize[n] * output_format_.croptop;
\r
572 picture_buffer_.resize(avpicture_get_size(c->pix_fmt, c->width, c->height));
\r
574 std::shared_ptr<AVFrame> out_frame(avcodec_alloc_frame(), av_free);
\r
576 avpicture_fill(reinterpret_cast<AVPicture*>(out_frame.get()),
\r
577 picture_buffer_.data(),
\r
582 sws_scale(sws_.get(),
\r
584 in_frame->linesize,
\r
586 format_desc_.height - output_format_.cropbot - output_format_.croptop,
\r
588 out_frame->linesize);
\r
593 byte_vector convert_audio(core::const_frame& frame, AVCodecContext* c)
\r
597 swr_ = std::shared_ptr<SwrContext>(swr_alloc_set_opts(nullptr,
\r
598 get_channel_layout(c), c->sample_fmt, c->sample_rate,
\r
599 av_get_default_channel_layout(format_desc_.audio_channels), AV_SAMPLE_FMT_S32, format_desc_.audio_sample_rate,
\r
600 0, nullptr), [](SwrContext* p){swr_free(&p);});
\r
603 CASPAR_THROW_EXCEPTION(bad_alloc());
\r
605 THROW_ON_ERROR2(swr_init(swr_.get()), "[audio_decoder]");
\r
608 byte_vector buffer(48000);
\r
610 const uint8_t* in[] = {reinterpret_cast<const uint8_t*>(frame.audio_data().data())};
\r
611 uint8_t* out[] = {buffer.data()};
\r
613 auto channel_samples = swr_convert(swr_.get(),
\r
614 out, static_cast<int>(buffer.size()) / c->channels / av_get_bytes_per_sample(c->sample_fmt),
\r
615 in, static_cast<int>(frame.audio_data().size()/format_desc_.audio_channels));
\r
617 buffer.resize(channel_samples * c->channels * av_get_bytes_per_sample(c->sample_fmt));
\r
624 auto space = boost::filesystem::space(boost::filesystem::path(filename_).parent_path());
\r
625 if(space.available < 512*1000000)
\r
626 BOOST_THROW_EXCEPTION(file_write_error() << msg_info("out of space"));
\r
629 void encode(const core::const_frame& frame)
\r
633 if(frame_number_ % 25 == 0)
\r
636 boost::timer frame_timer;
\r
638 encode_video_frame(frame);
\r
639 encode_audio_frame(frame);
\r
641 graph_->set_value("frame-time", frame_timer.elapsed()*format_desc_.fps*0.5);
\r
645 lock(exception_mutex_, [&]
\r
647 exception_ = std::current_exception();
\r
652 bool send(core::const_frame& frame)
\r
654 auto exception = lock(exception_mutex_, [&]
\r
659 if(exception != nullptr)
\r
660 std::rethrow_exception(exception);
\r
662 executor_.begin_invoke([=]
\r
671 struct ffmpeg_consumer_proxy : public core::frame_consumer
\r
673 const std::wstring filename_;
\r
674 const std::vector<option> options_;
\r
676 std::unique_ptr<ffmpeg_consumer> consumer_;
\r
680 ffmpeg_consumer_proxy(const std::wstring& filename, const std::vector<option>& options)
\r
681 : filename_(filename)
\r
682 , options_(options)
\r
686 virtual void initialize(const core::video_format_desc& format_desc, int)
\r
689 BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("Cannot reinitialize ffmpeg-consumer."));
\r
691 consumer_.reset(new ffmpeg_consumer(u8(filename_), format_desc, options_));
\r
694 bool send(core::const_frame frame) override
\r
696 return consumer_->send(frame);
\r
699 std::wstring print() const override
\r
701 return consumer_ ? consumer_->print() : L"[ffmpeg_consumer]";
\r
704 std::wstring name() const override
\r
709 boost::property_tree::wptree info() const override
\r
711 boost::property_tree::wptree info;
\r
712 info.add(L"type", L"file");
\r
713 info.add(L"filename", filename_);
\r
717 bool has_synchronization_clock() const override
\r
722 int buffer_depth() const override
\r
727 int index() const override
\r
732 spl::shared_ptr<core::frame_consumer> create_consumer(const std::vector<std::wstring>& params)
\r
734 if(params.size() < 1 || params[0] != L"FILE")
\r
735 return core::frame_consumer::empty();
\r
737 auto filename = (params.size() > 1 ? params[1] : L"");
\r
739 std::vector<option> options;
\r
741 if(params.size() >= 3)
\r
743 for(auto opt_it = params.begin()+2; opt_it != params.end();)
\r
745 auto name = u8(boost::trim_copy(boost::to_lower_copy(*opt_it++))).substr(1);
\r
746 auto value = u8(boost::trim_copy(boost::to_lower_copy(*opt_it++)));
\r
748 if(value == "h264")
\r
750 else if(value == "dvcpro")
\r
753 options.push_back(option(name, value));
\r
757 return spl::make_shared<ffmpeg_consumer_proxy>(env::media_folder() + filename, options);
\r
760 spl::shared_ptr<core::frame_consumer> create_consumer(const boost::property_tree::wptree& ptree)
\r
762 auto filename = ptree.get<std::wstring>(L"path");
\r
763 auto codec = ptree.get(L"vcodec", L"libx264");
\r
765 std::vector<option> options;
\r
766 options.push_back(option("vcodec", u8(codec)));
\r
768 return spl::make_shared<ffmpeg_consumer_proxy>(env::media_folder() + filename, options);
\r