]> git.sesse.net Git - casparcg/commitdiff
[scene] Fixed wrong framerate of nested content when channel is interlaced.
authorHelge Norberg <helge.norberg@svt.se>
Wed, 8 Mar 2017 19:02:27 +0000 (20:02 +0100)
committerHelge Norberg <helge.norberg@svt.se>
Wed, 8 Mar 2017 19:02:27 +0000 (20:02 +0100)
core/producer/scene/xml_scene_producer.cpp
core/video_format.cpp
core/video_format.h
modules/ffmpeg/producer/util/util.cpp
modules/psd/psd_scene_producer.cpp

index 351c24c01cda5fa03a640af490f6c9e38dce64a2..5e5231ba6aceb551e5cc84b04830ccc48b0ee7e6 100644 (file)
@@ -141,8 +141,10 @@ spl::shared_ptr<core::frame_producer> create_xml_scene_producer(
 
                        adjusted_format_desc.field_mode          = field_mode::progressive;
                        adjusted_format_desc.fps                        *= adjusted_format_desc.field_count;
-                       adjusted_format_desc.duration           /= adjusted_format_desc.field_count;
+                       adjusted_format_desc.time_scale         *= adjusted_format_desc.field_count;
+                       adjusted_format_desc.framerate          *= adjusted_format_desc.field_count;
                        adjusted_format_desc.field_count         = 1;
+                       adjusted_format_desc.audio_cadence       = core::find_audio_cadence(adjusted_format_desc.framerate);
 
                        return dependencies.producer_registry->create_producer(adjusted_dependencies, producer_string);
                }();
index bea44730618902287a47c45dce77c0992b68d618..4cb31290296580b938cd266a2effee4d88e47776 100644 (file)
@@ -137,5 +137,53 @@ std::wostream& operator<<(std::wostream& out, const video_format_desc& format_de
        return out;
 }
 
+std::vector<int> find_audio_cadence(const boost::rational<int>& framerate, bool log_quiet)
+{
+       static std::map<boost::rational<int>, std::vector<int>> CADENCES_BY_FRAMERATE = []
+       {
+               std::map<boost::rational<int>, std::vector<int>> result;
+
+               for (core::video_format format : enum_constants<core::video_format>())
+               {
+                       core::video_format_desc desc(format);
+                       boost::rational<int> format_rate(desc.time_scale, desc.duration);
+
+                       result.insert(std::make_pair(format_rate, desc.audio_cadence));
+               }
+
+               return result;
+       }();
+
+       auto exact_match = CADENCES_BY_FRAMERATE.find(framerate);
+
+       if (exact_match != CADENCES_BY_FRAMERATE.end())
+               return exact_match->second;
+
+       boost::rational<int> closest_framerate_diff     = std::numeric_limits<int>::max();
+       boost::rational<int> closest_framerate          = 0;
+
+       for (auto format_framerate : CADENCES_BY_FRAMERATE | boost::adaptors::map_keys)
+       {
+               auto diff = boost::abs(framerate - format_framerate);
+
+               if (diff < closest_framerate_diff)
+               {
+                       closest_framerate_diff = diff;
+                       closest_framerate = format_framerate;
+               }
+       }
+
+       if (log_quiet)
+               CASPAR_LOG(debug) << "No exact audio cadence match found for framerate " << to_string(framerate)
+                       << "\nClosest match is " << to_string(closest_framerate)
+                       << "\nwhich is a " << to_string(closest_framerate_diff) << " difference.";
+       else
+               CASPAR_LOG(warning) << "No exact audio cadence match found for framerate " << to_string(framerate)
+                       << "\nClosest match is " << to_string(closest_framerate)
+                       << "\nwhich is a " << to_string(closest_framerate_diff) << " difference.";
+
+       return CADENCES_BY_FRAMERATE[closest_framerate];
+}
+
 
 }}
