3 #include "ffmpeg_consumer.h"
5 #include "../util/error.h"
7 #include <common/except.h>
8 #include <common/executor.h>
9 #include <common/assert.h>
10 #include <common/utf.h>
11 #include <common/future.h>
12 #include <common/env.h>
13 #include <common/scope_exit.h>
15 #include <core/consumer/frame_consumer.h>
16 #include <core/frame/frame.h>
17 #include <core/video_format.h>
18 #include <core/monitor/monitor.h>
20 #include <boost/noncopyable.hpp>
21 #include <boost/rational.hpp>
22 #include <boost/format.hpp>
23 #include <boost/algorithm/string/predicate.hpp>
24 #include <boost/property_tree/ptree.hpp>
27 #pragma warning(disable: 4244)
28 #pragma warning(disable: 4245)
29 #include <boost/crc.hpp>
32 #include <tbb/atomic.h>
33 #include <tbb/concurrent_queue.h>
34 #include <tbb/parallel_invoke.h>
35 #include <tbb/parallel_for.h>
41 #pragma warning(disable: 4244)
45 #define __STDC_CONSTANT_MACROS
46 #define __STDC_LIMIT_MACROS
47 #include <libavformat/avformat.h>
48 #include <libavcodec/avcodec.h>
49 #include <libavutil/avutil.h>
50 #include <libavutil/frame.h>
51 #include <libavutil/opt.h>
52 #include <libavutil/imgutils.h>
53 #include <libavutil/parseutils.h>
54 #include <libavfilter/avfilter.h>
55 #include <libavfilter/buffersink.h>
56 #include <libavfilter/buffersrc.h>
61 using namespace Concurrency;
63 namespace caspar { namespace ffmpeg {
65 int crc16(const std::string& str)
67 boost::crc_16_type result;
69 result.process_bytes(str.data(), str.length());
71 return result.checksum();
74 class streaming_consumer final : public core::frame_consumer
80 core::monitor::subject subject_;
81 boost::filesystem::path path_;
82 int consumer_index_offset_;
84 std::map<std::string, std::string> options_;
86 core::video_format_desc in_video_format_;
88 std::shared_ptr<AVFormatContext> oc_;
89 tbb::atomic<bool> abort_request_;
91 std::shared_ptr<AVStream> video_st_;
92 std::shared_ptr<AVStream> audio_st_;
94 std::int64_t video_pts_;
95 std::int64_t audio_pts_;
97 AVFilterContext* audio_graph_in_;
98 AVFilterContext* audio_graph_out_;
99 std::shared_ptr<AVFilterGraph> audio_graph_;
100 std::shared_ptr<AVBitStreamFilterContext> audio_bitstream_filter_;
102 AVFilterContext* video_graph_in_;
103 AVFilterContext* video_graph_out_;
104 std::shared_ptr<AVFilterGraph> video_graph_;
105 std::shared_ptr<AVBitStreamFilterContext> video_bitstream_filter_;
109 executor video_encoder_executor_;
110 executor audio_encoder_executor_;
112 tbb::atomic<int> tokens_;
113 boost::mutex tokens_mutex_;
114 boost::condition_variable tokens_cond_;
116 executor write_executor_;
124 , consumer_index_offset_(crc16(path))
128 , audio_encoder_executor_(print() + L" audio_encoder")
129 , video_encoder_executor_(print() + L" video_encoder")
130 , write_executor_(print() + L" io")
132 abort_request_ = false;
135 boost::sregex_iterator(
138 boost::regex("-(?<NAME>[^-\\s]+)(\\s+(?<VALUE>[^\\s]+))?"));
139 it != boost::sregex_iterator();
142 options_[(*it)["NAME"].str()] = (*it)["VALUE"].matched ? (*it)["VALUE"].str() : "";
145 if (options_.find("threads") == options_.end())
146 options_["threads"] = "auto";
153 boost::regex("tokens")).get_value_or(2));
156 ~streaming_consumer()
160 video_encoder_executor_.begin_invoke([&] { encode_video(core::const_frame::empty(), nullptr); });
161 audio_encoder_executor_.begin_invoke([&] { encode_audio(core::const_frame::empty(), nullptr); });
163 video_encoder_executor_.stop();
164 audio_encoder_executor_.stop();
165 video_encoder_executor_.join();
166 audio_encoder_executor_.join();
168 video_graph_.reset();
169 audio_graph_.reset();
173 write_packet(nullptr, nullptr);
175 write_executor_.stop();
176 write_executor_.join();
178 FF(av_write_trailer(oc_.get()));
180 if (!(oc_->oformat->flags & AVFMT_NOFILE) && oc_->pb)
188 const core::video_format_desc& format_desc,
189 int channel_index) override
193 static boost::regex prot_exp("^.+:.*" );
195 const auto overwrite =
196 try_remove_arg<std::string>(
198 boost::regex("y")) != nullptr;
200 if(!boost::regex_match(
204 if(!path_.is_complete())
208 env::media_folder()) +
212 if(boost::filesystem::exists(path_))
215 BOOST_THROW_EXCEPTION(invalid_argument() << msg_info("File exists"));
217 boost::filesystem::remove(path_);
221 const auto oformat_name =
222 try_remove_arg<std::string>(
224 boost::regex("^f|format$"));
228 FF(avformat_alloc_output_context2(
231 oformat_name && !oformat_name->empty() ? oformat_name->c_str() : nullptr,
232 path_.string().c_str()));
236 avformat_free_context);
238 CASPAR_VERIFY(oc_->oformat);
240 oc_->interrupt_callback.callback = streaming_consumer::interrupt_cb;
241 oc_->interrupt_callback.opaque = this;
243 CASPAR_VERIFY(format_desc.format != core::video_format::invalid);
245 in_video_format_ = format_desc;
247 CASPAR_VERIFY(oc_->oformat);
249 const auto video_codec_name =
250 try_remove_arg<std::string>(
252 boost::regex("^c:v|codec:v|vcodec$"));
254 const auto video_codec =
256 ? avcodec_find_encoder_by_name(video_codec_name->c_str())
257 : avcodec_find_encoder(oc_->oformat->video_codec);
259 const auto audio_codec_name =
260 try_remove_arg<std::string>(
262 boost::regex("^c:a|codec:a|acodec$"));
264 const auto audio_codec =
266 ? avcodec_find_encoder_by_name(audio_codec_name->c_str())
267 : avcodec_find_encoder(oc_->oformat->audio_codec);
270 BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(
271 "Failed to find video codec " + (video_codec_name
273 : "with id " + boost::lexical_cast<std::string>(
274 oc_->oformat->video_codec))));
276 BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(
277 "Failed to find audio codec " + (audio_codec_name
279 : "with id " + boost::lexical_cast<std::string>(
280 oc_->oformat->audio_codec))));
285 configure_video_filters(
287 try_remove_arg<std::string>(options_,
288 boost::regex("vf|f:v|filter:v")).get_value_or(""));
290 configure_audio_filters(
292 try_remove_arg<std::string>(options_,
293 boost::regex("af|f:a|filter:a")).get_value_or(""));
298 configue_audio_bistream_filters(options_);
299 configue_video_bistream_filters(options_);
305 auto video_options = options_;
306 auto audio_options = options_;
308 video_st_ = open_encoder(
312 audio_st_ = open_encoder(
316 auto it = options_.begin();
317 while(it != options_.end())
319 if(video_options.find(it->first) == video_options.end() || audio_options.find(it->first) == audio_options.end())
320 it = options_.erase(it);
328 AVDictionary* av_opts = nullptr;
332 std::move(options_));
336 av_dict_free(&av_opts);
339 if (!(oc_->oformat->flags & AVFMT_NOFILE))
343 path_.string().c_str(),
345 &oc_->interrupt_callback,
349 FF(avformat_write_header(
353 options_ = to_map(av_opts);
364 for (const auto& option : options_)
367 << L"Invalid option: -"
370 << u16(option.second);
382 core::monitor::subject& monitor_output() override
387 std::wstring name() const override
392 std::future<bool> send(core::const_frame frame) override
394 CASPAR_VERIFY(in_video_format_.format != core::video_format::invalid);
397 std::shared_ptr<void> token(
402 tokens_cond_.notify_one();
405 return executor_.begin_invoke([=]() -> bool
407 boost::unique_lock<boost::mutex> tokens_lock(tokens_mutex_);
410 tokens_cond_.wait(tokens_lock);
412 video_encoder_executor_.begin_invoke([=]() mutable
419 audio_encoder_executor_.begin_invoke([=]() mutable
430 std::wstring print() const override
432 return L"streaming_consumer[" + u16(path_.string()) + L"]";
435 virtual boost::property_tree::wptree info() const override
437 return boost::property_tree::wptree();
440 bool has_synchronization_clock() const override
445 int buffer_depth() const override
450 int index() const override
452 return 100000 + consumer_index_offset_;
457 static int interrupt_cb(void* ctx)
460 return reinterpret_cast<streaming_consumer*>(ctx)->abort_request_;
463 std::shared_ptr<AVStream> open_encoder(
464 const AVCodec& codec,
465 std::map<std::string,
466 std::string>& options)
474 BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Could not allocate video-stream.") << boost::errinfo_api_function("av_new_stream"));
476 auto enc = st->codec;
480 switch(enc->codec_type)
482 case AVMEDIA_TYPE_VIDEO:
484 enc->time_base = video_graph_out_->inputs[0]->time_base;
485 enc->pix_fmt = static_cast<AVPixelFormat>(video_graph_out_->inputs[0]->format);
486 enc->sample_aspect_ratio = st->sample_aspect_ratio = video_graph_out_->inputs[0]->sample_aspect_ratio;
487 enc->width = video_graph_out_->inputs[0]->w;
488 enc->height = video_graph_out_->inputs[0]->h;
492 case AVMEDIA_TYPE_AUDIO:
494 enc->time_base = audio_graph_out_->inputs[0]->time_base;
495 enc->sample_fmt = static_cast<AVSampleFormat>(audio_graph_out_->inputs[0]->format);
496 enc->sample_rate = audio_graph_out_->inputs[0]->sample_rate;
497 enc->channel_layout = audio_graph_out_->inputs[0]->channel_layout;
498 enc->channels = audio_graph_out_->inputs[0]->channels;
504 if(oc_->oformat->flags & AVFMT_GLOBALHEADER)
505 enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
507 static const std::array<std::string, 4> char_id_map = {{"v", "a", "d", "s"}};
509 const auto char_id = char_id_map.at(enc->codec_type);
511 const auto codec_opts =
514 boost::regex("^(" + char_id + "?[^:]+):" + char_id + "$"));
516 AVDictionary* av_codec_opts = nullptr;
531 av_codec_opts ? &av_codec_opts : nullptr));
540 AV_DICT_IGNORE_SUFFIX);
544 options[t->key + (codec_opts.find(t->key) != codec_opts.end() ? ":" + char_id : "")] = t->value;
550 AV_DICT_IGNORE_SUFFIX);
553 av_dict_free(&av_codec_opts);
556 if(enc->codec_type == AVMEDIA_TYPE_AUDIO && !(codec.capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE))
558 CASPAR_ASSERT(enc->frame_size > 0);
559 av_buffersink_set_frame_size(audio_graph_out_,
563 return std::shared_ptr<AVStream>(st, [this](AVStream* st)
565 avcodec_close(st->codec);
569 void configue_audio_bistream_filters(
570 std::map<std::string, std::string>& options)
572 const auto audio_bitstream_filter_str =
573 try_remove_arg<std::string>(
575 boost::regex("^bsf:a|absf$"));
577 const auto audio_bitstream_filter =
578 audio_bitstream_filter_str
579 ? av_bitstream_filter_init(audio_bitstream_filter_str->c_str())
582 CASPAR_VERIFY(!audio_bitstream_filter_str || audio_bitstream_filter);
584 if(audio_bitstream_filter)
586 audio_bitstream_filter_.reset(
587 audio_bitstream_filter,
588 av_bitstream_filter_close);
591 if(audio_bitstream_filter_str && !audio_bitstream_filter_)
592 options["bsf:a"] = *audio_bitstream_filter_str;
595 void configue_video_bistream_filters(
596 std::map<std::string, std::string>& options)
598 const auto video_bitstream_filter_str =
599 try_remove_arg<std::string>(
601 boost::regex("^bsf:v|vbsf$"));
603 const auto video_bitstream_filter =
604 video_bitstream_filter_str
605 ? av_bitstream_filter_init(video_bitstream_filter_str->c_str())
608 CASPAR_VERIFY(!video_bitstream_filter_str || video_bitstream_filter);
610 if(video_bitstream_filter)
612 video_bitstream_filter_.reset(
613 video_bitstream_filter,
614 av_bitstream_filter_close);
617 if(video_bitstream_filter_str && !video_bitstream_filter_)
618 options["bsf:v"] = *video_bitstream_filter_str;
621 void configure_video_filters(
622 const AVCodec& codec,
623 const std::string& filtergraph)
626 avfilter_graph_alloc(),
629 avfilter_graph_free(&p);
632 video_graph_->nb_threads = boost::thread::hardware_concurrency()/2;
633 video_graph_->thread_type = AVFILTER_THREAD_SLICE;
635 const auto sample_aspect_ratio =
636 boost::rational<int>(
637 in_video_format_.square_width,
638 in_video_format_.square_height) /
639 boost::rational<int>(
640 in_video_format_.width,
641 in_video_format_.height);
643 const auto vsrc_options = (boost::format("video_size=%1%x%2%:pix_fmt=%3%:time_base=%4%/%5%:pixel_aspect=%6%/%7%:frame_rate=%8%/%9%")
644 % in_video_format_.width % in_video_format_.height
646 % in_video_format_.duration % in_video_format_.time_scale
647 % sample_aspect_ratio.numerator() % sample_aspect_ratio.denominator()
648 % in_video_format_.time_scale % in_video_format_.duration).str();
650 AVFilterContext* filt_vsrc = nullptr;
651 FF(avfilter_graph_create_filter(
653 avfilter_get_by_name("buffer"),
654 "ffmpeg_consumer_buffer",
655 vsrc_options.c_str(),
657 video_graph_.get()));
659 AVFilterContext* filt_vsink = nullptr;
660 FF(avfilter_graph_create_filter(
662 avfilter_get_by_name("buffersink"),
663 "ffmpeg_consumer_buffersink",
666 video_graph_.get()));
668 #pragma warning (push)
669 #pragma warning (disable : 4245)
671 FF(av_opt_set_int_list(
676 AV_OPT_SEARCH_CHILDREN));
678 #pragma warning (pop)
680 configure_filtergraph(
686 video_graph_in_ = filt_vsrc;
687 video_graph_out_ = filt_vsink;
690 << u16(std::string("\n")
691 + avfilter_graph_dump(
696 void configure_audio_filters(
697 const AVCodec& codec,
698 const std::string& filtergraph)
701 avfilter_graph_alloc(),
704 avfilter_graph_free(&p);
707 audio_graph_->nb_threads = boost::thread::hardware_concurrency()/2;
708 audio_graph_->thread_type = AVFILTER_THREAD_SLICE;
710 const auto asrc_options = (boost::format("sample_rate=%1%:sample_fmt=%2%:channels=%3%:time_base=%4%/%5%:channel_layout=%6%")
711 % in_video_format_.audio_sample_rate
712 % av_get_sample_fmt_name(AV_SAMPLE_FMT_S32)
713 % in_video_format_.audio_channels
714 % 1 % in_video_format_.audio_sample_rate
718 av_get_default_channel_layout(in_video_format_.audio_channels))).str();
720 AVFilterContext* filt_asrc = nullptr;
721 FF(avfilter_graph_create_filter(
723 avfilter_get_by_name("abuffer"),
724 "ffmpeg_consumer_abuffer",
725 asrc_options.c_str(),
727 audio_graph_.get()));
729 AVFilterContext* filt_asink = nullptr;
730 FF(avfilter_graph_create_filter(
732 avfilter_get_by_name("abuffersink"),
733 "ffmpeg_consumer_abuffersink",
736 audio_graph_.get()));
738 #pragma warning (push)
739 #pragma warning (disable : 4245)
743 "all_channel_counts",
745 AV_OPT_SEARCH_CHILDREN));
747 FF(av_opt_set_int_list(
752 AV_OPT_SEARCH_CHILDREN));
754 FF(av_opt_set_int_list(
757 codec.channel_layouts,
759 AV_OPT_SEARCH_CHILDREN));
761 FF(av_opt_set_int_list(
764 codec.supported_samplerates,
766 AV_OPT_SEARCH_CHILDREN));
768 #pragma warning (pop)
770 configure_filtergraph(
776 audio_graph_in_ = filt_asrc;
777 audio_graph_out_ = filt_asink;
780 << u16(std::string("\n")
781 + avfilter_graph_dump(
786 void configure_filtergraph(
787 AVFilterGraph& graph,
788 const std::string& filtergraph,
789 AVFilterContext& source_ctx,
790 AVFilterContext& sink_ctx)
792 AVFilterInOut* outputs = nullptr;
793 AVFilterInOut* inputs = nullptr;
797 if(!filtergraph.empty())
799 outputs = avfilter_inout_alloc();
800 inputs = avfilter_inout_alloc();
802 CASPAR_VERIFY(outputs && inputs);
804 outputs->name = av_strdup("in");
805 outputs->filter_ctx = &source_ctx;
806 outputs->pad_idx = 0;
807 outputs->next = nullptr;
809 inputs->name = av_strdup("out");
810 inputs->filter_ctx = &sink_ctx;
812 inputs->next = nullptr;
814 FF(avfilter_graph_parse(
830 FF(avfilter_graph_config(
836 avfilter_inout_free(&outputs);
837 avfilter_inout_free(&inputs);
842 void encode_video(core::const_frame frame_ptr, std::shared_ptr<void> token)
847 auto enc = video_st_->codec;
849 std::shared_ptr<AVFrame> src_av_frame;
851 if(frame_ptr != core::const_frame::empty())
855 [frame_ptr](AVFrame* frame)
857 av_frame_free(&frame);
860 avcodec_get_frame_defaults(src_av_frame.get());
862 const auto sample_aspect_ratio =
863 boost::rational<int>(
864 in_video_format_.square_width,
865 in_video_format_.square_height) /
866 boost::rational<int>(
867 in_video_format_.width,
868 in_video_format_.height);
870 src_av_frame->format = AV_PIX_FMT_BGRA;
871 src_av_frame->width = in_video_format_.width;
872 src_av_frame->height = in_video_format_.height;
873 src_av_frame->sample_aspect_ratio.num = sample_aspect_ratio.numerator();
874 src_av_frame->sample_aspect_ratio.den = sample_aspect_ratio.denominator();
875 src_av_frame->pts = video_pts_;
879 FF(av_image_fill_arrays(
881 src_av_frame->linesize,
882 frame_ptr.image_data().begin(),
883 static_cast<AVPixelFormat>(src_av_frame->format),
884 in_video_format_.width,
885 in_video_format_.height,
888 FF(av_buffersrc_add_frame(
890 src_av_frame.get()));
897 std::shared_ptr<AVFrame> filt_frame(
904 ret = av_buffersink_get_frame(
908 video_encoder_executor_.begin_invoke([=]
910 if(ret == AVERROR_EOF)
912 if(enc->codec->capabilities & CODEC_CAP_DELAY)
914 while(encode_av_frame(
916 video_bitstream_filter_.get(),
917 avcodec_encode_video2,
920 boost::this_thread::yield(); // TODO:
924 else if(ret != AVERROR(EAGAIN))
926 FF_RET(ret, "av_buffersink_get_frame");
928 if (filt_frame->interlaced_frame)
930 if (enc->codec->id == AV_CODEC_ID_MJPEG)
931 enc->field_order = filt_frame->top_field_first ? AV_FIELD_TT : AV_FIELD_BB;
933 enc->field_order = filt_frame->top_field_first ? AV_FIELD_TB : AV_FIELD_BT;
936 enc->field_order = AV_FIELD_PROGRESSIVE;
938 filt_frame->quality = enc->global_quality;
940 if (!enc->me_threshold)
941 filt_frame->pict_type = AV_PICTURE_TYPE_NONE;
945 video_bitstream_filter_.get(),
946 avcodec_encode_video2,
950 boost::this_thread::yield(); // TODO:
956 void encode_audio(core::const_frame frame_ptr, std::shared_ptr<void> token)
961 auto enc = audio_st_->codec;
963 std::shared_ptr<AVFrame> src_av_frame;
965 if(frame_ptr != core::const_frame::empty())
974 src_av_frame->channels = in_video_format_.audio_channels;
975 src_av_frame->channel_layout = av_get_default_channel_layout(in_video_format_.audio_channels);
976 src_av_frame->sample_rate = in_video_format_.audio_sample_rate;
977 src_av_frame->nb_samples = static_cast<int>(frame_ptr.audio_data().size()) / src_av_frame->channels;
978 src_av_frame->format = AV_SAMPLE_FMT_S32;
979 src_av_frame->pts = audio_pts_;
981 audio_pts_ += src_av_frame->nb_samples;
983 FF(av_samples_fill_arrays(
984 src_av_frame->extended_data,
985 src_av_frame->linesize,
986 reinterpret_cast<const std::uint8_t*>(&*frame_ptr.audio_data().begin()),
987 src_av_frame->channels,
988 src_av_frame->nb_samples,
989 static_cast<AVSampleFormat>(src_av_frame->format),
992 FF(av_buffersrc_add_frame(
994 src_av_frame.get()));
1001 std::shared_ptr<AVFrame> filt_frame(
1008 ret = av_buffersink_get_frame(
1012 audio_encoder_executor_.begin_invoke([=]
1014 if(ret == AVERROR_EOF)
1016 if(enc->codec->capabilities & CODEC_CAP_DELAY)
1018 while(encode_av_frame(
1020 audio_bitstream_filter_.get(),
1021 avcodec_encode_audio2,
1025 boost::this_thread::yield(); // TODO:
1029 else if(ret != AVERROR(EAGAIN))
1033 "av_buffersink_get_frame");
1037 audio_bitstream_filter_.get(),
1038 avcodec_encode_audio2,
1042 boost::this_thread::yield(); // TODO:
1048 template<typename F>
1049 bool encode_av_frame(
1051 AVBitStreamFilterContext* bsfc,
1053 const std::shared_ptr<AVFrame>& src_av_frame,
1054 std::shared_ptr<void> token)
1057 av_init_packet(&pkt);
1067 if(!got_packet || pkt.size <= 0)
1070 pkt.stream_index = st.index;
1076 auto a = av_bitstream_filter_filter(
1084 pkt.flags & AV_PKT_FLAG_KEY);
1086 if(a == 0 && new_pkt.data != pkt.data && new_pkt.destruct)
1088 auto t = reinterpret_cast<std::uint8_t*>(av_malloc(new_pkt.size + FF_INPUT_BUFFER_PADDING_SIZE));
1100 FF_INPUT_BUFFER_PADDING_SIZE);
1103 new_pkt.buf = nullptr;
1106 a = AVERROR(ENOMEM);
1109 av_free_packet(&pkt);
1113 "av_bitstream_filter_filter");
1119 av_buffer_default_free,
1123 CASPAR_VERIFY(new_pkt.buf);
1128 if (pkt.pts != AV_NOPTS_VALUE)
1133 st.codec->time_base,
1137 if (pkt.dts != AV_NOPTS_VALUE)
1142 st.codec->time_base,
1150 st.codec->time_base, st.time_base));
1153 std::shared_ptr<AVPacket>(
1165 const std::shared_ptr<AVPacket>& pkt_ptr,
1166 std::shared_ptr<void> token)
1168 write_executor_.begin_invoke([this, pkt_ptr, token]() mutable
1170 FF(av_interleaved_write_frame(
1176 template<typename T>
1177 static boost::optional<T> try_remove_arg(
1178 std::map<std::string, std::string>& options,
1179 const boost::regex& expr)
1181 for(auto it = options.begin(); it != options.end(); ++it)
1183 if(boost::regex_search(it->first, expr))
1185 auto arg = it->second;
1187 return boost::lexical_cast<T>(arg);
1191 return boost::optional<T>();
1194 static std::map<std::string, std::string> remove_options(
1195 std::map<std::string, std::string>& options,
1196 const boost::regex& expr)
1198 std::map<std::string, std::string> result;
1200 auto it = options.begin();
1201 while(it != options.end())
1204 if(boost::regex_search(it->first, what, expr))
1207 what.size() > 0 && what[1].matched
1209 : it->first] = it->second;
1210 it = options.erase(it);
1219 static void to_dict(AVDictionary** dest, const std::map<std::string, std::string>& c)
1221 for (const auto& entry : c)
1225 entry.first.c_str(),
1226 entry.second.c_str(), 0);
1230 static std::map<std::string, std::string> to_map(AVDictionary* dict)
1232 std::map<std::string, std::string> result;
1239 AV_DICT_IGNORE_SUFFIX)
1246 AV_DICT_IGNORE_SUFFIX))
1248 result[t->key] = t->value;
1255 spl::shared_ptr<core::frame_consumer> create_streaming_consumer(
1256 const std::vector<std::wstring>& params, core::interaction_sink*)
1258 if (params.size() < 1 || params.at(0) != L"STREAM")
1259 return core::frame_consumer::empty();
1261 auto path = u8(params.at(1));
1262 auto args = u8(boost::join(params, L" "));
1264 return spl::make_shared<streaming_consumer>(path, args);
1267 spl::shared_ptr<core::frame_consumer> create_preconfigured_streaming_consumer(
1268 const boost::property_tree::wptree& ptree, core::interaction_sink*)
1270 return spl::make_shared<streaming_consumer>(
1271 u8(ptree.get<std::wstring>(L"path")),
1272 u8(ptree.get<std::wstring>(L"args", L"")));