]> git.sesse.net Git - casparcg/commitdiff
ffmpeg_consumer: Fixed packet interleaving.
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Wed, 15 Feb 2012 10:43:20 +0000 (10:43 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Wed, 15 Feb 2012 10:43:20 +0000 (10:43 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/trunk@2416 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

modules/ffmpeg/consumer/ffmpeg_consumer.cpp

index 6c7509ccb6d8036388665ede286cdc3abedbe917..c872545710ae46069c2c05addb80a10d908b7dab 100644 (file)
@@ -259,7 +259,6 @@ public:
                boost::filesystem2::remove(boost::filesystem2::wpath(env::media_folder() + widen(filename))); // Delete the file if it exists\r
 \r
                graph_->set_color("frame-time", diagnostics::color(0.1f, 1.0f, 0.1f));\r
-               graph_->set_color("write-time", diagnostics::color(0.5f, 0.5f, 0.1f));\r
                graph_->set_text(print());\r
                diagnostics::register_graph(graph_);\r
 \r
@@ -297,9 +296,8 @@ public:
        ~ffmpeg_consumer()\r
        {    \r
                encode_executor_.stop();\r
-               encode_executor_.join();\r
-\r
                write_executor_.stop();\r
+               encode_executor_.join();\r
                write_executor_.join();\r
                \r
                LOG_ON_ERROR2(av_write_trailer(oc_.get()), "[ffmpeg_consumer]");\r
@@ -459,7 +457,7 @@ public:
                });\r
        }\r
 \r
-       std::shared_ptr<AVFrame> convert_video(const safe_ptr<core::read_frame>& frame, AVCodecContext* c)\r
+       std::shared_ptr<AVFrame> convert_video(core::read_frame& frame, AVCodecContext* c)\r
        {\r
                if(!sws_) \r
                {\r
@@ -469,7 +467,7 @@ public:
                }\r
 \r
                std::shared_ptr<AVFrame> in_frame(avcodec_alloc_frame(), av_free);\r
-               avpicture_fill(reinterpret_cast<AVPicture*>(in_frame.get()), const_cast<uint8_t*>(frame->image_data().begin()), PIX_FMT_BGRA, format_desc_.width, format_desc_.height);\r
+               avpicture_fill(reinterpret_cast<AVPicture*>(in_frame.get()), const_cast<uint8_t*>(frame.image_data().begin()), PIX_FMT_BGRA, format_desc_.width, format_desc_.height);\r
                                \r
                std::shared_ptr<AVFrame> out_frame(avcodec_alloc_frame(), av_free);\r
                picture_buf_.resize(avpicture_get_size(c->pix_fmt, c->width, c->height));\r
@@ -480,7 +478,7 @@ public:
                return out_frame;\r
        }\r
   \r
-       std::shared_ptr<AVPacket> encode_video_frame(const safe_ptr<core::read_frame>& frame)\r
+       std::shared_ptr<AVPacket> encode_video_frame(core::read_frame& frame)\r
        { \r
                auto c = video_st_->codec;\r
                \r
@@ -523,7 +521,7 @@ public:
                return nullptr;\r
        }\r
                \r
-       byte_vector convert_audio(const safe_ptr<core::read_frame>& frame, AVCodecContext* c)\r
+       byte_vector convert_audio(core::read_frame& frame, AVCodecContext* c)\r
        {\r
                if(!swr_)               \r
                        swr_.reset(new audio_resampler(c->channels, format_desc_.audio_channels, \r
@@ -531,7 +529,7 @@ public:
                                                                                   c->sample_fmt, AV_SAMPLE_FMT_S32));\r
                \r
 \r
-               auto audio_data = frame->audio_data();\r
+               auto audio_data = frame.audio_data();\r
 \r
                std::vector<int8_t,  tbb::cache_aligned_allocator<int8_t>> audio_resample_buffer;\r
                std::copy(reinterpret_cast<const uint8_t*>(audio_data.begin()), \r
@@ -543,7 +541,7 @@ public:
                return byte_vector(audio_resample_buffer.begin(), audio_resample_buffer.end());\r
        }\r
 \r
-       std::shared_ptr<AVPacket> encode_audio_frame(const safe_ptr<core::read_frame>& frame)\r
+       std::shared_ptr<AVPacket> encode_audio_frame(core::read_frame& frame)\r
        {                       \r
                auto c = audio_st_->codec;\r
 \r
@@ -596,21 +594,17 @@ public:
                {               \r
                        boost::timer frame_timer;\r
 \r
-                       auto video = encode_video_frame(frame);\r
-                       auto audio = encode_audio_frame(frame);\r
+                       auto video = encode_video_frame(*frame);\r
+                       auto audio = encode_audio_frame(*frame);\r
 \r
                        graph_->set_value("frame-time", frame_timer.elapsed()*format_desc_.fps*0.5);\r
                        \r
                        write_executor_.begin_invoke([=]\r
                        {\r
-                               boost::timer write_timer;\r
-\r
                                if(video)\r
-                                       av_write_frame(oc_.get(), video.get());\r
+                                       av_interleaved_write_frame(oc_.get(), video.get());\r
                                if(audio)\r
-                                       av_write_frame(oc_.get(), audio.get());\r
-\r
-                               graph_->set_value("write-time", write_timer.elapsed()*format_desc_.fps*0.5);\r
+                                       av_interleaved_write_frame(oc_.get(), audio.get());\r
                        });\r
                });\r
        }\r