index 42777242697bb07d528fceedabcf183acc939da1..44238b7bd66d3f5a160cb998abcd93a6a984fb06 100644 (file)
 #include <boost/rational.hpp>
 
 namespace caspar { namespace core {
-       
+
 enum class video_format
-{ 
-       pal,            
-       ntsc,           
-       x576p2500,      
-       x720p2500,      
+{
+       pal,
+       ntsc,
+       x576p2500,
+       x720p2500,
        x720p5000,
        x720p2398,
        x720p2400,
@@ -45,13 +45,13 @@ enum class video_format
        x720p3000,
        x720p6000,
        x1080p2398,
-       x1080p2400,     
-       x1080i5000,     
-       x1080i5994,     
-       x1080i6000,     
-       x1080p2500,     
-       x1080p2997,     
-       x1080p3000,     
+       x1080p2400,
+       x1080i5000,
+       x1080i5994,
+       x1080i6000,
+       x1080p2500,
+       x1080p2997,
+       x1080p3000,
        x1080p5000,
        x1080p5994,
        x1080p6000,
@@ -88,10 +88,10 @@ ENUM_ENABLE_BITWISE(field_mode);
 
 struct video_format_desc final
 {
-       video_format                    format;         
+       video_format                    format;
 
-       int                                             width;          
-       int                                             height;         
+       int                                             width;
+       int                                             height;
        int                                             square_width;
        int                                             square_height;
        core::field_mode                field_mode;     // progressive, interlaced upper field first, interlaced lower field first
@@ -100,7 +100,7 @@ struct video_format_desc final
        int                                             time_scale;
        int                                             duration;
        int                                             field_count;
-       std::size_t                             size;           // frame size in bytes 
+       std::size_t                             size;           // frame size in bytes
        std::wstring                    name;           // name of output format
 
        int                                             audio_sample_rate;
@@ -116,7 +116,7 @@ struct video_format_desc final
                                          int duration,
                                          const std::wstring& name,
                                          const std::vector<int>& audio_cadence);
-               
+
        video_format_desc(video_format format = video_format::invalid);
        video_format_desc(const std::wstring& name);
 };
@@ -126,4 +126,6 @@ bool operator!=(const video_format_desc& rhs, const video_format_desc& lhs);
 
 std::wostream& operator<<(std::wostream& out, const video_format_desc& format_desc);
 
+std::vector<int> find_audio_cadence(const boost::rational<int>& framerate, bool log_quiet = false);
+
 }}
index 6ed51aa1c8797beb7469dcc3b159871636b52fda..b573283c9c9e6b05edec7d014af50b9a3e0b5f05 100644 (file)
@@ -795,50 +795,7 @@ std::string to_string(const boost::rational<int>& framerate)
 
 std::vector<int> find_audio_cadence(const boost::rational<int>& framerate)
 {
-       static std::map<boost::rational<int>, std::vector<int>> CADENCES_BY_FRAMERATE = []
-       {
-               std::map<boost::rational<int>, std::vector<int>> result;
-
-               for (core::video_format format : enum_constants<core::video_format>())
-               {
-                       core::video_format_desc desc(format);
-                       boost::rational<int> format_rate(desc.time_scale, desc.duration);
-
-                       result.insert(std::make_pair(format_rate, desc.audio_cadence));
-               }
-
-               return result;
-       }();
-
-       auto exact_match = CADENCES_BY_FRAMERATE.find(framerate);
-
-       if (exact_match != CADENCES_BY_FRAMERATE.end())
-               return exact_match->second;
-
-       boost::rational<int> closest_framerate_diff = std::numeric_limits<int>::max();
-       boost::rational<int> closest_framerate = 0;
-
-       for (auto format_framerate : CADENCES_BY_FRAMERATE | boost::adaptors::map_keys)
-       {
-               auto diff = boost::abs(framerate - format_framerate);
-
-               if (diff < closest_framerate_diff)
-               {
-                       closest_framerate_diff = diff;
-                       closest_framerate = format_framerate;
-               }
-       }
-
-       if (is_logging_quiet_for_thread())
-               CASPAR_LOG(debug) << "No exact audio cadence match found for framerate " << to_string(framerate)
-               << "\nClosest match is " << to_string(closest_framerate)
-               << "\nwhich is a " << to_string(closest_framerate_diff) << " difference.";
-       else
-               CASPAR_LOG(warning) << "No exact audio cadence match found for framerate " << to_string(framerate)
-               << "\nClosest match is " << to_string(closest_framerate)
-               << "\nwhich is a " << to_string(closest_framerate_diff) << " difference.";
-
-       return CADENCES_BY_FRAMERATE[closest_framerate];
+       return core::find_audio_cadence(framerate, is_logging_quiet_for_thread());
 }
 
 //
index d0c40b2df9c3dc949fc29089782d2111dc54f59d..34492161e4781a22038b97432343b6cd64caba82 100644 (file)
@@ -396,7 +396,7 @@ spl::shared_ptr<core::frame_producer> create_psd_scene_producer(const core::fram
                                                                                                                                                                                                                                                                        dependencies.format_desc.time_scale*2,
                                                                                                                                                                                                                                                                        dependencies.format_desc.duration,
                                                                                                                                                                                                                                                                        dependencies.format_desc.name,
-                                                                                                                                                                                                                                                                       dependencies.format_desc.audio_cadence };
+                                                                                                                                                                                                                                                                       core::find_audio_cadence(dependencies.format_desc.framerate * 2) };
 
                        auto group = spl::make_shared<core::scene::scene_producer>(psd_layer->name(), L"layer group in " + params.at(0), doc.width(), doc.height(), format_desc);