Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Timothy Gu authored on 2013/08/04 08:30:00... | ... |
@@ -6373,6 +6373,33 @@ Full range (0-255 in case of 8bit luma) |
6373 | 6373 |
"Mpeg" range (16-235 in case of 8bit luma) |
6374 | 6374 |
@end table |
6375 | 6375 |
|
6376 |
+@item force_original_aspect_ratio |
|
6377 |
+Enable decreasing or increasing output video width or height if necessary to |
|
6378 |
+keep the original aspect ratio. Possible values: |
|
6379 |
+ |
|
6380 |
+@table @samp |
|
6381 |
+@item disable |
|
6382 |
+Scale the video as specified and disable this feature. |
|
6383 |
+ |
|
6384 |
+@item decrease |
|
6385 |
+The output video dimensions will automatically be decreased if needed. |
|
6386 |
+ |
|
6387 |
+@item increase |
|
6388 |
+The output video dimensions will automatically be increased if needed. |
|
6389 |
+ |
|
6390 |
+@end table |
|
6391 |
+ |
|
6392 |
+One useful instance of this option is that when you know a specific device's |
|
6393 |
+maximum allowed resolution, you can use this to limit the output video to |
|
6394 |
+that, while retaining the aspect ratio. For example, device A allows |
|
6395 |
+1280x720 playback, and your video is 1920x800. Using this option (set it to |
|
6396 |
+decrease) and specifying 1280x720 to the command line makes the output |
|
6397 |
+1280x533. |
|
6398 |
+ |
|
6399 |
+Please note that this is a different thing than specifying -1 for @option{w} |
|
6400 |
+or @option{h}, you still need to specify the output resolution for this option |
|
6401 |
+to work. |
|
6402 |
+ |
|
6376 | 6403 |
@end table |
6377 | 6404 |
|
6378 | 6405 |
The values of the @var{w} and @var{h} options are expressions |
... | ... |
@@ -101,6 +101,8 @@ typedef struct { |
101 | 101 |
int out_v_chr_pos; |
102 | 102 |
int in_h_chr_pos; |
103 | 103 |
int in_v_chr_pos; |
104 |
+ |
|
105 |
+ int force_original_aspect_ratio; |
|
104 | 106 |
} ScaleContext; |
105 | 107 |
|
106 | 108 |
static av_cold int init(AVFilterContext *ctx) |
... | ... |
@@ -274,6 +276,19 @@ static int config_props(AVFilterLink *outlink) |
274 | 274 |
if (h == -1) |
275 | 275 |
h = av_rescale(w, inlink->h, inlink->w); |
276 | 276 |
|
277 |
+ if (scale->force_original_aspect_ratio) { |
|
278 |
+ int tmp_w = av_rescale(h, inlink->w, inlink->h); |
|
279 |
+ int tmp_h = av_rescale(w, inlink->h, inlink->w); |
|
280 |
+ |
|
281 |
+ if (scale->force_original_aspect_ratio == 1) { |
|
282 |
+ w = FFMIN(tmp_w, w); |
|
283 |
+ h = FFMIN(tmp_h, h); |
|
284 |
+ } else { |
|
285 |
+ w = FFMAX(tmp_w, w); |
|
286 |
+ h = FFMAX(tmp_h, h); |
|
287 |
+ } |
|
288 |
+ } |
|
289 |
+ |
|
277 | 290 |
if (w > INT_MAX || h > INT_MAX || |
278 | 291 |
(h * inlink->w) > INT_MAX || |
279 | 292 |
(w * inlink->h) > INT_MAX) |
... | ... |
@@ -501,6 +516,10 @@ static const AVOption scale_options[] = { |
501 | 501 |
{ "in_h_chr_pos", "input horizontal chroma position in luma grid/256", OFFSET(in_h_chr_pos), AV_OPT_TYPE_INT, { .i64 = -1}, -1, 512, FLAGS }, |
502 | 502 |
{ "out_v_chr_pos", "output vertical chroma position in luma grid/256" , OFFSET(out_v_chr_pos), AV_OPT_TYPE_INT, { .i64 = -1}, -1, 512, FLAGS }, |
503 | 503 |
{ "out_h_chr_pos", "output horizontal chroma position in luma grid/256", OFFSET(out_h_chr_pos), AV_OPT_TYPE_INT, { .i64 = -1}, -1, 512, FLAGS }, |
504 |
+ { "force_original_aspect_ratio", "decrease or increase w/h if necessary to keep the original AR", OFFSET(force_original_aspect_ratio), AV_OPT_TYPE_INT, { .i64 = 0}, 0, 2, FLAGS, "force_oar" }, |
|
505 |
+ { "disable", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, 0, 0, FLAGS, "force_oar" }, |
|
506 |
+ { "decrease", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 1 }, 0, 0, FLAGS, "force_oar" }, |
|
507 |
+ { "increase", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 2 }, 0, 0, FLAGS, "force_oar" }, |
|
504 | 508 |
{ NULL }, |
505 | 509 |
}; |
506 | 510 |
|