Re: [FFmpeg-devel] [PATCH v4 1/2] avcodec/libvpxenc: add VP9 temporal scalability encoding option
HI, On Mon, Jan 13, 2020 at 4:44 PM James Zern wrote: > Hi, > > On Fri, Jan 10, 2020 at 9:59 AM Wonkap Jang > wrote: > > > > This commit reuses the configuration options for VP8 that enables > > temporal scalability for VP9. It also adds a way to enable three > > preset temporal structures (refer to the documentation for more > > detail) that can be used in offline encoding. > > --- > > doc/encoders.texi | 18 ++- > > libavcodec/libvpxenc.c | 251 + > > 2 files changed, 243 insertions(+), 26 deletions(-) > > > > [...] > > #endif > > @@ -223,8 +231,16 @@ static av_cold void dump_enc_cfg(AVCodecContext > *avctx, > > " %*s%u\n", width, "ts_number_layers:", > cfg->ts_number_layers); > > av_log(avctx, level, > > "\n %*s", width, "ts_target_bitrate:"); > > This should move to the vp8 branch and a new heading added for vp9's > layer_target_bitrate. > > > [...] > > -static int vp8_ts_param_parse(struct vpx_codec_enc_cfg *enccfg, char > *key, char *value) > > +static void set_temporal_layer_pattern(int layering_mode, > > + vpx_codec_enc_cfg_t *cfg, > > + int *layer_flags, > > + int *flag_periodicity) > > +{ > > +switch (layering_mode) { > > +case 2: { > > +/** > > + * 2-layers, 2-frame period. > > + */ > > +int ids[2] = { 0, 1 }; > > these can be static const. > [WJ] OK. > > > +cfg->ts_periodicity = 2; > > +*flag_periodicity = 2; > > +cfg->ts_number_layers = 2; > > +cfg->ts_rate_decimator[0] = 2; > > +cfg->ts_rate_decimator[1] = 1; > > +memcpy(cfg->ts_layer_id, ids, sizeof(ids)); > > + > > +layer_flags[0] = > > + VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF | > > + VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF; > > + > > this line can be removed. > [WJ] OK. > > > +layer_flags[1] = > > +VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_GF | > > +VP8_EFLAG_NO_UPD_LAST | > > +VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_REF_GF; > > +break; > > +} > > +case 3: { > > +/** > > + * 3-layers structure with one reference frame. > > + * This works same as temporal_layering_mode 3. > > + * > > + * 3-layers, 4-frame period. > > + */ > > +int ids[4] = { 0, 2, 1, 2 }; > > +cfg->ts_periodicity = 4; > > +*flag_periodicity = 4; > > +cfg->ts_number_layers = 3; > > +cfg->ts_rate_decimator[0] = 4; > > +cfg->ts_rate_decimator[1] = 2; > > +cfg->ts_rate_decimator[2] = 1; > > +memcpy(cfg->ts_layer_id, ids, sizeof(ids)); > > + > > +/** > > + * 0=L, 1=GF, 2=ARF, > > what about [3]? > [WJ] decimator is for indicating the framerate decimation per temporal layer. There are three temporal layers in this case, no need for [3]. > > > + * Intra-layer prediction disabled. > > + */ > > +layer_flags[0] = > > +VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF | > > +VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF; > > +layer_flags[2] = > > can you reorder this to be in the natural 0...3 order? > [WJ] this is in the order of temporal layer id, just like it is written in vpx_temporal_svc_encoder in libvpx/examples, but I'll make the change as suggested. > > > [...] > > +/** > > + * 0=L, 1=GF, 2=ARF, Intra-layer prediction disabled. > > + */ > > +layer_flags[0] = > > +VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF | > > +VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF; > > +layer_flags[2] = > > same comment here about order. > > > [...] > > + > > +#if (VPX_ENCODER_ABI_VERSION >= 12) && CONFIG_LIBVPX_VP9_ENCODER > > +enccfg->temporal_layering_mode = 1; // only bypass mode is being > supported for now. > > ...mode is supported... > [WJ] gotit. > > > +enccfg->ss_number_layers = 1; // making sure the spatial > scalability is off. Will support this in future. > > this can be TODO: add spatial scalability support. [WJ] gotit. > > > +#endif > > +if (ts_layering_mode) { > > + // make sure the ts_layering_mode comes at the end of the > ts_parameter string to ensure that > > + // correct configuration is done. > > + ctx->ts_layer_flags = av_malloc(sizeof(int) * > VPX_TS_MAX_PERIODICITY); > > prefer sizeof(var). > [WJ] OK. > > > [...] > > > > -if(!avctx->bit_rate) > > -if(avctx->rc_max_rate || avctx->rc_buffer_size || > avctx->rc_initial_buffer_occupancy) { > > +if (!avctx->bit_rate) > > +if (avctx->rc_max_rate || avctx->rc_buffer_size || > avctx->rc_initial_buffer_occupancy) { > > this is unrelated to the change, please remove it. > [WJ] ok. > > > [...] > > +#if VPX_ENCODER_ABI_VERSION >= 12 > > +codecctl_int(avctx,
Re: [FFmpeg-devel] [PATCH v4 1/2] avcodec/libvpxenc: add VP9 temporal scalability encoding option
Hi, On Fri, Jan 10, 2020 at 9:59 AM Wonkap Jang wrote: > > This commit reuses the configuration options for VP8 that enables > temporal scalability for VP9. It also adds a way to enable three > preset temporal structures (refer to the documentation for more > detail) that can be used in offline encoding. > --- > doc/encoders.texi | 18 ++- > libavcodec/libvpxenc.c | 251 + > 2 files changed, 243 insertions(+), 26 deletions(-) > > [...] > #endif > @@ -223,8 +231,16 @@ static av_cold void dump_enc_cfg(AVCodecContext *avctx, > " %*s%u\n", width, "ts_number_layers:", cfg->ts_number_layers); > av_log(avctx, level, > "\n %*s", width, "ts_target_bitrate:"); This should move to the vp8 branch and a new heading added for vp9's layer_target_bitrate. > [...] > -static int vp8_ts_param_parse(struct vpx_codec_enc_cfg *enccfg, char *key, > char *value) > +static void set_temporal_layer_pattern(int layering_mode, > + vpx_codec_enc_cfg_t *cfg, > + int *layer_flags, > + int *flag_periodicity) > +{ > +switch (layering_mode) { > +case 2: { > +/** > + * 2-layers, 2-frame period. > + */ > +int ids[2] = { 0, 1 }; these can be static const. > +cfg->ts_periodicity = 2; > +*flag_periodicity = 2; > +cfg->ts_number_layers = 2; > +cfg->ts_rate_decimator[0] = 2; > +cfg->ts_rate_decimator[1] = 1; > +memcpy(cfg->ts_layer_id, ids, sizeof(ids)); > + > +layer_flags[0] = > + VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF | > + VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF; > + this line can be removed. > +layer_flags[1] = > +VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_GF | > +VP8_EFLAG_NO_UPD_LAST | > +VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_REF_GF; > +break; > +} > +case 3: { > +/** > + * 3-layers structure with one reference frame. > + * This works same as temporal_layering_mode 3. > + * > + * 3-layers, 4-frame period. > + */ > +int ids[4] = { 0, 2, 1, 2 }; > +cfg->ts_periodicity = 4; > +*flag_periodicity = 4; > +cfg->ts_number_layers = 3; > +cfg->ts_rate_decimator[0] = 4; > +cfg->ts_rate_decimator[1] = 2; > +cfg->ts_rate_decimator[2] = 1; > +memcpy(cfg->ts_layer_id, ids, sizeof(ids)); > + > +/** > + * 0=L, 1=GF, 2=ARF, what about [3]? > + * Intra-layer prediction disabled. > + */ > +layer_flags[0] = > +VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF | > +VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF; > +layer_flags[2] = can you reorder this to be in the natural 0...3 order? > [...] > +/** > + * 0=L, 1=GF, 2=ARF, Intra-layer prediction disabled. > + */ > +layer_flags[0] = > +VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF | > +VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF; > +layer_flags[2] = same comment here about order. > [...] > + > +#if (VPX_ENCODER_ABI_VERSION >= 12) && CONFIG_LIBVPX_VP9_ENCODER > +enccfg->temporal_layering_mode = 1; // only bypass mode is being > supported for now. ...mode is supported... > +enccfg->ss_number_layers = 1; // making sure the spatial scalability is > off. Will support this in future. this can be TODO: add spatial scalability support. > +#endif > +if (ts_layering_mode) { > + // make sure the ts_layering_mode comes at the end of the ts_parameter > string to ensure that > + // correct configuration is done. > + ctx->ts_layer_flags = av_malloc(sizeof(int) * VPX_TS_MAX_PERIODICITY); prefer sizeof(var). > [...] > > -if(!avctx->bit_rate) > -if(avctx->rc_max_rate || avctx->rc_buffer_size || > avctx->rc_initial_buffer_occupancy) { > +if (!avctx->bit_rate) > +if (avctx->rc_max_rate || avctx->rc_buffer_size || > avctx->rc_initial_buffer_occupancy) { this is unrelated to the change, please remove it. > [...] > +#if VPX_ENCODER_ABI_VERSION >= 12 > +codecctl_int(avctx, VP9E_SET_SVC, 1); > +codecctl_intp(avctx, VP9E_SET_SVC_PARAMETERS, (int *) _params); drop the space after the cast. > [...] > +#if CONFIG_LIBVPX_VP9_ENCODER && VPX_ENCODER_ABI_VERSION >= 12 > +else if (avctx->codec_id == AV_CODEC_ID_VP9) { > +codecctl_intp(avctx, VP9E_SET_SVC_LAYER_ID, (int *) _id); drop the space after the cast. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v4 1/2] avcodec/libvpxenc: add VP9 temporal scalability encoding option
On Fri, Jan 10, 2020 at 9:59 AM Wonkap Jang wrote: > This commit reuses the configuration options for VP8 that enables > temporal scalability for VP9. It also adds a way to enable three > preset temporal structures (refer to the documentation for more > detail) that can be used in offline encoding. > --- > doc/encoders.texi | 18 ++- > libavcodec/libvpxenc.c | 251 + > 2 files changed, 243 insertions(+), 26 deletions(-) > > diff --git a/doc/encoders.texi b/doc/encoders.texi > index 61e674cf96..88429aed4c 100644 > --- a/doc/encoders.texi > +++ b/doc/encoders.texi > @@ -1885,8 +1885,6 @@ Enable error resiliency features. > Increase sharpness at the expense of lower PSNR. > The valid range is [0, 7]. > > -@item VP8-specific options > -@table @option > @item ts-parameters > Sets the temporal scalability configuration using a :-separated list of > key=value pairs. For example, to specify temporal scalability parameters > @@ -1894,7 +1892,7 @@ with @code{ffmpeg}: > @example > ffmpeg -i INPUT -c:v libvpx -ts-parameters ts_number_layers=3:\ > ts_target_bitrate=250,500,1000:ts_rate_decimator=4,2,1:\ > -ts_periodicity=4:ts_layer_id=0,2,1,2 OUTPUT > +ts_periodicity=4:ts_layer_id=0,2,1,2:ts_layering_mode=3 OUTPUT > @end example > Below is a brief explanation of each of the parameters, please > refer to @code{struct vpx_codec_enc_cfg} in @code{vpx/vpx_encoder.h} for > more > @@ -1911,6 +1909,20 @@ Frame rate decimation factor for each temporal > layer. > Length of the sequence defining frame temporal layer membership. > @item ts_layer_id > Template defining the membership of frames to temporal layers. > +@item ts_layering_mode > +(optional) Selecting the temporal structure from a set of pre-defined > temporal layering modes. > +Currently supports the following options. > +@table @option > +@item 0 > +No temporal layering flags are provided internally, > +relies on flags being passed in using metadata in AVFrame. > +@item 2 > +Two temporal layers. 0-1... > +@item 3 > +Three temporal layers. 0-2-1-2...; with single reference frame. > +@item 4 > +Same as option "3", except there is a dependency between > +the two temporal layer 2 frames within the temporal period. > @end table > @end table > > diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c > index 0b8a070304..14cc1e7158 100644 > --- a/libavcodec/libvpxenc.c > +++ b/libavcodec/libvpxenc.c > @@ -100,7 +100,9 @@ typedef struct VPxEncoderContext { > int rc_undershoot_pct; > int rc_overshoot_pct; > > -AVDictionary *vp8_ts_parameters; > +AVDictionary *vpx_ts_parameters; > +int *ts_layer_flags; > +int current_temporal_idx; > > // VP9-only > int lossless; > @@ -137,6 +139,7 @@ static const char *const ctlidstr[] = { > [VP8E_SET_CQ_LEVEL] = "VP8E_SET_CQ_LEVEL", > [VP8E_SET_MAX_INTRA_BITRATE_PCT] = "VP8E_SET_MAX_INTRA_BITRATE_PCT", > [VP8E_SET_SHARPNESS] = "VP8E_SET_SHARPNESS", > +[VP8E_SET_TEMPORAL_LAYER_ID] = "VP8E_SET_TEMPORAL_LAYER_ID", > #if CONFIG_LIBVPX_VP9_ENCODER > [VP9E_SET_LOSSLESS]= "VP9E_SET_LOSSLESS", > [VP9E_SET_TILE_COLUMNS]= "VP9E_SET_TILE_COLUMNS", > @@ -144,6 +147,11 @@ static const char *const ctlidstr[] = { > [VP9E_SET_FRAME_PARALLEL_DECODING] = > "VP9E_SET_FRAME_PARALLEL_DECODING", > [VP9E_SET_AQ_MODE] = "VP9E_SET_AQ_MODE", > [VP9E_SET_COLOR_SPACE] = "VP9E_SET_COLOR_SPACE", > +[VP9E_SET_SVC_LAYER_ID]= "VP9E_SET_SVC_LAYER_ID", > +#if VPX_ENCODER_ABI_VERSION >= 12 > +[VP9E_SET_SVC_PARAMETERS] = "VP9E_SET_SVC_PARAMETERS", > +#endif > +[VP9E_SET_SVC] = "VP9E_SET_SVC", > #if VPX_ENCODER_ABI_VERSION >= 11 > [VP9E_SET_COLOR_RANGE] = "VP9E_SET_COLOR_RANGE", > #endif > @@ -223,8 +231,16 @@ static av_cold void dump_enc_cfg(AVCodecContext > *avctx, > " %*s%u\n", width, "ts_number_layers:", > cfg->ts_number_layers); > av_log(avctx, level, > "\n %*s", width, "ts_target_bitrate:"); > -for (i = 0; i < VPX_TS_MAX_LAYERS; i++) > -av_log(avctx, level, "%u ", cfg->ts_target_bitrate[i]); > +if (avctx->codec_id == AV_CODEC_ID_VP8) { > +for (i = 0; i < VPX_TS_MAX_LAYERS; i++) > +av_log(avctx, level, "%u ", cfg->ts_target_bitrate[i]); > +} > +#if (VPX_ENCODER_ABI_VERSION >= 12) && CONFIG_LIBVPX_VP9_ENCODER > +if (avctx->codec_id == AV_CODEC_ID_VP9) { > +for (i = 0; i < VPX_TS_MAX_LAYERS; i++) > +av_log(avctx, level, "%u ", cfg->layer_target_bitrate[i]); > +} > +#endif > av_log(avctx, level, "\n"); > av_log(avctx, level, > "\n %*s", width, "ts_rate_decimator:"); > @@ -346,6 +362,8 @@ static av_cold int vpx_free(AVCodecContext *avctx) > } > #endif > > +av_freep(>ts_layer_flags); > + > vpx_codec_destroy(>encoder); > if (ctx->is_alpha)
[FFmpeg-devel] [PATCH v4 1/2] avcodec/libvpxenc: add VP9 temporal scalability encoding option
This commit reuses the configuration options for VP8 that enables temporal scalability for VP9. It also adds a way to enable three preset temporal structures (refer to the documentation for more detail) that can be used in offline encoding. --- doc/encoders.texi | 18 ++- libavcodec/libvpxenc.c | 251 + 2 files changed, 243 insertions(+), 26 deletions(-) diff --git a/doc/encoders.texi b/doc/encoders.texi index 61e674cf96..88429aed4c 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -1885,8 +1885,6 @@ Enable error resiliency features. Increase sharpness at the expense of lower PSNR. The valid range is [0, 7]. -@item VP8-specific options -@table @option @item ts-parameters Sets the temporal scalability configuration using a :-separated list of key=value pairs. For example, to specify temporal scalability parameters @@ -1894,7 +1892,7 @@ with @code{ffmpeg}: @example ffmpeg -i INPUT -c:v libvpx -ts-parameters ts_number_layers=3:\ ts_target_bitrate=250,500,1000:ts_rate_decimator=4,2,1:\ -ts_periodicity=4:ts_layer_id=0,2,1,2 OUTPUT +ts_periodicity=4:ts_layer_id=0,2,1,2:ts_layering_mode=3 OUTPUT @end example Below is a brief explanation of each of the parameters, please refer to @code{struct vpx_codec_enc_cfg} in @code{vpx/vpx_encoder.h} for more @@ -1911,6 +1909,20 @@ Frame rate decimation factor for each temporal layer. Length of the sequence defining frame temporal layer membership. @item ts_layer_id Template defining the membership of frames to temporal layers. +@item ts_layering_mode +(optional) Selecting the temporal structure from a set of pre-defined temporal layering modes. +Currently supports the following options. +@table @option +@item 0 +No temporal layering flags are provided internally, +relies on flags being passed in using metadata in AVFrame. +@item 2 +Two temporal layers. 0-1... +@item 3 +Three temporal layers. 0-2-1-2...; with single reference frame. +@item 4 +Same as option "3", except there is a dependency between +the two temporal layer 2 frames within the temporal period. @end table @end table diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c index 0b8a070304..14cc1e7158 100644 --- a/libavcodec/libvpxenc.c +++ b/libavcodec/libvpxenc.c @@ -100,7 +100,9 @@ typedef struct VPxEncoderContext { int rc_undershoot_pct; int rc_overshoot_pct; -AVDictionary *vp8_ts_parameters; +AVDictionary *vpx_ts_parameters; +int *ts_layer_flags; +int current_temporal_idx; // VP9-only int lossless; @@ -137,6 +139,7 @@ static const char *const ctlidstr[] = { [VP8E_SET_CQ_LEVEL] = "VP8E_SET_CQ_LEVEL", [VP8E_SET_MAX_INTRA_BITRATE_PCT] = "VP8E_SET_MAX_INTRA_BITRATE_PCT", [VP8E_SET_SHARPNESS] = "VP8E_SET_SHARPNESS", +[VP8E_SET_TEMPORAL_LAYER_ID] = "VP8E_SET_TEMPORAL_LAYER_ID", #if CONFIG_LIBVPX_VP9_ENCODER [VP9E_SET_LOSSLESS]= "VP9E_SET_LOSSLESS", [VP9E_SET_TILE_COLUMNS]= "VP9E_SET_TILE_COLUMNS", @@ -144,6 +147,11 @@ static const char *const ctlidstr[] = { [VP9E_SET_FRAME_PARALLEL_DECODING] = "VP9E_SET_FRAME_PARALLEL_DECODING", [VP9E_SET_AQ_MODE] = "VP9E_SET_AQ_MODE", [VP9E_SET_COLOR_SPACE] = "VP9E_SET_COLOR_SPACE", +[VP9E_SET_SVC_LAYER_ID]= "VP9E_SET_SVC_LAYER_ID", +#if VPX_ENCODER_ABI_VERSION >= 12 +[VP9E_SET_SVC_PARAMETERS] = "VP9E_SET_SVC_PARAMETERS", +#endif +[VP9E_SET_SVC] = "VP9E_SET_SVC", #if VPX_ENCODER_ABI_VERSION >= 11 [VP9E_SET_COLOR_RANGE] = "VP9E_SET_COLOR_RANGE", #endif @@ -223,8 +231,16 @@ static av_cold void dump_enc_cfg(AVCodecContext *avctx, " %*s%u\n", width, "ts_number_layers:", cfg->ts_number_layers); av_log(avctx, level, "\n %*s", width, "ts_target_bitrate:"); -for (i = 0; i < VPX_TS_MAX_LAYERS; i++) -av_log(avctx, level, "%u ", cfg->ts_target_bitrate[i]); +if (avctx->codec_id == AV_CODEC_ID_VP8) { +for (i = 0; i < VPX_TS_MAX_LAYERS; i++) +av_log(avctx, level, "%u ", cfg->ts_target_bitrate[i]); +} +#if (VPX_ENCODER_ABI_VERSION >= 12) && CONFIG_LIBVPX_VP9_ENCODER +if (avctx->codec_id == AV_CODEC_ID_VP9) { +for (i = 0; i < VPX_TS_MAX_LAYERS; i++) +av_log(avctx, level, "%u ", cfg->layer_target_bitrate[i]); +} +#endif av_log(avctx, level, "\n"); av_log(avctx, level, "\n %*s", width, "ts_rate_decimator:"); @@ -346,6 +362,8 @@ static av_cold int vpx_free(AVCodecContext *avctx) } #endif +av_freep(>ts_layer_flags); + vpx_codec_destroy(>encoder); if (ctx->is_alpha) { vpx_codec_destroy(>encoder_alpha); @@ -370,23 +388,154 @@ static void vp8_ts_parse_int_array(int *dest, char *value, size_t value_len, int } } -static int vp8_ts_param_parse(struct vpx_codec_enc_cfg *enccfg, char *key, char *value) +static void