]> git.sesse.net Git - casparcg/commitdiff
2.1.0: ffmpeg_consumer: -croptop, -cropbot, -cropright, -cropleft.
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Tue, 28 Feb 2012 20:31:50 +0000 (20:31 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Tue, 28 Feb 2012 20:31:50 +0000 (20:31 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.1.0@2503 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

modules/ffmpeg/consumer/ffmpeg_consumer.cpp

index d3dc353ec53c936b43ae1312bf39822cf8dd44c6..2b7bf23f257b3c82f02fe39ba978184cacba883b 100644 (file)
@@ -120,6 +120,10 @@ struct output_format
        int                             height;\r
        CodecID                 vcodec;\r
        CodecID                 acodec;\r
+       int                             croptop;\r
+       int                             cropbot;\r
+       int                             cropleft;\r
+       int                             cropright;\r
 \r
        output_format(const core::video_format_desc& format_desc, const std::string& filename, std::vector<option>& options)\r
                : format(av_guess_format(nullptr, filename.c_str(), nullptr))\r
@@ -127,6 +131,10 @@ struct output_format
                , height(format_desc.height)\r
                , vcodec(CODEC_ID_NONE)\r
                , acodec(CODEC_ID_NONE)\r
+               , croptop(0)\r
+               , cropbot(0)\r
+               , cropleft(0)\r
+               , cropright(0)\r
        {\r
                boost::range::remove_erase_if(options, [&](const option& o)\r
                {\r
@@ -205,7 +213,31 @@ struct output_format
                        \r
                        return true;\r
                }\r
+               else if(name == "croptop")\r
+               {\r
+                       croptop = boost::lexical_cast<int>(value);\r
+\r
+                       return true;\r
+               }\r
+               else if(name == "cropbot")\r
+               {\r
+                       cropbot = boost::lexical_cast<int>(value);\r
 \r
+                       return true;\r
+               }\r
+               else if(name == "cropleft")\r
+               {\r
+                       cropleft = boost::lexical_cast<int>(value);\r
+\r
+                       return true;\r
+               }\r
+               else if(name == "cropright")\r
+               {\r
+                       cropright = boost::lexical_cast<int>(value);\r
+\r
+                       return true;\r
+               }\r
+               \r
                return false;\r
        }\r
 };\r
@@ -456,19 +488,51 @@ public:
        {\r
                if(!sws_) \r
                {\r
-                       sws_.reset(sws_getContext(format_desc_.width, format_desc_.height, PIX_FMT_BGRA, c->width, c->height, c->pix_fmt, SWS_BICUBIC, nullptr, nullptr, nullptr), sws_freeContext);\r
+                       sws_.reset(sws_getContext(format_desc_.width  - output_format_.cropleft - output_format_.cropright, \r
+                                                                         format_desc_.height - output_format_.croptop  - output_format_.cropbot, \r
+                                                                         PIX_FMT_BGRA,\r
+                                                                         c->width,\r
+                                                                         c->height, \r
+                                                                         c->pix_fmt, \r
+                                                                         SWS_BICUBIC, nullptr, nullptr, nullptr), \r
+                                               sws_freeContext);\r
                        if (sws_ == nullptr) \r
                                BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Cannot initialize the conversion context"));\r
                }\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
-                               \r
+\r
+               avpicture_fill(reinterpret_cast<AVPicture*>(in_frame.get()), \r
+                                          const_cast<uint8_t*>(frame.image_data().begin()),\r
+                                          PIX_FMT_BGRA, \r
+                                          format_desc_.width,\r
+                                          format_desc_.height);\r
+\r
+               for(int n = 0; n < 4; ++n)\r
+               {\r
+                       in_frame->data[n]         = in_frame->data[n] + output_format_.cropleft;\r
+                       in_frame->linesize[n] = in_frame->linesize[n] - output_format_.cropleft - output_format_.cropright;\r
+               }\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
-               avpicture_fill(reinterpret_cast<AVPicture*>(out_frame.get()), picture_buf_.data(), c->pix_fmt, c->width, c->height);\r
 \r
-               sws_scale(sws_.get(), in_frame->data, in_frame->linesize, 0, format_desc_.height, out_frame->data, out_frame->linesize);\r
+               picture_buf_.resize(avpicture_get_size(c->pix_fmt, \r
+                                                                                          c->width,\r
+                                                                                          c->height));\r
+\r
+               avpicture_fill(reinterpret_cast<AVPicture*>(out_frame.get()),\r
+                                          picture_buf_.data(), \r
+                                          c->pix_fmt, \r
+                                          c->width, \r
+                                          c->height);\r
+\r
+               sws_scale(sws_.get(), \r
+                                 in_frame->data, \r
+                                 in_frame->linesize,\r
+                                 output_format_.croptop, \r
+                                 format_desc_.height - output_format_.croptop - output_format_.cropbot, \r
+                                 out_frame->data, \r
+                                 out_frame->linesize);\r
 \r
                return out_frame;\r
        }\r