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
, 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
\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
{\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