Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] libavfilter/vf_pad: Try round up w/h for odd resolution to avoid failure
@ 2022-05-01  9:10 Linjie Fu
  0 siblings, 0 replies; only message in thread
From: Linjie Fu @ 2022-05-01  9:10 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Linjie Fu

Try round_up output w/h for the clips with odd resolution to avoid failure if no
padding is required(e.g. iw/ih+0+0).

$ffmpeg -i input.mp4 -vf "scale=1241x1234,pad=iw+0+0:ih+3+3:0:3" -f null -

Before:
Round down to 1240x1234 and failed since s->w < inlink->w (e.g. 1240 < 1241)
[Parsed_pad_1 @ 0x7f849090f840] Padded dimensions cannot be smaller than input dimensions.
[Parsed_pad_1 @ 0x7f849090f840] Failed to configure input pad on Parsed_pad_1
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:0
Conversion failed!

After:
Try to Round up for odd resolution (1241x1234 -> 1242x1240)
Stream #0:0(und): Video: wrapped_avframe, yuv420p(tv, progressive), 1242x1240

Signed-off-by: Linjie Fu <linjie.justin.fu@gmail.com>
---
 libavfilter/vf_pad.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/libavfilter/vf_pad.c b/libavfilter/vf_pad.c
index e52f7284d4..c9a0a75630 100644
--- a/libavfilter/vf_pad.c
+++ b/libavfilter/vf_pad.c
@@ -107,6 +107,7 @@ static int config_input(AVFilterLink *inlink)
     AVFilterContext *ctx = inlink->dst;
     PadContext *s = ctx->priv;
     AVRational adjusted_aspect = s->aspect;
+    int round_w, round_h;
     int ret;
     double var_values[VARS_NB], res;
     char *expr;
@@ -178,9 +179,13 @@ static int config_input(AVFilterLink *inlink)
     if (s->y < 0 || s->y + inlink->h > s->h)
         s->y = var_values[VAR_Y] = (s->h - inlink->h) / 2;
 
-    s->w    = ff_draw_round_to_sub(&s->draw, 0, -1, s->w);
-    s->h    = ff_draw_round_to_sub(&s->draw, 1, -1, s->h);
-    /* sanity check params */
+    round_w = ff_draw_round_to_sub(&s->draw, 0, -1, s->w);
+    round_h = ff_draw_round_to_sub(&s->draw, 1, -1, s->h);
+
+    s->w = round_w < inlink->w ? ff_draw_round_to_sub(&s->draw, 0, 1, s->w) : round_w;
+    s->h = round_h < inlink->h ? ff_draw_round_to_sub(&s->draw, 0, 1, s->h) : round_h;
+
+   /* sanity check params */
     if (s->w < inlink->w || s->h < inlink->h) {
         av_log(ctx, AV_LOG_ERROR, "Padded dimensions cannot be smaller than input dimensions.\n");
         return AVERROR(EINVAL);
-- 
2.31.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-01  9:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-01  9:10 [FFmpeg-devel] [PATCH] libavfilter/vf_pad: Try round up w/h for odd resolution to avoid failure Linjie Fu

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git