]> git.sesse.net Git - casparcg/commitdiff
* Fixed bug in input where video without audio causes input to be ticked to much...
authorHelge Norberg <helge.norberg@svt.se>
Fri, 4 Sep 2015 17:15:41 +0000 (19:15 +0200)
committerHelge Norberg <helge.norberg@svt.se>
Fri, 4 Sep 2015 17:15:41 +0000 (19:15 +0200)
* Merged read_fps code from 2.0 to 2.1 for correctly detecting framerate.
* Changed logging of execution of AMCP commands.

modules/ffmpeg/producer/ffmpeg_producer.cpp
modules/ffmpeg/producer/input/input.cpp
modules/ffmpeg/producer/util/util.cpp
modules/ffmpeg/producer/video/video_decoder.cpp
protocol/amcp/AMCPCommandQueue.cpp

index bf517df6384ae8e30138eeeefad0daeffa12a2ab..eb6020247205cc372b303a3905e830eebb0185d9 100644 (file)
@@ -389,7 +389,7 @@ public:
        void decode_next_frame()
        {
                for(int n = 0; n < 8 && muxer_.empty(); ++n)
-               {                               
+               {
                        if(!muxer_.video_ready())
                                muxer_.push_video(video_decoder_ ? (*video_decoder_)() : create_frame());
                        if(!muxer_.audio_ready())
index 823e10ac74685d570a85f63bc7858128366e3b98..f48041f047ef9508c149356ba409b7ebfbd90f35 100644 (file)
@@ -98,7 +98,7 @@ public:
                
        size_type size() const
        {
-               return index_ != -1 ? packets_.size() : std::numeric_limits<size_type>::max();
+               return index_ > -1 ? packets_.size() : std::numeric_limits<size_type>::max();
        }
 };
                
@@ -215,11 +215,16 @@ private:
                        }
                }
                
-               auto stream = format_context_->streams[default_stream_index_];
-               auto codec  = stream->codec;
-               auto fixed_target = (target*stream->time_base.den*codec->time_base.num)/(stream->time_base.num*codec->time_base.den)*codec->ticks_per_frame;
+               auto stream     = format_context_->streams[default_stream_index_];
+               auto fps        = read_fps(*format_context_, 0.0);
                
-               THROW_ON_ERROR2(avformat_seek_file(format_context_.get(), default_stream_index_, std::numeric_limits<int64_t>::min(), fixed_target, fixed_target, 0), print());         
+               THROW_ON_ERROR2(avformat_seek_file(
+                               format_context_.get(),
+                               default_stream_index_,
+                               std::numeric_limits<int64_t>::min(),
+                               static_cast<int64_t>((target / fps * stream->time_base.den) / stream->time_base.num),
+                               std::numeric_limits<int64_t>::max(),
+                               0), print());
                
                video_stream_.push(nullptr);
                audio_stream_.push(nullptr);
index 3967519eaf25041a4cf387a8a28470abcae1f5fe..a526340e094ea314ade90c39749b095dd2bd4391 100644 (file)
@@ -359,7 +359,15 @@ double read_fps(AVFormatContext& context, double fail_value)
        {
                const auto video_context = context.streams[video_index]->codec;
                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 static_cast<double>(frame_rate_time_base.den) / static_cast<double>(frame_rate_time_base.num);
+               }
+
                AVRational time_base = video_context->time_base;
 
                if(boost::filesystem::path(context.filename).extension().string() == ".flv")
index 3492e9ab2369adcc0f74c236764c6bdc67282958..e06becdbd7e74304efa32698d06632ab1bb752a3 100644 (file)
@@ -134,7 +134,7 @@ public:
                        return nullptr;
                
                auto stream_time_base    = stream_->time_base;
-               auto packet_frame_number = static_cast<uint32_t>((static_cast<double>(pkt.pts * stream_time_base.num)/stream_time_base.den)*fps_);
+               auto packet_frame_number = static_cast<uint32_t>((static_cast<double>(pkt.pts * stream_time_base.num) / stream_time_base.den) * fps_);
 
                file_frame_number_ = packet_frame_number;
 
index 4263a525e4606fa96f8a29d1dddc6ea0dec027c6..e372047e10450914061af8d64d669d7c1365cef3 100644 (file)
@@ -86,10 +86,10 @@ void AMCPCommandQueue::AddCommand(AMCPCommand::ptr_type pCurrentCommand)
        {
                try
                {
-                       caspar::timer timer;
-
                        try
                        {
+                               caspar::timer timer;
+
                                auto print = pCurrentCommand->print();
                                auto params = boost::join(pCurrentCommand->parameters(), L" ");
 
@@ -102,9 +102,9 @@ void AMCPCommandQueue::AddCommand(AMCPCommand::ptr_type pCurrentCommand)
                                }
 
                                if (pCurrentCommand->Execute())
-                                       CASPAR_LOG(debug) << "Executed command: " << print << " " << timer.elapsed();
+                                       CASPAR_LOG(debug) << "Executed command (" << timer.elapsed() << "s): " << print;
                                else
-                                       CASPAR_LOG(warning) << "Failed to execute command: " << print << " " << timer.elapsed();
+                                       CASPAR_LOG(warning) << "Failed to execute command: " << print;
                        }
                        catch (file_not_found&)
                        {
@@ -119,7 +119,7 @@ void AMCPCommandQueue::AddCommand(AMCPCommand::ptr_type pCurrentCommand)
                        catch (...)
                        {
                                CASPAR_LOG_CURRENT_EXCEPTION();
-                               CASPAR_LOG(warning) << "Failed to execute command:" << pCurrentCommand->print() << " " << timer.elapsed();
+                               CASPAR_LOG(warning) << "Failed to execute command:" << pCurrentCommand->print();
                                pCurrentCommand->SetReplyString(L"501 " + pCurrentCommand->print() + L" FAILED\r\n");
                        }