PR #25912 opened by mindfreeze URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25912 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25912.patch
APV allows at most 20x20 tiles in the profiles the wrapper accepts. When the tile-w/tile-h passed in oapv-params gives a larger grid, liboapv enlarges the tiles until the grid fits, without reporting it. At 15360x8640, tile-w=512:tile-h=256 (30x34 tiles) is encoded with 768x432 tiles, so the stream does not have the tile layout that was asked for. Repeat liboapv's computation and log the tile size that is used: as a warning when tile-w or tile-h were given, in verbose otherwise, since the default 256x256 tiles are enlarged the same way in frames wider or taller than 5120. This is similar to what is done in [upstream](https://github.com/AcademySoftwareFoundation/openapv/blob/3f0291391dbb1fbc27229b2543aad4ce778b0d72/src/oapv_param.c#L547) FFmpeg do not support the UNCONST profile, so we would need to exclude it when we support it. ## Change `check_tile_grid()` repeats liboapv's computation after the parameters are parsed and logs the tile size that will be used. It logs at warning level when `tile-w` or `tile-h` was given explicitly and at verbose level otherwise. The encoder output does not change. ## How to reproduce ``` ffmpeg -f lavfi -i testsrc2=s=15360x8640 -frames:v 1 -pix_fmt yuv422p10le -c:v liboapv \ -oapv-params tile-w=512:tile-h=256 out.apv ffmpeg -i out.apv -c copy -bsf:v trace_headers -f null - 2>&1 | grep tile_.*_in_mbs ``` Before: no message; the stream has `tile_width_in_mbs = 48`, `tile_height_in_mbs = 27` (768×432), not 32×16. After: ``` [liboapv] Tile size 512x256 gives a 30x34 tile grid, more than the 20x20 APV allows; liboapv will use 768x432 tiles ``` ## Testing Tested with liboapv 1.1.3.0 (git [1d3cc6b](https://github.com/AcademySoftwareFoundation/openapv/tree/1d3cc6bfd0ff0c34953a2f8265f0fd6ee4efdd02)): - 15360×8640 with `tile-w=512:tile-h=256` gives a warning; the size it predicts, 768×432, matches the stream. - 15360×8640 with `tile-w=7680:tile-h=256` (only the rows over the limit) predicts 7680×432, which matches the stream. - 15360×8640 with the default tiles logs only at `-v verbose`. - 3840×2160 with `tile-w=512:tile-h=256` (the grid fits) prints nothing. - The FATE APV tests pass. They don't cover liboapv. From 66f94beb0ab7bbc7b5bc3904bb318c062609bd18 Mon Sep 17 00:00:00 2001 From: Vibhoothi <[email protected]> Date: Tue, 10 Nov 2026 15:59:39 +0000 Subject: [PATCH] avcodec/liboapvenc: warn when liboapv enlarges the requested tiles APV allows at most 20x20 tiles in the profiles the wrapper accepts. When the tile-w/tile-h passed in oapv-params give a larger grid, liboapv enlarges the tiles until the grid fits, without reporting it. At 15360x8640, tile-w=512:tile-h=256 (30x34 tiles) is encoded with 768x432 tiles, so the stream does not have the tile layout that was asked for. Repeat liboapv's computation and log the tile size that is used: as a warning when tile-w or tile-h were given, in verbose otherwise, since the default 256x256 tiles are enlarged the same way in frames wider or taller than 5120. Signed-off-by: Vibhoothi <[email protected]> --- libavcodec/liboapvenc.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/libavcodec/liboapvenc.c b/libavcodec/liboapvenc.c index 0f59d65e146..6fc3d0e8958 100644 --- a/libavcodec/liboapvenc.c +++ b/libavcodec/liboapvenc.c @@ -308,6 +308,35 @@ static int apv_metadata_add_payload(const AVCodecContext *avctx, ApvEncContext * return 0; } +/** + * APV allows at most OAPV_MAX_TILE_COLS x OAPV_MAX_TILE_ROWS tiles in the + * profiles this wrapper accepts, and recompute tiles possible and is reported. + */ +static void check_tile_grid(AVCodecContext *avctx, const oapve_param_t *param, + int requested) +{ + const int w = FFALIGN(param->w, OAPV_MB_W); + const int h = FFALIGN(param->h, OAPV_MB_H); + int tile_w = FFMIN(param->tile_w, w); + int tile_h = FFMIN(param->tile_h, h); + const int cols = (w + tile_w - 1) / tile_w; + const int rows = (h + tile_h - 1) / tile_h; + + if (cols <= OAPV_MAX_TILE_COLS && rows <= OAPV_MAX_TILE_ROWS) + return; + + if (cols > OAPV_MAX_TILE_COLS) + tile_w = FFALIGN((w + OAPV_MAX_TILE_COLS - 1) / OAPV_MAX_TILE_COLS, OAPV_MB_W); + if (rows > OAPV_MAX_TILE_ROWS) + tile_h = FFALIGN((h + OAPV_MAX_TILE_ROWS - 1) / OAPV_MAX_TILE_ROWS, OAPV_MB_H); + + av_log(avctx, requested ? AV_LOG_WARNING : AV_LOG_VERBOSE, + "Tile size %dx%d gives a %dx%d tile grid, more than the %dx%d APV " + "allows; liboapv will use %dx%d tiles\n", + param->tile_w, param->tile_h, cols, rows, + OAPV_MAX_TILE_COLS, OAPV_MAX_TILE_ROWS, tile_w, tile_h); +} + /** * Populate the liboapv configuration from AVCodecContext and encoder options. * @@ -403,6 +432,10 @@ static int get_conf(AVCodecContext *avctx, oapve_cdesc_t *cdsc) if (ret < 0) return ret; + check_tile_grid(avctx, &cdsc->param[FRM_IDX], + av_dict_get(apv->oapv_params, "tile-w", NULL, 0) || + av_dict_get(apv->oapv_params, "tile-h", NULL, 0)); + avctx->profile = cdsc->param[FRM_IDX].profile_idc; -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
