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>
40 #pragma warning(disable: 4244)
44 #define __STDC_CONSTANT_MACROS
45 #define __STDC_LIMIT_MACROS
46 #include <libavformat/avformat.h>
47 #include <libavcodec/avcodec.h>
48 #include <libavutil/avutil.h>
49 #include <libavutil/frame.h>
50 #include <libavutil/opt.h>
51 #include <libavutil/imgutils.h>
52 #include <libavutil/parseutils.h>
53 #include <libavfilter/avfilter.h>
54 #include <libavfilter/buffersink.h>
55 #include <libavfilter/buffersrc.h>
60 namespace caspar { namespace ffmpeg {
62 int crc16(const std::string& str)
64 boost::crc_16_type result;
66 result.process_bytes(str.data(), str.length());
68 return result.checksum();
71 class streaming_consumer final : public core::frame_consumer
77 core::monitor::subject subject_;
78 boost::filesystem::path path_;
79 int consumer_index_offset_;
81 std::map<std::string, std::string> options_;
83 core::video_format_desc in_video_format_;
85 std::shared_ptr<AVFormatContext> oc_;
86 tbb::atomic<bool> abort_request_;
88 std::shared_ptr<AVStream> video_st_;
89 std::shared_ptr<AVStream> audio_st_;
91 std::int64_t video_pts_;
92 std::int64_t audio_pts_;
94 AVFilterContext* audio_graph_in_;
95 AVFilterContext* audio_graph_out_;
96 std::shared_ptr<AVFilterGraph> audio_graph_;
97 std::shared_ptr<AVBitStreamFilterContext> audio_bitstream_filter_;
99 AVFilterContext* video_graph_in_;
100 AVFilterContext* video_graph_out_;
101 std::shared_ptr<AVFilterGraph> video_graph_;
102 std::shared_ptr<AVBitStreamFilterContext> video_bitstream_filter_;
106 executor video_encoder_executor_;
107 executor audio_encoder_executor_;
109 tbb::atomic<int> tokens_;
110 boost::mutex tokens_mutex_;
111 boost::condition_variable tokens_cond_;
113 executor write_executor_;
121 , consumer_index_offset_(crc16(path))
125 , audio_encoder_executor_(print() + L" audio_encoder")
126 , video_encoder_executor_(print() + L" video_encoder")
127 , write_executor_(print() + L" io")
129 abort_request_ = false;
132 boost::sregex_iterator(
135 boost::regex("-(?<NAME>[^-\\s]+)(\\s+(?<VALUE>[^\\s]+))?"));
136 it != boost::sregex_iterator();
139 options_[(*it)["NAME"].str()] = (*it)["VALUE"].matched ? (*it)["VALUE"].str() : "";
142 if (options_.find("threads") == options_.end())
143 options_["threads"] = "auto";
150 boost::regex("tokens")).get_value_or(2));
153 ~streaming_consumer()
157 video_encoder_executor_.begin_invoke([&] { encode_video(core::const_frame::empty(), nullptr); });
158 audio_encoder_executor_.begin_invoke([&] { encode_audio(core::const_frame::empty(), nullptr); });
160 video_encoder_executor_.stop();
161 audio_encoder_executor_.stop();
162 video_encoder_executor_.join();
163 audio_encoder_executor_.join();
165 video_graph_.reset();
166 audio_graph_.reset();
170 write_packet(nullptr, nullptr);
172 write_executor_.stop();
173 write_executor_.join();
175 FF(av_write_trailer(oc_.get()));
177 if (!(oc_->oformat->flags & AVFMT_NOFILE) && oc_->pb)
185 const core::video_format_desc& format_desc,
186 int channel_index) override
190 static boost::regex prot_exp("^.+:.*" );
192 const auto overwrite =
193 try_remove_arg<std::string>(
195 boost::regex("y")) != nullptr;
197 if(!boost::regex_match(
201 if(!path_.is_complete())
205 env::media_folder()) +
209 if(boost::filesystem::exists(path_))
212 BOOST_THROW_EXCEPTION(invalid_argument() << msg_info("File exists"));
214 boost::filesystem::remove(path_);
218 const auto oformat_name =
219 try_remove_arg<std::string>(
221 boost::regex("^f|format$"));
225 FF(avformat_alloc_output_context2(
228 oformat_name && !oformat_name->empty() ? oformat_name->c_str() : nullptr,
229 path_.string().c_str()));
233 avformat_free_context);
235 CASPAR_VERIFY(oc_->oformat);
237 oc_->interrupt_callback.callback = streaming_consumer::interrupt_cb;
238 oc_->interrupt_callback.opaque = this;
240 CASPAR_VERIFY(format_desc.format != core::video_format::invalid);
242 in_video_format_ = format_desc;
244 CASPAR_VERIFY(oc_->oformat);
246 const auto video_codec_name =
247 try_remove_arg<std::string>(
249 boost::regex("^c:v|codec:v|vcodec$"));
251 const auto video_codec =
253 ? avcodec_find_encoder_by_name(video_codec_name->c_str())
254 : avcodec_find_encoder(oc_->oformat->video_codec);
256 const auto audio_codec_name =
257 try_remove_arg<std::string>(
259 boost::regex("^c:a|codec:a|acodec$"));
261 const auto audio_codec =
263 ? avcodec_find_encoder_by_name(audio_codec_name->c_str())
264 : avcodec_find_encoder(oc_->oformat->audio_codec);
267 BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(
268 "Failed to find video codec " + (video_codec_name
270 : "with id " + boost::lexical_cast<std::string>(
271 oc_->oformat->video_codec))));
273 BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(
274 "Failed to find audio codec " + (audio_codec_name
276 : "with id " + boost::lexical_cast<std::string>(
277 oc_->oformat->audio_codec))));
282 configure_video_filters(
284 try_remove_arg<std::string>(options_,
285 boost::regex("vf|f:v|filter:v")).get_value_or(""));
287 configure_audio_filters(
289 try_remove_arg<std::string>(options_,
290 boost::regex("af|f:a|filter:a")).get_value_or(""));
295 configue_audio_bistream_filters(options_);
296 configue_video_bistream_filters(options_);
302 auto video_options = options_;
303 auto audio_options = options_;
305 video_st_ = open_encoder(
309 audio_st_ = open_encoder(
313 auto it = options_.begin();
314 while(it != options_.end())
316 if(video_options.find(it->first) == video_options.end() || audio_options.find(it->first) == audio_options.end())
317 it = options_.erase(it);
325 AVDictionary* av_opts = nullptr;
329 std::move(options_));
333 av_dict_free(&av_opts);
336 if (!(oc_->oformat->flags & AVFMT_NOFILE))
340 path_.string().c_str(),
342 &oc_->interrupt_callback,
346 FF(avformat_write_header(
350 options_ = to_map(av_opts);
361 for (const auto& option : options_)
364 << L"Invalid option: -"
367 << u16(option.second);
379 core::monitor::subject& monitor_output() override
384 std::wstring name() const override
389 std::future<bool> send(core::const_frame frame) override
391 CASPAR_VERIFY(in_video_format_.format != core::video_format::invalid);
394 std::shared_ptr<void> token(
399 tokens_cond_.notify_one();
402 return executor_.begin_invoke([=]() -> bool
404 boost::unique_lock<boost::mutex> tokens_lock(tokens_mutex_);
407 tokens_cond_.wait(tokens_lock);
409 video_encoder_executor_.begin_invoke([=]() mutable
416 audio_encoder_executor_.begin_invoke([=]() mutable
427 std::wstring print() const override
429 return L"streaming_consumer[" + u16(path_.string()) + L"]";
432 virtual boost::property_tree::wptree info() const override
434 return boost::property_tree::wptree();
437 bool has_synchronization_clock() const override
442 int buffer_depth() const override
447 int index() const override
449 return 100000 + consumer_index_offset_;
454 static int interrupt_cb(void* ctx)
457 return reinterpret_cast<streaming_consumer*>(ctx)->abort_request_;
460 std::shared_ptr<AVStream> open_encoder(
461 const AVCodec& codec,
462 std::map<std::string,
463 std::string>& options)
471 BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Could not allocate video-stream.") << boost::errinfo_api_function("av_new_stream"));
473 auto enc = st->codec;
477 switch(enc->codec_type)
479 case AVMEDIA_TYPE_VIDEO:
481 enc->time_base = video_graph_out_->inputs[0]->time_base;
482 enc->pix_fmt = static_cast<AVPixelFormat>(video_graph_out_->inputs[0]->format);
483 enc->sample_aspect_ratio = st->sample_aspect_ratio = video_graph_out_->inputs[0]->sample_aspect_ratio;
484 enc->width = video_graph_out_->inputs[0]->w;
485 enc->height = video_graph_out_->inputs[0]->h;
489 case AVMEDIA_TYPE_AUDIO:
491 enc->time_base = audio_graph_out_->inputs[0]->time_base;
492 enc->sample_fmt = static_cast<AVSampleFormat>(audio_graph_out_->inputs[0]->format);
493 enc->sample_rate = audio_graph_out_->inputs[0]->sample_rate;
494 enc->channel_layout = audio_graph_out_->inputs[0]->channel_layout;
495 enc->channels = audio_graph_out_->inputs[0]->channels;
501 if(oc_->oformat->flags & AVFMT_GLOBALHEADER)
502 enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
504 static const std::array<std::string, 4> char_id_map = {{"v", "a", "d", "s"}};
506 const auto char_id = char_id_map.at(enc->codec_type);
508 const auto codec_opts =
511 boost::regex("^(" + char_id + "?[^:]+):" + char_id + "$"));
513 AVDictionary* av_codec_opts = nullptr;
528 av_codec_opts ? &av_codec_opts : nullptr));
537 AV_DICT_IGNORE_SUFFIX);
541 options[t->key + (codec_opts.find(t->key) != codec_opts.end() ? ":" + char_id : "")] = t->value;
547 AV_DICT_IGNORE_SUFFIX);
550 av_dict_free(&av_codec_opts);
553 if(enc->codec_type == AVMEDIA_TYPE_AUDIO && !(codec.capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE))
555 CASPAR_ASSERT(enc->frame_size > 0);
556 av_buffersink_set_frame_size(audio_graph_out_,
560 return std::shared_ptr<AVStream>(st, [this](AVStream* st)
562 avcodec_close(st->codec);
566 void configue_audio_bistream_filters(
567 std::map<std::string, std::string>& options)
569 const auto audio_bitstream_filter_str =
570 try_remove_arg<std::string>(
572 boost::regex("^bsf:a|absf$"));
574 const auto audio_bitstream_filter =
575 audio_bitstream_filter_str
576 ? av_bitstream_filter_init(audio_bitstream_filter_str->c_str())
579 CASPAR_VERIFY(!audio_bitstream_filter_str || audio_bitstream_filter);
581 if(audio_bitstream_filter)
583 audio_bitstream_filter_.reset(
584 audio_bitstream_filter,
585 av_bitstream_filter_close);
588 if(audio_bitstream_filter_str && !audio_bitstream_filter_)
589 options["bsf:a"] = *audio_bitstream_filter_str;
592 void configue_video_bistream_filters(
593 std::map<std::string, std::string>& options)
595 const auto video_bitstream_filter_str =
596 try_remove_arg<std::string>(
598 boost::regex("^bsf:v|vbsf$"));
600 const auto video_bitstream_filter =
601 video_bitstream_filter_str
602 ? av_bitstream_filter_init(video_bitstream_filter_str->c_str())
605 CASPAR_VERIFY(!video_bitstream_filter_str || video_bitstream_filter);
607 if(video_bitstream_filter)
609 video_bitstream_filter_.reset(
610 video_bitstream_filter,
611 av_bitstream_filter_close);
614 if(video_bitstream_filter_str && !video_bitstream_filter_)
615 options["bsf:v"] = *video_bitstream_filter_str;
618 void configure_video_filters(
619 const AVCodec& codec,
620 const std::string& filtergraph)
623 avfilter_graph_alloc(),
626 avfilter_graph_free(&p);
629 video_graph_->nb_threads = boost::thread::hardware_concurrency()/2;
630 video_graph_->thread_type = AVFILTER_THREAD_SLICE;
632 const auto sample_aspect_ratio =
633 boost::rational<int>(
634 in_video_format_.square_width,
635 in_video_format_.square_height) /
636 boost::rational<int>(
637 in_video_format_.width,
638 in_video_format_.height);
640 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%")
641 % in_video_format_.width % in_video_format_.height
643 % in_video_format_.duration % in_video_format_.time_scale
644 % sample_aspect_ratio.numerator() % sample_aspect_ratio.denominator()
645 % in_video_format_.time_scale % in_video_format_.duration).str();
647 AVFilterContext* filt_vsrc = nullptr;
648 FF(avfilter_graph_create_filter(
650 avfilter_get_by_name("buffer"),
651 "ffmpeg_consumer_buffer",
652 vsrc_options.c_str(),
654 video_graph_.get()));
656 AVFilterContext* filt_vsink = nullptr;
657 FF(avfilter_graph_create_filter(
659 avfilter_get_by_name("buffersink"),
660 "ffmpeg_consumer_buffersink",
663 video_graph_.get()));
665 #pragma warning (push)
666 #pragma warning (disable : 4245)
668 FF(av_opt_set_int_list(
673 AV_OPT_SEARCH_CHILDREN));
675 #pragma warning (pop)
677 configure_filtergraph(
683 video_graph_in_ = filt_vsrc;
684 video_graph_out_ = filt_vsink;
687 << u16(std::string("\n")
688 + avfilter_graph_dump(
693 void configure_audio_filters(
694 const AVCodec& codec,
695 const std::string& filtergraph)
698 avfilter_graph_alloc(),
701 avfilter_graph_free(&p);
704 audio_graph_->nb_threads = boost::thread::hardware_concurrency()/2;
705 audio_graph_->thread_type = AVFILTER_THREAD_SLICE;
707 const auto asrc_options = (boost::format("sample_rate=%1%:sample_fmt=%2%:channels=%3%:time_base=%4%/%5%:channel_layout=%6%")
708 % in_video_format_.audio_sample_rate
709 % av_get_sample_fmt_name(AV_SAMPLE_FMT_S32)
710 % in_video_format_.audio_channels
711 % 1 % in_video_format_.audio_sample_rate
715 av_get_default_channel_layout(in_video_format_.audio_channels))).str();
717 AVFilterContext* filt_asrc = nullptr;
718 FF(avfilter_graph_create_filter(
720 avfilter_get_by_name("abuffer"),
721 "ffmpeg_consumer_abuffer",
722 asrc_options.c_str(),
724 audio_graph_.get()));
726 AVFilterContext* filt_asink = nullptr;
727 FF(avfilter_graph_create_filter(
729 avfilter_get_by_name("abuffersink"),
730 "ffmpeg_consumer_abuffersink",
733 audio_graph_.get()));
735 #pragma warning (push)
736 #pragma warning (disable : 4245)
740 "all_channel_counts",
742 AV_OPT_SEARCH_CHILDREN));
744 FF(av_opt_set_int_list(
749 AV_OPT_SEARCH_CHILDREN));
751 FF(av_opt_set_int_list(
754 codec.channel_layouts,
756 AV_OPT_SEARCH_CHILDREN));
758 FF(av_opt_set_int_list(
761 codec.supported_samplerates,
763 AV_OPT_SEARCH_CHILDREN));
765 #pragma warning (pop)
767 configure_filtergraph(
773 audio_graph_in_ = filt_asrc;
774 audio_graph_out_ = filt_asink;
777 << u16(std::string("\n")
778 + avfilter_graph_dump(
783 void configure_filtergraph(
784 AVFilterGraph& graph,
785 const std::string& filtergraph,
786 AVFilterContext& source_ctx,
787 AVFilterContext& sink_ctx)
789 AVFilterInOut* outputs = nullptr;
790 AVFilterInOut* inputs = nullptr;
794 if(!filtergraph.empty())
796 outputs = avfilter_inout_alloc();
797 inputs = avfilter_inout_alloc();
799 CASPAR_VERIFY(outputs && inputs);
801 outputs->name = av_strdup("in");
802 outputs->filter_ctx = &source_ctx;
803 outputs->pad_idx = 0;
804 outputs->next = nullptr;
806 inputs->name = av_strdup("out");
807 inputs->filter_ctx = &sink_ctx;
809 inputs->next = nullptr;
811 FF(avfilter_graph_parse(
827 FF(avfilter_graph_config(
833 avfilter_inout_free(&outputs);
834 avfilter_inout_free(&inputs);
839 void encode_video(core::const_frame frame_ptr, std::shared_ptr<void> token)
844 auto enc = video_st_->codec;
846 std::shared_ptr<AVFrame> src_av_frame;
848 if(frame_ptr != core::const_frame::empty())
852 [frame_ptr](AVFrame* frame)
854 av_frame_free(&frame);
857 avcodec_get_frame_defaults(src_av_frame.get());
859 const auto sample_aspect_ratio =
860 boost::rational<int>(
861 in_video_format_.square_width,
862 in_video_format_.square_height) /
863 boost::rational<int>(
864 in_video_format_.width,
865 in_video_format_.height);
867 src_av_frame->format = AV_PIX_FMT_BGRA;
868 src_av_frame->width = in_video_format_.width;
869 src_av_frame->height = in_video_format_.height;
870 src_av_frame->sample_aspect_ratio.num = sample_aspect_ratio.numerator();
871 src_av_frame->sample_aspect_ratio.den = sample_aspect_ratio.denominator();
872 src_av_frame->pts = video_pts_;
876 FF(av_image_fill_arrays(
878 src_av_frame->linesize,
879 frame_ptr.image_data().begin(),
880 static_cast<AVPixelFormat>(src_av_frame->format),
881 in_video_format_.width,
882 in_video_format_.height,
885 FF(av_buffersrc_add_frame(
887 src_av_frame.get()));
894 std::shared_ptr<AVFrame> filt_frame(
901 ret = av_buffersink_get_frame(
905 video_encoder_executor_.begin_invoke([=]
907 if(ret == AVERROR_EOF)
909 if(enc->codec->capabilities & CODEC_CAP_DELAY)
911 while(encode_av_frame(
913 video_bitstream_filter_.get(),
914 avcodec_encode_video2,
917 boost::this_thread::yield(); // TODO:
921 else if(ret != AVERROR(EAGAIN))
923 FF_RET(ret, "av_buffersink_get_frame");
925 if (filt_frame->interlaced_frame)
927 if (enc->codec->id == AV_CODEC_ID_MJPEG)
928 enc->field_order = filt_frame->top_field_first ? AV_FIELD_TT : AV_FIELD_BB;
930 enc->field_order = filt_frame->top_field_first ? AV_FIELD_TB : AV_FIELD_BT;
933 enc->field_order = AV_FIELD_PROGRESSIVE;
935 filt_frame->quality = enc->global_quality;
937 if (!enc->me_threshold)
938 filt_frame->pict_type = AV_PICTURE_TYPE_NONE;
942 video_bitstream_filter_.get(),
943 avcodec_encode_video2,
947 boost::this_thread::yield(); // TODO:
953 void encode_audio(core::const_frame frame_ptr, std::shared_ptr<void> token)
958 auto enc = audio_st_->codec;
960 std::shared_ptr<AVFrame> src_av_frame;
962 if(frame_ptr != core::const_frame::empty())
971 src_av_frame->channels = in_video_format_.audio_channels;
972 src_av_frame->channel_layout = av_get_default_channel_layout(in_video_format_.audio_channels);
973 src_av_frame->sample_rate = in_video_format_.audio_sample_rate;
974 src_av_frame->nb_samples = static_cast<int>(frame_ptr.audio_data().size()) / src_av_frame->channels;
975 src_av_frame->format = AV_SAMPLE_FMT_S32;
976 src_av_frame->pts = audio_pts_;
978 audio_pts_ += src_av_frame->nb_samples;
980 FF(av_samples_fill_arrays(
981 src_av_frame->extended_data,
982 src_av_frame->linesize,
983 reinterpret_cast<const std::uint8_t*>(&*frame_ptr.audio_data().begin()),
984 src_av_frame->channels,
985 src_av_frame->nb_samples,
986 static_cast<AVSampleFormat>(src_av_frame->format),
989 FF(av_buffersrc_add_frame(
991 src_av_frame.get()));
998 std::shared_ptr<AVFrame> filt_frame(
1005 ret = av_buffersink_get_frame(
1009 audio_encoder_executor_.begin_invoke([=]
1011 if(ret == AVERROR_EOF)
1013 if(enc->codec->capabilities & CODEC_CAP_DELAY)
1015 while(encode_av_frame(
1017 audio_bitstream_filter_.get(),
1018 avcodec_encode_audio2,
1022 boost::this_thread::yield(); // TODO:
1026 else if(ret != AVERROR(EAGAIN))
1030 "av_buffersink_get_frame");
1034 audio_bitstream_filter_.get(),
1035 avcodec_encode_audio2,
1039 boost::this_thread::yield(); // TODO:
1045 template<typename F>
1046 bool encode_av_frame(
1048 AVBitStreamFilterContext* bsfc,
1050 const std::shared_ptr<AVFrame>& src_av_frame,
1051 std::shared_ptr<void> token)
1054 av_init_packet(&pkt);
1064 if(!got_packet || pkt.size <= 0)
1067 pkt.stream_index = st.index;
1073 auto a = av_bitstream_filter_filter(
1081 pkt.flags & AV_PKT_FLAG_KEY);
1083 if(a == 0 && new_pkt.data != pkt.data && new_pkt.destruct)
1085 auto t = reinterpret_cast<std::uint8_t*>(av_malloc(new_pkt.size + FF_INPUT_BUFFER_PADDING_SIZE));
1097 FF_INPUT_BUFFER_PADDING_SIZE);
1100 new_pkt.buf = nullptr;
1103 a = AVERROR(ENOMEM);
1106 av_free_packet(&pkt);
1110 "av_bitstream_filter_filter");
1116 av_buffer_default_free,
1120 CASPAR_VERIFY(new_pkt.buf);
1125 if (pkt.pts != AV_NOPTS_VALUE)
1130 st.codec->time_base,
1134 if (pkt.dts != AV_NOPTS_VALUE)
1139 st.codec->time_base,
1147 st.codec->time_base, st.time_base));
1150 std::shared_ptr<AVPacket>(
1162 const std::shared_ptr<AVPacket>& pkt_ptr,
1163 std::shared_ptr<void> token)
1165 write_executor_.begin_invoke([this, pkt_ptr, token]() mutable
1167 FF(av_interleaved_write_frame(
1173 template<typename T>
1174 static boost::optional<T> try_remove_arg(
1175 std::map<std::string, std::string>& options,
1176 const boost::regex& expr)
1178 for(auto it = options.begin(); it != options.end(); ++it)
1180 if(boost::regex_search(it->first, expr))
1182 auto arg = it->second;
1184 return boost::lexical_cast<T>(arg);
1188 return boost::optional<T>();
1191 static std::map<std::string, std::string> remove_options(
1192 std::map<std::string, std::string>& options,
1193 const boost::regex& expr)
1195 std::map<std::string, std::string> result;
1197 auto it = options.begin();
1198 while(it != options.end())
1201 if(boost::regex_search(it->first, what, expr))
1204 what.size() > 0 && what[1].matched
1206 : it->first] = it->second;
1207 it = options.erase(it);
1216 static void to_dict(AVDictionary** dest, const std::map<std::string, std::string>& c)
1218 for (const auto& entry : c)
1222 entry.first.c_str(),
1223 entry.second.c_str(), 0);
1227 static std::map<std::string, std::string> to_map(AVDictionary* dict)
1229 std::map<std::string, std::string> result;
1236 AV_DICT_IGNORE_SUFFIX)
1243 AV_DICT_IGNORE_SUFFIX))
1245 result[t->key] = t->value;
1252 spl::shared_ptr<core::frame_consumer> create_streaming_consumer(
1253 const std::vector<std::wstring>& params, core::interaction_sink*)
1255 if (params.size() < 1 || params.at(0) != L"STREAM")
1256 return core::frame_consumer::empty();
1258 auto path = u8(params.at(1));
1259 auto args = u8(boost::join(params, L" "));
1261 return spl::make_shared<streaming_consumer>(path, args);
1264 spl::shared_ptr<core::frame_consumer> create_preconfigured_streaming_consumer(
1265 const boost::property_tree::wptree& ptree, core::interaction_sink*)
1267 return spl::make_shared<streaming_consumer>(
1268 u8(ptree.get<std::wstring>(L"path")),
1269 u8(ptree.get<std::wstring>(L"args", L"")));