summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/ffmpeg/libavfilter/vf_scale.c
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/ffmpeg/libavfilter/vf_scale.c')
-rw-r--r--chromium/third_party/ffmpeg/libavfilter/vf_scale.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/chromium/third_party/ffmpeg/libavfilter/vf_scale.c b/chromium/third_party/ffmpeg/libavfilter/vf_scale.c
index 2e692cff5b7..b1d97af4e04 100644
--- a/chromium/third_party/ffmpeg/libavfilter/vf_scale.c
+++ b/chromium/third_party/ffmpeg/libavfilter/vf_scale.c
@@ -71,7 +71,7 @@ enum var_name {
VARS_NB
};
-typedef struct {
+typedef struct ScaleContext {
const AVClass *class;
struct SwsContext *sws; ///< software scaler context
struct SwsContext *isws[2]; ///< software scaler context for interlaced material
@@ -81,6 +81,7 @@ typedef struct {
* New dimensions. Special values are:
* 0 = original width/height
* -1 = keep original aspect
+ * -N = try to keep aspect but make sure it is divisible by N
*/
int w, h;
char *size_str;
@@ -236,6 +237,7 @@ static int config_props(AVFilterLink *outlink)
double var_values[VARS_NB], res;
char *expr;
int ret;
+ int factor_w, factor_h;
var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w;
var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h;
@@ -270,23 +272,35 @@ static int config_props(AVFilterLink *outlink)
w = scale->w;
h = scale->h;
- /* sanity check params */
- if (w < -1 || h < -1) {
- av_log(ctx, AV_LOG_ERROR, "Size values less than -1 are not acceptable.\n");
- return AVERROR(EINVAL);
+ /* Check if it is requested that the result has to be divisible by a some
+ * factor (w or h = -n with n being the factor). */
+ factor_w = 1;
+ factor_h = 1;
+ if (w < -1) {
+ factor_w = -w;
}
- if (w == -1 && h == -1)
+ if (h < -1) {
+ factor_h = -h;
+ }
+
+ if (w < 0 && h < 0)
scale->w = scale->h = 0;
if (!(w = scale->w))
w = inlink->w;
if (!(h = scale->h))
h = inlink->h;
- if (w == -1)
- w = av_rescale(h, inlink->w, inlink->h);
- if (h == -1)
- h = av_rescale(w, inlink->h, inlink->w);
+ /* Make sure that the result is divisible by the factor we determined
+ * earlier. If no factor was set, it is nothing will happen as the default
+ * factor is 1 */
+ if (w < 0)
+ w = av_rescale(h, inlink->w, inlink->h * factor_w) * factor_w;
+ if (h < 0)
+ h = av_rescale(w, inlink->h, inlink->w * factor_h) * factor_h;
+
+ /* Note that force_original_aspect_ratio may overwrite the previous set
+ * dimensions so that it is not divisible by the set factors anymore. */
if (scale->force_original_aspect_ratio) {
int tmp_w = av_rescale(h, inlink->w, inlink->h);
int tmp_h = av_rescale(w, inlink->h, inlink->w);