summaryrefslogtreecommitdiff
path: root/graphics/ffmpeg/patches/patch-libavcodec_libsvtav1_c
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/ffmpeg/patches/patch-libavcodec_libsvtav1_c')
-rw-r--r--graphics/ffmpeg/patches/patch-libavcodec_libsvtav1_c389
1 files changed, 0 insertions, 389 deletions
diff --git a/graphics/ffmpeg/patches/patch-libavcodec_libsvtav1_c b/graphics/ffmpeg/patches/patch-libavcodec_libsvtav1_c
deleted file mode 100644
index 9170e88..0000000
--- a/graphics/ffmpeg/patches/patch-libavcodec_libsvtav1_c
+++ /dev/null
@@ -1,389 +0,0 @@
1- avcodec/libsvtav1: Fix duplicate definition of caps_internal
2- avcodec/libsvtav1: make coded GOP type configurable
3- avcodec/libsvtav1: Fix value range for rc mode
4- avcodec/libsvtav1: properly enforce CQP mode when set in wrapper
5- avcodec/libsvtav1: add a svtav1-params option to pass a list of key=value parameters
6- avcodec/libsvtav1: update some options and defaults
7- avcodec/libsvtav1: deprecate some options
8- avcodec/libsvtav1: fine tune qp mode settings
9- avcodec/libsvtav1: pass color description info
10- avcodec/libsvtav1: give svtav1-params priority over avctx values
11- avcodec/libsvtav1: pass pict_type to library
12- avcodec/libsvtav1: add support for setting chroma sample location
13- avcodec/libsvtav1: update avctx bit rate according to RC mode
14- avcodec/libsvtav1: signal CPB properties through side data
15- avcodec/libsvtav1: properly initialize the flush EbBufferHeaderType struct
16- avcodec/libsvtav1: remove compressed_ten_bit_format and simplify alloc_buffer
17- avcodec/libsvtav1: replace vbv_bufsize with maximum_buffer_size_ms
18- avcodec/libsvtav1: only set max_buf_sz if both bitrate and rc_buf_sz is set
19- avcodec/libsvtav1: don't force a default value for deprecated options
20
21Index: libavcodec/libsvtav1.c
22--- libavcodec/libsvtav1.c.orig
23+++ libavcodec/libsvtav1.c
24@@ -60,17 +60,20 @@ typedef struct SvtContext {
25 EOS_STATUS eos_flag;
26
27 // User options.
28+ AVDictionary *svtav1_opts;
29+#if FF_API_SVTAV1_OPTS
30 int hierarchical_level;
31 int la_depth;
32- int enc_mode;
33- int rc_mode;
34 int scd;
35- int qp;
36
37 int tier;
38
39 int tile_columns;
40 int tile_rows;
41+#endif
42+ int enc_mode;
43+ int crf;
44+ int qp;
45 } SvtContext;
46
47 static const struct {
48@@ -120,16 +123,12 @@ static int svt_print_error(void *log_ctx, EbErrorType
49
50 static int alloc_buffer(EbSvtAv1EncConfiguration *config, SvtContext *svt_enc)
51 {
52- const int pack_mode_10bit =
53- (config->encoder_bit_depth > 8) && (config->compressed_ten_bit_format == 0) ? 1 : 0;
54- const size_t luma_size_8bit =
55- config->source_width * config->source_height * (1 << pack_mode_10bit);
56- const size_t luma_size_10bit =
57- (config->encoder_bit_depth > 8 && pack_mode_10bit == 0) ? luma_size_8bit : 0;
58+ const size_t luma_size = config->source_width * config->source_height *
59+ (config->encoder_bit_depth > 8 ? 2 : 1);
60
61 EbSvtIOFormat *in_data;
62
63- svt_enc->raw_size = (luma_size_8bit + luma_size_10bit) * 3 / 2;
64+ svt_enc->raw_size = luma_size * 3 / 2;
65
66 // allocate buffer for in and out
67 svt_enc->in_buf = av_mallocz(sizeof(*svt_enc->in_buf));
68@@ -151,11 +150,132 @@ static int config_enc_params(EbSvtAv1EncConfiguration
69 {
70 SvtContext *svt_enc = avctx->priv_data;
71 const AVPixFmtDescriptor *desc;
72+ AVDictionaryEntry *en = NULL;
73
74+ // Update param from options
75+#if FF_API_SVTAV1_OPTS
76+ if (svt_enc->hierarchical_level >= 0)
77+ param->hierarchical_levels = svt_enc->hierarchical_level;
78+ if (svt_enc->tier >= 0)
79+ param->tier = svt_enc->tier;
80+ if (svt_enc->scd >= 0)
81+ param->scene_change_detection = svt_enc->scd;
82+ if (svt_enc->tile_columns >= 0)
83+ param->tile_columns = svt_enc->tile_columns;
84+ if (svt_enc->tile_rows >= 0)
85+ param->tile_rows = svt_enc->tile_rows;
86+
87+ if (svt_enc->la_depth >= 0)
88+ param->look_ahead_distance = svt_enc->la_depth;
89+#endif
90+
91+ if (svt_enc->enc_mode >= 0)
92+ param->enc_mode = svt_enc->enc_mode;
93+
94+ if (avctx->bit_rate) {
95+ param->target_bit_rate = avctx->bit_rate;
96+ if (avctx->rc_max_rate != avctx->bit_rate)
97+ param->rate_control_mode = 1;
98+ else
99+ param->rate_control_mode = 2;
100+
101+ param->max_qp_allowed = avctx->qmax;
102+ param->min_qp_allowed = avctx->qmin;
103+ }
104+ param->max_bit_rate = avctx->rc_max_rate;
105+ if (avctx->bit_rate && avctx->rc_buffer_size)
106+ param->maximum_buffer_size_ms = avctx->rc_buffer_size * 1000LL / avctx->bit_rate;
107+
108+ if (svt_enc->crf > 0) {
109+ param->qp = svt_enc->crf;
110+ param->rate_control_mode = 0;
111+ } else if (svt_enc->qp > 0) {
112+ param->qp = svt_enc->qp;
113+ param->rate_control_mode = 0;
114+ param->enable_adaptive_quantization = 0;
115+ }
116+
117+ desc = av_pix_fmt_desc_get(avctx->pix_fmt);
118+ param->color_primaries = avctx->color_primaries;
119+ param->matrix_coefficients = (desc->flags & AV_PIX_FMT_FLAG_RGB) ?
120+ AVCOL_SPC_RGB : avctx->colorspace;
121+ param->transfer_characteristics = avctx->color_trc;
122+
123+ if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED)
124+ param->color_range = avctx->color_range == AVCOL_RANGE_JPEG;
125+ else
126+ param->color_range = !!(desc->flags & AV_PIX_FMT_FLAG_RGB);
127+
128+#if SVT_AV1_CHECK_VERSION(1, 0, 0)
129+ if (avctx->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED) {
130+ const char *name =
131+ av_chroma_location_name(avctx->chroma_sample_location);
132+
133+ switch (avctx->chroma_sample_location) {
134+ case AVCHROMA_LOC_LEFT:
135+ param->chroma_sample_position = EB_CSP_VERTICAL;
136+ break;
137+ case AVCHROMA_LOC_TOPLEFT:
138+ param->chroma_sample_position = EB_CSP_COLOCATED;
139+ break;
140+ default:
141+ if (!name)
142+ break;
143+
144+ av_log(avctx, AV_LOG_WARNING,
145+ "Specified chroma sample location %s is unsupported "
146+ "on the AV1 bit stream level. Usage of a container that "
147+ "allows passing this information - such as Matroska - "
148+ "is recommended.\n",
149+ name);
150+ break;
151+ }
152+ }
153+#endif
154+
155+ if (avctx->profile != FF_PROFILE_UNKNOWN)
156+ param->profile = avctx->profile;
157+
158+ if (avctx->level != FF_LEVEL_UNKNOWN)
159+ param->level = avctx->level;
160+
161+ if (avctx->gop_size > 0)
162+ param->intra_period_length = avctx->gop_size - 1;
163+
164+ if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
165+ param->frame_rate_numerator = avctx->framerate.num;
166+ param->frame_rate_denominator = avctx->framerate.den;
167+ } else {
168+ param->frame_rate_numerator = avctx->time_base.den;
169+ param->frame_rate_denominator = avctx->time_base.num * avctx->ticks_per_frame;
170+ }
171+
172+ /* 2 = IDR, closed GOP, 1 = CRA, open GOP */
173+ param->intra_refresh_type = avctx->flags & AV_CODEC_FLAG_CLOSED_GOP ? 2 : 1;
174+
175+#if SVT_AV1_CHECK_VERSION(0, 9, 1)
176+ while ((en = av_dict_get(svt_enc->svtav1_opts, "", en, AV_DICT_IGNORE_SUFFIX))) {
177+ EbErrorType ret = svt_av1_enc_parse_parameter(param, en->key, en->value);
178+ if (ret != EB_ErrorNone) {
179+ int level = (avctx->err_recognition & AV_EF_EXPLODE) ? AV_LOG_ERROR : AV_LOG_WARNING;
180+ av_log(avctx, level, "Error parsing option %s: %s.\n", en->key, en->value);
181+ if (avctx->err_recognition & AV_EF_EXPLODE)
182+ return AVERROR(EINVAL);
183+ }
184+ }
185+#else
186+ if ((en = av_dict_get(svt_enc->svtav1_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
187+ int level = (avctx->err_recognition & AV_EF_EXPLODE) ? AV_LOG_ERROR : AV_LOG_WARNING;
188+ av_log(avctx, level, "svt-params needs libavcodec to be compiled with SVT-AV1 "
189+ "headers >= 0.9.1.\n");
190+ if (avctx->err_recognition & AV_EF_EXPLODE)
191+ return AVERROR(ENOSYS);
192+ }
193+#endif
194+
195 param->source_width = avctx->width;
196 param->source_height = avctx->height;
197
198- desc = av_pix_fmt_desc_get(avctx->pix_fmt);
199 param->encoder_bit_depth = desc->comp[0].depth;
200
201 if (desc->log2_chroma_w == 1 && desc->log2_chroma_h == 1)
202@@ -169,12 +289,6 @@ static int config_enc_params(EbSvtAv1EncConfiguration
203 return AVERROR(EINVAL);
204 }
205
206- if (avctx->profile != FF_PROFILE_UNKNOWN)
207- param->profile = avctx->profile;
208-
209- if (avctx->level != FF_LEVEL_UNKNOWN)
210- param->level = avctx->level;
211-
212 if ((param->encoder_color_format == EB_YUV422 || param->encoder_bit_depth > 10)
213 && param->profile != FF_PROFILE_AV1_PROFESSIONAL ) {
214 av_log(avctx, AV_LOG_WARNING, "Forcing Professional profile\n");
215@@ -184,40 +298,21 @@ static int config_enc_params(EbSvtAv1EncConfiguration
216 param->profile = FF_PROFILE_AV1_HIGH;
217 }
218
219- // Update param from options
220- param->hierarchical_levels = svt_enc->hierarchical_level;
221- param->enc_mode = svt_enc->enc_mode;
222- param->tier = svt_enc->tier;
223- param->rate_control_mode = svt_enc->rc_mode;
224- param->scene_change_detection = svt_enc->scd;
225- param->qp = svt_enc->qp;
226+ avctx->bit_rate = param->rate_control_mode > 0 ?
227+ param->target_bit_rate : 0;
228+ avctx->rc_max_rate = param->max_bit_rate;
229+ avctx->rc_buffer_size = param->maximum_buffer_size_ms * avctx->bit_rate / 1000LL;
230
231- param->target_bit_rate = avctx->bit_rate;
232+ if (avctx->bit_rate || avctx->rc_max_rate || avctx->rc_buffer_size) {
233+ AVCPBProperties *cpb_props = ff_add_cpb_side_data(avctx);
234+ if (!cpb_props)
235+ return AVERROR(ENOMEM);
236
237- if (avctx->gop_size > 0)
238- param->intra_period_length = avctx->gop_size - 1;
239-
240- if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
241- param->frame_rate_numerator = avctx->framerate.num;
242- param->frame_rate_denominator = avctx->framerate.den;
243- } else {
244- param->frame_rate_numerator = avctx->time_base.den;
245- param->frame_rate_denominator = avctx->time_base.num * avctx->ticks_per_frame;
246+ cpb_props->buffer_size = avctx->rc_buffer_size;
247+ cpb_props->max_bitrate = avctx->rc_max_rate;
248+ cpb_props->avg_bitrate = avctx->bit_rate;
249 }
250
251- if (param->rate_control_mode) {
252- param->max_qp_allowed = avctx->qmax;
253- param->min_qp_allowed = avctx->qmin;
254- }
255-
256- param->intra_refresh_type = 2; /* Real keyframes only */
257-
258- if (svt_enc->la_depth >= 0)
259- param->look_ahead_distance = svt_enc->la_depth;
260-
261- param->tile_columns = svt_enc->tile_columns;
262- param->tile_rows = svt_enc->tile_rows;
263-
264 return 0;
265 }
266
267@@ -330,11 +425,8 @@ static int eb_send_frame(AVCodecContext *avctx, const
268 if (svt_enc->eos_flag == EOS_SENT)
269 return 0;
270
271- headerPtrLast.n_alloc_len = 0;
272- headerPtrLast.n_filled_len = 0;
273- headerPtrLast.n_tick_count = 0;
274- headerPtrLast.p_app_private = NULL;
275- headerPtrLast.p_buffer = NULL;
276+ memset(&headerPtrLast, 0, sizeof(headerPtrLast));
277+ headerPtrLast.pic_type = EB_AV1_INVALID_PICTURE;
278 headerPtrLast.flags = EB_BUFFERFLAG_EOS;
279
280 svt_av1_enc_send_picture(svt_enc->svt_handle, &headerPtrLast);
281@@ -350,6 +442,16 @@ static int eb_send_frame(AVCodecContext *avctx, const
282 headerPtr->p_app_private = NULL;
283 headerPtr->pts = frame->pts;
284
285+ switch (frame->pict_type) {
286+ case AV_PICTURE_TYPE_I:
287+ headerPtr->pic_type = EB_AV1_KEY_PICTURE;
288+ break;
289+ default:
290+ // Actually means auto, or default.
291+ headerPtr->pic_type = EB_AV1_INVALID_PICTURE;
292+ break;
293+ }
294+
295 svt_av1_enc_send_picture(svt_enc->svt_handle, headerPtr);
296
297 return 0;
298@@ -472,21 +574,22 @@ static av_cold int eb_enc_close(AVCodecContext *avctx)
299 #define OFFSET(x) offsetof(SvtContext, x)
300 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
301 static const AVOption options[] = {
302- { "hielevel", "Hierarchical prediction levels setting", OFFSET(hierarchical_level),
303- AV_OPT_TYPE_INT, { .i64 = 4 }, 3, 4, VE , "hielevel"},
304+#if FF_API_SVTAV1_OPTS
305+ { "hielevel", "Hierarchical prediction levels setting (Deprecated, use svtav1-params)", OFFSET(hierarchical_level),
306+ AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 4, VE | AV_OPT_FLAG_DEPRECATED , "hielevel"},
307 { "3level", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 3 }, INT_MIN, INT_MAX, VE, "hielevel" },
308 { "4level", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 4 }, INT_MIN, INT_MAX, VE, "hielevel" },
309
310- { "la_depth", "Look ahead distance [0, 120]", OFFSET(la_depth),
311- AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 120, VE },
312+ { "la_depth", "Look ahead distance [0, 120] (Deprecated, use svtav1-params)", OFFSET(la_depth),
313+ AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 120, VE | AV_OPT_FLAG_DEPRECATED },
314
315- { "preset", "Encoding preset [0, 8]",
316- OFFSET(enc_mode), AV_OPT_TYPE_INT, { .i64 = MAX_ENC_PRESET }, 0, MAX_ENC_PRESET, VE },
317-
318- { "tier", "Set operating point tier", OFFSET(tier),
319- AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE, "tier" },
320+ { "tier", "Set operating point tier (Deprecated, use svtav1-params)", OFFSET(tier),
321+ AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE | AV_OPT_FLAG_DEPRECATED, "tier" },
322 { "main", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, VE, "tier" },
323 { "high", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, VE, "tier" },
324+#endif
325+ { "preset", "Encoding preset",
326+ OFFSET(enc_mode), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, MAX_ENC_PRESET, VE },
327
328 FF_AV1_PROFILE_OPTS
329
330@@ -518,21 +621,20 @@ static const AVOption options[] = {
331 { LEVEL("7.3", 73) },
332 #undef LEVEL
333
334- { "rc", "Bit rate control mode", OFFSET(rc_mode),
335- AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 3, VE , "rc"},
336- { "cqp", "Constant quantizer", 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, VE, "rc" },
337- { "vbr", "Variable Bit Rate, use a target bitrate for the entire stream", 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, "rc" },
338- { "cvbr", "Constrained Variable Bit Rate, use a target bitrate for each GOP", 0, AV_OPT_TYPE_CONST,{ .i64 = 2 }, INT_MIN, INT_MAX, VE, "rc" },
339+ { "crf", "Constant Rate Factor value", OFFSET(crf),
340+ AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 63, VE },
341+ { "qp", "Initial Quantizer level value", OFFSET(qp),
342+ AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 63, VE },
343+#if FF_API_SVTAV1_OPTS
344+ { "sc_detection", "Scene change detection (Deprecated, use svtav1-params)", OFFSET(scd),
345+ AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE | AV_OPT_FLAG_DEPRECATED },
346
347- { "qp", "Quantizer to use with cqp rate control mode", OFFSET(qp),
348- AV_OPT_TYPE_INT, { .i64 = 50 }, 0, 63, VE },
349+ { "tile_columns", "Log2 of number of tile columns to use (Deprecated, use svtav1-params)", OFFSET(tile_columns), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 4, VE | AV_OPT_FLAG_DEPRECATED },
350+ { "tile_rows", "Log2 of number of tile rows to use (Deprecated, use svtav1-params)", OFFSET(tile_rows), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 6, VE | AV_OPT_FLAG_DEPRECATED },
351+#endif
352
353- { "sc_detection", "Scene change detection", OFFSET(scd),
354- AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
355+ { "svtav1-params", "Set the SVT-AV1 configuration using a :-separated list of key=value parameters", OFFSET(svtav1_opts), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE },
356
357- { "tile_columns", "Log2 of number of tile columns to use", OFFSET(tile_columns), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 4, VE},
358- { "tile_rows", "Log2 of number of tile rows to use", OFFSET(tile_rows), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 6, VE},
359-
360 {NULL},
361 };
362
363@@ -544,9 +646,10 @@ static const AVClass class = {
364 };
365
366 static const AVCodecDefault eb_enc_defaults[] = {
367- { "b", "7M" },
368+ { "b", "0" },
369+ { "flags", "+cgop" },
370 { "g", "-1" },
371- { "qmin", "0" },
372+ { "qmin", "1" },
373 { "qmax", "63" },
374 { NULL },
375 };
376@@ -561,12 +664,11 @@ AVCodec ff_libsvtav1_encoder = {
377 .receive_packet = eb_receive_packet,
378 .close = eb_enc_close,
379 .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_OTHER_THREADS,
380- .caps_internal = FF_CODEC_CAP_AUTO_THREADS,
381+ .caps_internal = FF_CODEC_CAP_AUTO_THREADS | FF_CODEC_CAP_INIT_CLEANUP,
382 .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P,
383 AV_PIX_FMT_YUV420P10,
384 AV_PIX_FMT_NONE },
385 .priv_class = &class,
386 .defaults = eb_enc_defaults,
387- .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
388 .wrapper_name = "libsvtav1",
389 };