+ if( (ost->resample_height != (ist->st->codec->height - (ost->topBand + ost->bottomBand)))
+ || (ost->resample_width != (ist->st->codec->width - (ost->leftBand + ost->rightBand)))
+ || (ost->resample_pix_fmt!= ist->st->codec->pix_fmt) ) {
+
+ /* keep bands proportional to the frame size */
+ topBand = ((int64_t)ist->st->codec->height * ost->original_topBand / ost->original_height) & ~1;
+ bottomBand = ((int64_t)ist->st->codec->height * ost->original_bottomBand / ost->original_height) & ~1;
+ leftBand = ((int64_t)ist->st->codec->width * ost->original_leftBand / ost->original_width) & ~1;
+ rightBand = ((int64_t)ist->st->codec->width * ost->original_rightBand / ost->original_width) & ~1;
+
+ /* sanity check to ensure no bad band sizes sneak in */
+ assert(topBand <= INT_MAX && topBand >= 0);
+ assert(bottomBand <= INT_MAX && bottomBand >= 0);
+ assert(leftBand <= INT_MAX && leftBand >= 0);
+ assert(rightBand <= INT_MAX && rightBand >= 0);
+
+ ost->topBand = topBand;
+ ost->bottomBand = bottomBand;
+ ost->leftBand = leftBand;
+ ost->rightBand = rightBand;
+
+ ost->resample_height = ist->st->codec->height - (ost->topBand + ost->bottomBand);
+ ost->resample_width = ist->st->codec->width - (ost->leftBand + ost->rightBand);
+ ost->resample_pix_fmt= ist->st->codec->pix_fmt;
+
+ /* initialize a new scaler context */
+ sws_freeContext(ost->img_resample_ctx);
+ sws_flags = av_get_int(sws_opts, "sws_flags", NULL);
+ ost->img_resample_ctx = sws_getContext(
+ ist->st->codec->width - (ost->leftBand + ost->rightBand),
+ ist->st->codec->height - (ost->topBand + ost->bottomBand),
+ ist->st->codec->pix_fmt,
+ ost->st->codec->width - (ost->padleft + ost->padright),
+ ost->st->codec->height - (ost->padtop + ost->padbottom),
+ ost->st->codec->pix_fmt,
+ sws_flags, NULL, NULL, NULL);
+ if (ost->img_resample_ctx == NULL) {
+ fprintf(stderr, "Cannot get resampling context\n");
+ av_exit(1);
+ }
+ }