summaryrefslogtreecommitdiff
path: root/libavcodec/vaapi_encode_h265.c
diff options
context:
space:
mode:
authorLinjie Fu <linjie.fu@intel.com>2020-05-12 21:47:13 +0800
committerLinjie Fu <linjie.fu@intel.com>2020-07-20 15:27:05 +0800
commit43a08d907ba765677254b4816f246a8ecfd7ff78 (patch)
tree347008227008d05bd8dcc9c0f42ee3c2da5baf1f /libavcodec/vaapi_encode_h265.c
parenta7c2cdf0f6bc53d2bdf05fc92f20415a3de7045f (diff)
lavc/vaapi_encode_h265: add h265 tile encoding support
Default to enable uniform_spacing_flag. Guess level by the tile rows/cols. Supported for ICL+ platforms. Also add documentations. To encode with 4 rows 2 columns: ffmpeg ... -c:v hevc_vaapi -tiles 4x2 ... ffmpeg ... -c:v hevc_vaapi -tile_rows 4 -tile_cols 2 ... Suggested-by: Jun Zhao <mypopydev@gmail.com> Signed-off-by: Linjie Fu <linjie.justin.fu@gmail.com>
Diffstat (limited to 'libavcodec/vaapi_encode_h265.c')
-rw-r--r--libavcodec/vaapi_encode_h265.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 045a0261a1..7aa395fb61 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -63,6 +63,9 @@ typedef struct VAAPIEncodeH265Context {
int level;
int sei;
+ int trows;
+ int tcols;
+
// Derived settings.
int fixed_qp_idr;
int fixed_qp_p;
@@ -344,7 +347,7 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
level = ff_h265_guess_level(ptl, avctx->bit_rate,
ctx->surface_width, ctx->surface_height,
- ctx->nb_slices, 1, 1,
+ ctx->nb_slices, ctx->tile_rows, ctx->tile_cols,
(ctx->b_per_p > 0) + 1);
if (level) {
av_log(avctx, AV_LOG_VERBOSE, "Using level %s.\n", level->name);
@@ -557,6 +560,20 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
pps->pps_loop_filter_across_slices_enabled_flag = 1;
+ if (ctx->tile_rows && ctx->tile_cols) {
+ pps->tiles_enabled_flag = 1;
+ pps->uniform_spacing_flag = 1;
+
+ pps->num_tile_rows_minus1 = ctx->tile_rows - 1;
+ pps->num_tile_columns_minus1 = ctx->tile_cols - 1;
+
+ pps->loop_filter_across_tiles_enabled_flag = 1;
+
+ for (i = 0; i <= pps->num_tile_rows_minus1; i++)
+ pps->row_height_minus1[i] = ctx->row_height[i] - 1;
+ for (i = 0; i <= pps->num_tile_columns_minus1; i++)
+ pps->column_width_minus1[i] = ctx->col_width[i] - 1;
+ }
// Fill VAAPI parameter buffers.
@@ -665,6 +682,13 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
},
};
+ if (pps->tiles_enabled_flag) {
+ for (i = 0; i <= vpic->num_tile_rows_minus1; i++)
+ vpic->row_height_minus1[i] = pps->row_height_minus1[i];
+ for (i = 0; i <= vpic->num_tile_columns_minus1; i++)
+ vpic->column_width_minus1[i] = pps->column_width_minus1[i];
+ }
+
return 0;
}
@@ -1180,6 +1204,11 @@ static av_cold int vaapi_encode_h265_init(AVCodecContext *avctx)
if (priv->qp > 0)
ctx->explicit_qp = priv->qp;
+ if (priv->trows && priv->tcols) {
+ ctx->tile_rows = priv->trows;
+ ctx->tile_cols = priv->tcols;
+ }
+
return ff_vaapi_encode_init(avctx);
}
@@ -1256,6 +1285,13 @@ static const AVOption vaapi_encode_h265_options[] = {
{ .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL },
INT_MIN, INT_MAX, FLAGS, "sei" },
+ { "tiles", "Tile rows x cols",
+ OFFSET(trows), AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, 0, FLAGS },
+ { "tile_rows", "Number of rows for tile encoding",
+ OFFSET(trows), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
+ { "tile_cols", "Number of cols for tile encoding",
+ OFFSET(tcols), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
+
{ NULL },
};