]> git.sesse.net Git - casparcg/commitdiff
[ffmpeg_consumer] #513 Fixed parsing of -pix_fmt in consumer
authorHelge Norberg <helge.norberg@svt.se>
Tue, 28 Mar 2017 09:44:41 +0000 (11:44 +0200)
committerHelge Norberg <helge.norberg@svt.se>
Tue, 28 Mar 2017 09:44:41 +0000 (11:44 +0200)
CHANGELOG
modules/ffmpeg/consumer/ffmpeg_consumer.cpp

index 249e936d043042cd486ddce5d807c0037f701d7f..c90fce6e9f23a1fea187523cd65bc3139fc70fc6 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -41,6 +41,8 @@ Consumers
       BT.601 color matrix instead of the BT.709 color matrix. RGB codecs like\r
       qtrle was never affected but all the YCbCr based codecs were.\r
     + Fixed bug in parsing of paths containing -.\r
+    + Fixed bugs where previously effective arguments like -pix_fmt were\r
+      ignored.\r
   o DeckLink consumer:\r
     + Rewrote the frame hand-off between send() and ScheduledFrameCompleted() in\r
       a way that hopefully resolves all dead-lock scenarios previously possible.\r
index 188fa418878652b424ef1b324ae24d80e87943ec..b0c3460e659cba4a3c0f66630810e6e6a4ca1a35 100644 (file)
@@ -381,8 +381,9 @@ public:
                        {
                                configure_video_filters(
                                        *video_codec,
-                                       try_remove_arg<std::string>(options_,
-                                       boost::regex("vf|f:v|filter:v")).get_value_or(""));
+                                       try_remove_arg<std::string>(options_, boost::regex("vf|f:v|filter:v"))
+                                                       .get_value_or(""),
+                                       try_remove_arg<std::string>(options_, boost::regex("pix_fmt")));
 
                                configure_audio_filters(
                                        *audio_codec,
@@ -650,7 +651,8 @@ private:
 
        void configure_video_filters(
                        const AVCodec& codec,
-                       std::string filtergraph)
+                       std::string filtergraph,
+                       const boost::optional<std::string>& preferred_pix_fmt)
        {
                video_graph_.reset(
                                avfilter_graph_alloc(),
@@ -698,12 +700,33 @@ private:
 #pragma warning (push)
 #pragma warning (disable : 4245)
 
-               FF(av_opt_set_int_list(
+               if (preferred_pix_fmt)
+               {
+                       auto requested_fmt = av_get_pix_fmt(preferred_pix_fmt->c_str());
+                       auto valid_fmts = from_terminated_array<AVPixelFormat>(codec.pix_fmts, AVPixelFormat::AV_PIX_FMT_NONE);
+
+                       if (!cpplinq::from(valid_fmts).contains(requested_fmt))
+                               CASPAR_THROW_EXCEPTION(user_error() << msg_info(*preferred_pix_fmt + " is not supported by codec."));
+
+                       std::vector<AVPixelFormat> fmts = { requested_fmt, AVPixelFormat::AV_PIX_FMT_NONE };
+
+                       FF(av_opt_set_int_list(
+                               filt_vsink,
+                               "pix_fmts",
+                               fmts.data(),
+                               -1,
+                               AV_OPT_SEARCH_CHILDREN));
+               }
+               else
+               {
+                       FF(av_opt_set_int_list(
                                filt_vsink,
                                "pix_fmts",
                                codec.pix_fmts,
                                -1,
                                AV_OPT_SEARCH_CHILDREN));
+               }
+
 
 #pragma warning (pop)