]> git.sesse.net Git - casparcg/blobdiff - modules/ffmpeg/producer/util/util.cpp
[ffmpeg] Ported 2.0.7 ffmpeg producer to 2.1.0 while still keeping the usage of the...
[casparcg] / modules / ffmpeg / producer / util / util.cpp
index 8c5e955705aaa3ca99d75f27bcbdec48a52673b7..d57b9b60da5a4aa60568587daebad2d1da780ef4 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "../tbb_avcodec.h"
 #include "../../ffmpeg_error.h"
+#include "../../ffmpeg.h"
 
 #include <tbb/concurrent_unordered_map.h>
 #include <tbb/concurrent_queue.h>
 #include <core/frame/frame_transform.h>
 #include <core/frame/frame_factory.h>
 #include <core/frame/frame.h>
+#include <core/frame/audio_channel_layout.h>
 #include <core/producer/frame_producer.h>
 
 #include <common/except.h>
 #include <common/array.h>
 #include <common/os/filesystem.h>
+#include <common/memcpy.h>
 
 #include <tbb/parallel_for.h>
 
@@ -147,12 +150,12 @@ core::pixel_format_desc pixel_format_desc(PixelFormat pix_fmt, int width, int he
        }
 }
 
-core::mutable_frame make_frame(const void* tag, const spl::shared_ptr<AVFrame>& decoded_frame, double fps, core::frame_factory& frame_factory)
+core::mutable_frame make_frame(const void* tag, const spl::shared_ptr<AVFrame>& decoded_frame, core::frame_factory& frame_factory, const core::audio_channel_layout& channel_layout)
 {                      
        static tbb::concurrent_unordered_map<int64_t, tbb::concurrent_queue<std::shared_ptr<SwsContext>>> sws_contvalid_exts_;
        
        if(decoded_frame->width < 1 || decoded_frame->height < 1)
-               return frame_factory.create_frame(tag, core::pixel_format_desc(core::pixel_format::invalid));
+               return frame_factory.create_frame(tag, core::pixel_format_desc(core::pixel_format::invalid), core::audio_channel_layout::invalid());
 
        const auto width  = decoded_frame->width;
        const auto height = decoded_frame->height;
@@ -178,7 +181,7 @@ core::mutable_frame make_frame(const void* tag, const spl::shared_ptr<AVFrame>&
                
                auto target_desc = pixel_format_desc(target_pix_fmt, width, height);
 
-               auto write = frame_factory.create_frame(tag, target_desc);
+               auto write = frame_factory.create_frame(tag, target_desc, channel_layout);
 
                std::shared_ptr<SwsContext> sws_context;
 
@@ -203,8 +206,7 @@ core::mutable_frame make_frame(const void* tag, const spl::shared_ptr<AVFrame>&
                                                                        boost::errinfo_api_function("sws_getContext"));
                }       
                
-               spl::shared_ptr<AVFrame> av_frame(avcodec_alloc_frame(), av_free);      
-               avcodec_get_frame_defaults(av_frame.get());                     
+               auto av_frame = create_frame();
                if(target_pix_fmt == PIX_FMT_BGRA)
                {
                        auto size = avpicture_fill(reinterpret_cast<AVPicture*>(av_frame.get()), write.image_data(0).begin(), PIX_FMT_BGRA, width, height);
@@ -228,7 +230,7 @@ core::mutable_frame make_frame(const void* tag, const spl::shared_ptr<AVFrame>&
        }
        else
        {
-               auto write = frame_factory.create_frame(tag, desc);
+               auto write = frame_factory.create_frame(tag, desc, channel_layout);
                
                for(int n = 0; n < static_cast<int>(desc.planes.size()); ++n)
                {
@@ -240,13 +242,20 @@ core::mutable_frame make_frame(const void* tag, const spl::shared_ptr<AVFrame>&
                        CASPAR_ASSERT(decoded);
                        CASPAR_ASSERT(write.image_data(n).begin());
 
-                       // Copy line by line since ffmpeg sometimes pads each line.
-                       tbb::affinity_partitioner ap;
-                       tbb::parallel_for(tbb::blocked_range<int>(0, desc.planes[n].height), [&](const tbb::blocked_range<int>& r)
+                       if (decoded_linesize != plane.linesize)
                        {
-                               for(int y = r.begin(); y != r.end(); ++y)
-                                       A_memcpy(result + y*plane.linesize, decoded + y*decoded_linesize, plane.linesize);
-                       }, ap);
+                               // Copy line by line since ffmpeg sometimes pads each line.
+                               tbb::affinity_partitioner ap;
+                               tbb::parallel_for(tbb::blocked_range<int>(0, desc.planes[n].height), [&](const tbb::blocked_range<int>& r)
+                               {
+                                       for (int y = r.begin(); y != r.end(); ++y)
+                                               A_memcpy(result + y*plane.linesize, decoded + y*decoded_linesize, plane.linesize);
+                               }, ap);
+                       }
+                       else
+                       {
+                               fast_memcpy(result, decoded, plane.size);
+                       }
                }
        
                return std::move(write);
@@ -264,8 +273,7 @@ spl::shared_ptr<AVFrame> make_av_frame(core::mutable_frame& frame)
 
 spl::shared_ptr<AVFrame> make_av_frame(std::array<uint8_t*, 4> data, const core::pixel_format_desc& pix_desc)
 {
-       spl::shared_ptr<AVFrame> av_frame(avcodec_alloc_frame(), av_free);      
-       avcodec_get_frame_defaults(av_frame.get());
+       auto av_frame = create_frame();
        
        auto planes              = pix_desc.planes;
        auto format              = pix_desc.format;
@@ -351,69 +359,83 @@ AVRational fix_time_base(AVRational time_base)
 }
 
 double read_fps(AVFormatContext& context, double fail_value)
-{                                              
+{
+       auto framerate = read_framerate(context, boost::rational<int>(static_cast<int>(fail_value * 1000000.0), 1000000));
+       
+       return static_cast<double>(framerate.numerator()) / static_cast<double>(framerate.denominator());
+}
+
+boost::rational<int> read_framerate(AVFormatContext& context, const boost::rational<int>& fail_value)
+{
        auto video_index = av_find_best_stream(&context, AVMEDIA_TYPE_VIDEO, -1, -1, 0, 0);
        auto audio_index = av_find_best_stream(&context, AVMEDIA_TYPE_AUDIO, -1, -1, 0, 0);
-       
-       if(video_index > -1)
+
+       if (video_index > -1)
        {
                const auto video_context = context.streams[video_index]->codec;
-               const auto video_stream  = context.streams[video_index];
-                                               
+               const auto video_stream = context.streams[video_index];
+
+               auto frame_rate_time_base = video_stream->avg_frame_rate;
+               std::swap(frame_rate_time_base.num, frame_rate_time_base.den);
+
+               if (is_sane_fps(frame_rate_time_base))
+               {
+                       return boost::rational<int>(frame_rate_time_base.den, frame_rate_time_base.num);
+               }
+
                AVRational time_base = video_context->time_base;
 
-               if(boost::filesystem::path(context.filename).extension().string() == ".flv")
+               if (boost::filesystem::path(context.filename).extension().string() == ".flv")
                {
                        try
                        {
                                auto meta = read_flv_meta_info(context.filename);
-                               return boost::lexical_cast<double>(meta["framerate"]);
+                               return boost::rational<int>(static_cast<int>(boost::lexical_cast<double>(meta["framerate"]) * 1000000.0), 1000000);
                        }
-                       catch(...)
+                       catch (...)
                        {
-                               return 0.0;
+                               return fail_value;
                        }
                }
                else
                {
                        time_base.num *= video_context->ticks_per_frame;
 
-                       if(!is_sane_fps(time_base))
-                       {                       
+                       if (!is_sane_fps(time_base))
+                       {
                                time_base = fix_time_base(time_base);
 
-                               if(!is_sane_fps(time_base) && audio_index > -1)
+                               if (!is_sane_fps(time_base) && audio_index > -1)
                                {
                                        auto& audio_context = *context.streams[audio_index]->codec;
-                                       auto& audio_stream  = *context.streams[audio_index];
+                                       auto& audio_stream = *context.streams[audio_index];
 
                                        double duration_sec = audio_stream.duration / static_cast<double>(audio_context.sample_rate);
-                                                               
+
                                        time_base.num = static_cast<int>(duration_sec*100000.0);
-                                       time_base.den = static_cast<int>(video_stream->nb_frames*100000);
+                                       time_base.den = static_cast<int>(video_stream->nb_frames * 100000);
                                }
                        }
                }
-               
-               double fps = static_cast<double>(time_base.den) / static_cast<double>(time_base.num);
 
-               double closest_fps = 0.0;
+               boost::rational<int> fps(time_base.den, time_base.num);
+               boost::rational<int> closest_fps(0);
 
                for (auto video_mode : enum_constants<core::video_format>())
                {
                        auto format = core::video_format_desc(core::video_format(video_mode));
 
-                       double diff1 = std::abs(format.fps - fps);
-                       double diff2 = std::abs(closest_fps - fps);
+                       auto diff1 = boost::abs(boost::rational<int>(format.time_scale, format.duration) - fps);
+                       auto diff2 = boost::abs(closest_fps - fps);
 
-                       if(diff1 < diff2)
-                               closest_fps = format.fps;
+                       if (diff1 < diff2)
+                               closest_fps = boost::rational<int>(format.time_scale, format.duration);
                }
-       
+
                return closest_fps;
        }
 
-       return fail_value;      
+       return fail_value;
 }
 
 void fix_meta_data(AVFormatContext& context)
@@ -462,19 +484,45 @@ spl::shared_ptr<AVPacket> create_packet()
 
 spl::shared_ptr<AVFrame> create_frame()
 {      
-       spl::shared_ptr<AVFrame> frame(avcodec_alloc_frame(), av_free);
-       avcodec_get_frame_defaults(frame.get());
+       spl::shared_ptr<AVFrame> frame(av_frame_alloc(), [](AVFrame* p)
+       {
+               av_frame_free(&p);
+       });
        return frame;
 }
 
-spl::shared_ptr<AVCodecContext> open_codec(AVFormatContext& context, enum AVMediaType type, int& index)
+std::shared_ptr<core::mutable_audio_buffer> flush_audio()
+{
+       static std::shared_ptr<core::mutable_audio_buffer> audio(new core::mutable_audio_buffer());
+       return audio;
+}
+
+std::shared_ptr<core::mutable_audio_buffer> empty_audio()
+{
+       static std::shared_ptr<core::mutable_audio_buffer> audio(new core::mutable_audio_buffer());
+       return audio;
+}
+
+std::shared_ptr<AVFrame> flush_video()
+{
+       static auto video = create_frame();
+       return video;
+}
+
+std::shared_ptr<AVFrame> empty_video()
+{
+       static auto video = create_frame();
+       return video;
+}
+
+spl::shared_ptr<AVCodecContext> open_codec(AVFormatContext& context, enum AVMediaType type, int& index, bool single_threaded)
 {      
        AVCodec* decoder;
-       index = THROW_ON_ERROR2(av_find_best_stream(&context, type, -1, -1, &decoder, 0), "");
+       index = THROW_ON_ERROR2(av_find_best_stream(&context, type, index, -1, &decoder, 0), "");
        //if(strcmp(decoder->name, "prores") == 0 && decoder->next && strcmp(decoder->next->name, "prores_lgpl") == 0)
        //      decoder = decoder->next;
 
-       THROW_ON_ERROR2(tbb_avcodec_open(context.streams[index]->codec, decoder), "");
+       THROW_ON_ERROR2(tbb_avcodec_open(context.streams[index]->codec, decoder, single_threaded), "");
        return spl::shared_ptr<AVCodecContext>(context.streams[index]->codec, tbb_avcodec_close);
 }
 
@@ -482,7 +530,10 @@ spl::shared_ptr<AVFormatContext> open_input(const std::wstring& filename)
 {
        AVFormatContext* weak_context = nullptr;
        THROW_ON_ERROR2(avformat_open_input(&weak_context, u8(filename).c_str(), nullptr, nullptr), filename);
-       spl::shared_ptr<AVFormatContext> context(weak_context, av_close_input_file);                    
+       spl::shared_ptr<AVFormatContext> context(weak_context, [](AVFormatContext* p)
+       {
+               avformat_close_input(&p);
+       });
        THROW_ON_ERROR2(avformat_find_stream_info(weak_context, nullptr), filename);
        fix_meta_data(*context);
        return context;
@@ -496,7 +547,7 @@ std::wstring print_mode(int width, int height, double fps, bool interlaced)
        return boost::lexical_cast<std::wstring>(width) + L"x" + boost::lexical_cast<std::wstring>(height) + (!interlaced ? L"p" : L"i") + fps_ss.str();
 }
 
-bool is_valid_file(const std::wstring& filename)
+bool is_valid_file(const std::wstring& filename, bool only_video)
 {                              
        static const auto invalid_exts = {
                L".png",
@@ -514,6 +565,11 @@ bool is_valid_file(const std::wstring& filename)
                L".swf",
                L".ct"
        };
+       static const auto only_audio = {
+               L".mp3",
+               L".wav",
+               L".wma"
+       };
        static const auto valid_exts = {
                L".m2t",
                L".mov",
@@ -521,8 +577,6 @@ bool is_valid_file(const std::wstring& filename)
                L".dv",
                L".flv",
                L".mpg",
-               L".wav",
-               L".mp3",
                L".dnxhd",
                L".h264",
                L".prores"
@@ -531,11 +585,17 @@ bool is_valid_file(const std::wstring& filename)
        auto ext = boost::to_lower_copy(boost::filesystem::path(filename).extension().wstring());
                
        if(std::find(valid_exts.begin(), valid_exts.end(), ext) != valid_exts.end())
-               return true;    
+               return true;
+
+       if (!only_video && std::find(only_audio.begin(), only_audio.end(), ext) != only_audio.end())
+               return true;
        
        if(std::find(invalid_exts.begin(), invalid_exts.end(), ext) != invalid_exts.end())
                return false;   
 
+       if (only_video && std::find(only_audio.begin(), only_audio.end(), ext) != only_audio.end())
+               return false;
+
        auto u8filename = u8(filename);
        
        int score = 0;
@@ -552,7 +612,7 @@ bool is_valid_file(const std::wstring& filename)
                buf.push_back(*file_it);
 
        if(buf.empty())
-               return nullptr;
+               return false;
 
        pb.buf          = buf.data();
        pb.buf_size = static_cast<int>(buf.size());
@@ -566,7 +626,10 @@ bool try_get_duration(const std::wstring filename, std::int64_t& duration, boost
        if (avformat_open_input(&weak_context, u8(filename).c_str(), nullptr, nullptr) < 0)
                return false;
 
-       std::shared_ptr<AVFormatContext> context(weak_context, av_close_input_file);
+       std::shared_ptr<AVFormatContext> context(weak_context, [](AVFormatContext* p)
+       {
+               avformat_close_input(&p);
+       });
 
        context->probesize = context->probesize / 10;
        context->max_analyze_duration = context->probesize / 10;
@@ -588,7 +651,7 @@ bool try_get_duration(const std::wstring filename, std::int64_t& duration, boost
        return true;
 }
 
-std::wstring probe_stem(const std::wstring& stem)
+std::wstring probe_stem(const std::wstring& stem, bool only_video)
 {
        auto stem2 = boost::filesystem::path(stem);
        auto parent = find_case_insensitive(stem2.parent_path().wstring());
@@ -600,11 +663,182 @@ std::wstring probe_stem(const std::wstring& stem)
 
        for(auto it = boost::filesystem::directory_iterator(dir); it != boost::filesystem::directory_iterator(); ++it)
        {
-               if(boost::iequals(it->path().stem().wstring(), stem2.filename().wstring()) && is_valid_file(it->path().wstring()))
+               if(boost::iequals(it->path().stem().wstring(), stem2.filename().wstring()) && is_valid_file(it->path().wstring(), only_video))
                        return it->path().wstring();
        }
        return L"";
 }
+
+core::audio_channel_layout get_audio_channel_layout(int num_channels, std::uint64_t layout, const std::wstring& channel_layout_spec)
+{
+       if (!channel_layout_spec.empty())
+       {
+               if (boost::contains(channel_layout_spec, L":")) // Custom on the fly layout specified.
+               {
+                       std::vector<std::wstring> type_and_channel_order;
+                       boost::split(type_and_channel_order, channel_layout_spec, boost::is_any_of(L":"), boost::algorithm::token_compress_off);
+                       auto& type                      = type_and_channel_order.at(0);
+                       auto& order                     = type_and_channel_order.at(1);
+
+                       return core::audio_channel_layout(num_channels, std::move(type), order);
+               }
+               else // Preconfigured named channel layout selected.
+               {
+                       auto channel_layout = core::audio_channel_layout_repository::get_default()->get_layout(channel_layout_spec);
+
+                       if (!channel_layout)
+                               CASPAR_THROW_EXCEPTION(user_error() << msg_info(L"No channel layout with name " + channel_layout_spec + L" registered"));
+
+                       channel_layout->num_channels = num_channels;
+
+                       return *channel_layout;
+               }
+       }
+
+       if (!layout)
+       {
+               if (num_channels == 1)
+                       return core::audio_channel_layout(num_channels, L"mono", L"FC");
+               else if (num_channels == 2)
+                       return core::audio_channel_layout(num_channels, L"stereo", L"FL FR");
+               else
+                       return core::audio_channel_layout(num_channels, L"", L""); // Passthru without named channels as is.
+       }
+
+       // What FFmpeg calls "channel layout" is only the "layout type" of a channel layout in
+       // CasparCG where the channel layout supports different orders as well.
+       // The user needs to provide additional mix-configs in casparcg.config to support more
+       // than the most common (5.1, mono and stereo) types.
+
+       // Based on information in https://ffmpeg.org/ffmpeg-utils.html#Channel-Layout
+       switch (layout)
+       {
+       case AV_CH_LAYOUT_MONO:
+               return core::audio_channel_layout(num_channels, L"mono",                        L"FC");
+       case AV_CH_LAYOUT_STEREO:
+               return core::audio_channel_layout(num_channels, L"stereo",                      L"FL FR");
+       case AV_CH_LAYOUT_2POINT1:
+               return core::audio_channel_layout(num_channels, L"2.1",                         L"FL FR LFE");
+       case AV_CH_LAYOUT_SURROUND:
+               return core::audio_channel_layout(num_channels, L"3.0",                         L"FL FR FC");
+       case AV_CH_LAYOUT_2_1:
+               return core::audio_channel_layout(num_channels, L"3.0(back)",           L"FL FR BC");
+       case AV_CH_LAYOUT_4POINT0:
+               return core::audio_channel_layout(num_channels, L"4.0",                         L"FL FR FC BC");
+       case AV_CH_LAYOUT_QUAD:
+               return core::audio_channel_layout(num_channels, L"quad",                        L"FL FR BL BR");
+       case AV_CH_LAYOUT_2_2:
+               return core::audio_channel_layout(num_channels, L"quad(side)",          L"FL FR SL SR");
+       case AV_CH_LAYOUT_3POINT1:
+               return core::audio_channel_layout(num_channels, L"3.1",                         L"FL FR FC LFE");
+       case AV_CH_LAYOUT_5POINT0_BACK:
+               return core::audio_channel_layout(num_channels, L"5.0",                         L"FL FR FC BL BR");
+       case AV_CH_LAYOUT_5POINT0:
+               return core::audio_channel_layout(num_channels, L"5.0(side)",           L"FL FR FC SL SR");
+       case AV_CH_LAYOUT_4POINT1:
+               return core::audio_channel_layout(num_channels, L"4.1",                         L"FL FR FC LFE BC");
+       case AV_CH_LAYOUT_5POINT1_BACK:
+               return core::audio_channel_layout(num_channels, L"5.1",                         L"FL FR FC LFE BL BR");
+       case AV_CH_LAYOUT_5POINT1:
+               return core::audio_channel_layout(num_channels, L"5.1(side)",           L"FL FR FC LFE SL SR");
+       case AV_CH_LAYOUT_6POINT0:
+               return core::audio_channel_layout(num_channels, L"6.0",                         L"FL FR FC BC SL SR");
+       case AV_CH_LAYOUT_6POINT0_FRONT:
+               return core::audio_channel_layout(num_channels, L"6.0(front)",          L"FL FR FLC FRC SL SR");
+       case AV_CH_LAYOUT_HEXAGONAL:
+               return core::audio_channel_layout(num_channels, L"hexagonal",           L"FL FR FC BL BR BC");
+       case AV_CH_LAYOUT_6POINT1:
+               return core::audio_channel_layout(num_channels, L"6.1",                         L"FL FR FC LFE BC SL SR");
+       case AV_CH_LAYOUT_6POINT1_BACK:
+               return core::audio_channel_layout(num_channels, L"6.1(back)",           L"FL FR FC LFE BL BR BC");
+       case AV_CH_LAYOUT_6POINT1_FRONT:
+               return core::audio_channel_layout(num_channels, L"6.1(front)",          L"FL FR LFE FLC FRC SL SR");
+       case AV_CH_LAYOUT_7POINT0:
+               return core::audio_channel_layout(num_channels, L"7.0",                         L"FL FR FC BL BR SL SR");
+       case AV_CH_LAYOUT_7POINT0_FRONT:
+               return core::audio_channel_layout(num_channels, L"7.0(front)",          L"FL FR FC FLC FRC SL SR");
+       case AV_CH_LAYOUT_7POINT1:
+               return core::audio_channel_layout(num_channels, L"7.1",                         L"FL FR FC LFE BL BR SL SR");
+       case AV_CH_LAYOUT_7POINT1_WIDE_BACK:
+               return core::audio_channel_layout(num_channels, L"7.1(wide)",           L"FL FR FC LFE BL BR FLC FRC");
+       case AV_CH_LAYOUT_7POINT1_WIDE:
+               return core::audio_channel_layout(num_channels, L"7.1(wide-side)",      L"FL FR FC LFE FLC FRC SL SR");
+       case AV_CH_LAYOUT_STEREO_DOWNMIX:
+               return core::audio_channel_layout(num_channels, L"downmix",                     L"DL DR");
+       default:
+               // Passthru
+               return core::audio_channel_layout(num_channels, L"", L"");
+       }
+}
+
+// av_get_default_channel_layout does not work for layouts not predefined in ffmpeg. This is needed to support > 8 channels.
+std::int64_t create_channel_layout_bitmask(int num_channels)
+{
+       if (num_channels > 63)
+               CASPAR_THROW_EXCEPTION(invalid_argument() << msg_info(L"FFmpeg cannot handle more than 63 audio channels"));
+
+       const auto ALL_63_CHANNELS = 0x7FFFFFFFFFFFFFFFULL;
+
+       auto to_shift = 63 - num_channels;
+       auto result = ALL_63_CHANNELS >> to_shift;
+
+       return static_cast<std::int64_t>(result);
+}
+
+std::string to_string(const boost::rational<int>& framerate)
+{
+       return boost::lexical_cast<std::string>(framerate.numerator())
+               + "/" + boost::lexical_cast<std::string>(framerate.denominator()) + " (" + boost::lexical_cast<std::string>(static_cast<double>(framerate.numerator()) / static_cast<double>(framerate.denominator())) + ") fps";
+}
+
+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];
+}
+
 //
 //void av_dup_frame(AVFrame* frame)
 //{