Message ID | 20201116223546.1745620-1-wonkap@google.com |
---|---|
State | Superseded |
Headers | show |
Series | [FFmpeg-devel,v1] avcodec/libvpxenc: add a way to set VP9E_SET_SVC_REF_FRAME_CONFIG. | expand |
Context | Check | Description |
---|---|---|
andriy/x86_make | success | Make finished |
andriy/x86_make_fate | success | Make fate finished |
andriy/PPC64_make | success | Make finished |
Hi, On Mon, Nov 16, 2020 at 2:36 PM Wonkap Jang <wonkap-at-google.com@ffmpeg.org> wrote: > > In order to fine-control referencing schemes in VP9 encoding, there > is a need to use VP9E_SET_SVC_REF_FRAME_CONFIG method. This commit > provides a way to use the API through frame metadata. > --- > libavcodec/libvpxenc.c | 77 ++++++++++++++++++++++++++++++++++++++++++ The documentation could use an update too. Maybe some of the earlier per-frame metadata was missed. > 1 file changed, 77 insertions(+) > > diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c > index a7c76eb835..dbe399bf72 100644 > --- a/libavcodec/libvpxenc.c > +++ b/libavcodec/libvpxenc.c > @@ -125,6 +125,11 @@ typedef struct VPxEncoderContext { > * encounter a frame with ROI side data. > */ > int roi_warned; > + > +#if (VPX_ENCODER_ABI_VERSION >= 12) && CONFIG_LIBVPX_VP9_ENCODER > + vpx_svc_ref_frame_config_t ref_frame_config; > + AVDictionary *vpx_ref_frame_config; > +#endif > } VPxContext; > > /** String mappings for enum vp8e_enc_control_id */ > @@ -152,6 +157,7 @@ static const char *const ctlidstr[] = { > [VP9E_SET_SVC_LAYER_ID] = "VP9E_SET_SVC_LAYER_ID", > #if VPX_ENCODER_ABI_VERSION >= 12 This check isn't sufficient since the vpx_svc_ref_frame_config_t struct was changed a few times after this point. > [VP9E_SET_SVC_PARAMETERS] = "VP9E_SET_SVC_PARAMETERS", > + [VP9E_SET_SVC_REF_FRAME_CONFIG] = "VP9E_SET_SVC_REF_FRAME_CONFIG", > #endif > [VP9E_SET_SVC] = "VP9E_SET_SVC", > #if VPX_ENCODER_ABI_VERSION >= 11 > @@ -394,6 +400,18 @@ static void vp8_ts_parse_int_array(int *dest, char *value, size_t value_len, int > } > } > > +static void vp8_ts_parse_int64_array(int64_t *dest, char *value, size_t value_len, int max_entries) > +{ > + int dest_idx = 0; > + char *saveptr = NULL; > + char *token = av_strtok(value, ",", &saveptr); > + > + while (token && dest_idx < max_entries) { > + dest[dest_idx++] = strtoul(token, NULL, 10); int64 seems like it was overkill in the api, but you probably want strtoull here.
Hi James, On Wed, Nov 18, 2020 at 1:13 PM James Zern <jzern-at-google.com@ffmpeg.org> wrote: > Hi, > > On Mon, Nov 16, 2020 at 2:36 PM Wonkap Jang > <wonkap-at-google.com@ffmpeg.org> wrote: > > > > In order to fine-control referencing schemes in VP9 encoding, there > > is a need to use VP9E_SET_SVC_REF_FRAME_CONFIG method. This commit > > provides a way to use the API through frame metadata. > > --- > > libavcodec/libvpxenc.c | 77 ++++++++++++++++++++++++++++++++++++++++++ > > The documentation could use an update too. Maybe some of the earlier > per-frame metadata was missed. > > > 1 file changed, 77 insertions(+) > > > > diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c > > index a7c76eb835..dbe399bf72 100644 > > --- a/libavcodec/libvpxenc.c > > +++ b/libavcodec/libvpxenc.c > > @@ -125,6 +125,11 @@ typedef struct VPxEncoderContext { > > * encounter a frame with ROI side data. > > */ > > int roi_warned; > > + > > +#if (VPX_ENCODER_ABI_VERSION >= 12) && CONFIG_LIBVPX_VP9_ENCODER > > + vpx_svc_ref_frame_config_t ref_frame_config; > > + AVDictionary *vpx_ref_frame_config; > > +#endif > > } VPxContext; > > > > /** String mappings for enum vp8e_enc_control_id */ > > @@ -152,6 +157,7 @@ static const char *const ctlidstr[] = { > > [VP9E_SET_SVC_LAYER_ID] = "VP9E_SET_SVC_LAYER_ID", > > #if VPX_ENCODER_ABI_VERSION >= 12 > > This check isn't sufficient since the vpx_svc_ref_frame_config_t > struct was changed a few times after this point. > > > [VP9E_SET_SVC_PARAMETERS] = "VP9E_SET_SVC_PARAMETERS", > > + [VP9E_SET_SVC_REF_FRAME_CONFIG] = > "VP9E_SET_SVC_REF_FRAME_CONFIG", > > #endif > > [VP9E_SET_SVC] = "VP9E_SET_SVC", > > #if VPX_ENCODER_ABI_VERSION >= 11 > > @@ -394,6 +400,18 @@ static void vp8_ts_parse_int_array(int *dest, char > *value, size_t value_len, int > > } > > } > > > > +static void vp8_ts_parse_int64_array(int64_t *dest, char *value, size_t > value_len, int max_entries) > > +{ > > + int dest_idx = 0; > > + char *saveptr = NULL; > > + char *token = av_strtok(value, ",", &saveptr); > > + > > + while (token && dest_idx < max_entries) { > > + dest[dest_idx++] = strtoul(token, NULL, 10); > > int64 seems like it was overkill in the api, but you probably want > strtoull here. > _______________________________________________ > 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". I tried to figure out the right version number, but it seems that the version number was not bumped when the change was made. I tried to find a new #define that I could use, but cannot seem to find one. Is there one that you could suggest I use? Or perhaps a way to find one? Need help. Thank you, Wonkap
On Mon, Nov 23, 2020 at 2:49 PM Wonkap Jang <wonkap-at-google.com@ffmpeg.org> wrote: > > Hi James, > > On Wed, Nov 18, 2020 at 1:13 PM James Zern <jzern-at-google.com@ffmpeg.org> > wrote: > > > Hi, > > > > On Mon, Nov 16, 2020 at 2:36 PM Wonkap Jang > > <wonkap-at-google.com@ffmpeg.org> wrote: > > > > > > In order to fine-control referencing schemes in VP9 encoding, there > > > is a need to use VP9E_SET_SVC_REF_FRAME_CONFIG method. This commit > > > provides a way to use the API through frame metadata. > > > --- > > > libavcodec/libvpxenc.c | 77 ++++++++++++++++++++++++++++++++++++++++++ > > > > The documentation could use an update too. Maybe some of the earlier > > per-frame metadata was missed. > > > > > 1 file changed, 77 insertions(+) > > > > > > diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c > > > index a7c76eb835..dbe399bf72 100644 > > > --- a/libavcodec/libvpxenc.c > > > +++ b/libavcodec/libvpxenc.c > > > @@ -125,6 +125,11 @@ typedef struct VPxEncoderContext { > > > * encounter a frame with ROI side data. > > > */ > > > int roi_warned; > > > + > > > +#if (VPX_ENCODER_ABI_VERSION >= 12) && CONFIG_LIBVPX_VP9_ENCODER > > > + vpx_svc_ref_frame_config_t ref_frame_config; > > > + AVDictionary *vpx_ref_frame_config; > > > +#endif > > > } VPxContext; > > > > > > /** String mappings for enum vp8e_enc_control_id */ > > > @@ -152,6 +157,7 @@ static const char *const ctlidstr[] = { > > > [VP9E_SET_SVC_LAYER_ID] = "VP9E_SET_SVC_LAYER_ID", > > > #if VPX_ENCODER_ABI_VERSION >= 12 > > > > This check isn't sufficient since the vpx_svc_ref_frame_config_t > > struct was changed a few times after this point. > > > > > [VP9E_SET_SVC_PARAMETERS] = "VP9E_SET_SVC_PARAMETERS", > > > + [VP9E_SET_SVC_REF_FRAME_CONFIG] = > > "VP9E_SET_SVC_REF_FRAME_CONFIG", > > > #endif > > > [VP9E_SET_SVC] = "VP9E_SET_SVC", > > > #if VPX_ENCODER_ABI_VERSION >= 11 > > > @@ -394,6 +400,18 @@ static void vp8_ts_parse_int_array(int *dest, char > > *value, size_t value_len, int > > > } > > > } > > > > > > +static void vp8_ts_parse_int64_array(int64_t *dest, char *value, size_t > > value_len, int max_entries) > > > +{ > > > + int dest_idx = 0; > > > + char *saveptr = NULL; > > > + char *token = av_strtok(value, ",", &saveptr); > > > + > > > + while (token && dest_idx < max_entries) { > > > + dest[dest_idx++] = strtoul(token, NULL, 10); > > > > int64 seems like it was overkill in the api, but you probably want > > strtoull here. > > _______________________________________________ > > 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". > > > I tried to figure out the right version number, but it seems that the > version number was not bumped when the change was made. > I tried to find a new #define that I could use, but cannot seem to find > one. Is there one that you could suggest I use? Or perhaps a way to find > one? > Need help. > From the blame log it looks like v1.7.0-936-g04b3d49ba was the last meaningful edit, so you can use the version from v1.8.0; it doesn't have to be perfect.
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c index a7c76eb835..dbe399bf72 100644 --- a/libavcodec/libvpxenc.c +++ b/libavcodec/libvpxenc.c @@ -125,6 +125,11 @@ typedef struct VPxEncoderContext { * encounter a frame with ROI side data. */ int roi_warned; + +#if (VPX_ENCODER_ABI_VERSION >= 12) && CONFIG_LIBVPX_VP9_ENCODER + vpx_svc_ref_frame_config_t ref_frame_config; + AVDictionary *vpx_ref_frame_config; +#endif } VPxContext; /** String mappings for enum vp8e_enc_control_id */ @@ -152,6 +157,7 @@ static const char *const ctlidstr[] = { [VP9E_SET_SVC_LAYER_ID] = "VP9E_SET_SVC_LAYER_ID", #if VPX_ENCODER_ABI_VERSION >= 12 [VP9E_SET_SVC_PARAMETERS] = "VP9E_SET_SVC_PARAMETERS", + [VP9E_SET_SVC_REF_FRAME_CONFIG] = "VP9E_SET_SVC_REF_FRAME_CONFIG", #endif [VP9E_SET_SVC] = "VP9E_SET_SVC", #if VPX_ENCODER_ABI_VERSION >= 11 @@ -394,6 +400,18 @@ static void vp8_ts_parse_int_array(int *dest, char *value, size_t value_len, int } } +static void vp8_ts_parse_int64_array(int64_t *dest, char *value, size_t value_len, int max_entries) +{ + int dest_idx = 0; + char *saveptr = NULL; + char *token = av_strtok(value, ",", &saveptr); + + while (token && dest_idx < max_entries) { + dest[dest_idx++] = strtoul(token, NULL, 10); + token = av_strtok(NULL, ",", &saveptr); + } +} + static void set_temporal_layer_pattern(int layering_mode, vpx_codec_enc_cfg_t *cfg, int *layer_flags, int *flag_periodicity) { @@ -541,6 +559,48 @@ static int vpx_ts_param_parse(VPxContext *ctx, struct vpx_codec_enc_cfg *enccfg, return 0; } +#if (VPX_ENCODER_ABI_VERSION >= 12) && CONFIG_LIBVPX_VP9_ENCODER +static int vpx_ref_frame_config_parse(VPxContext *ctx, const struct vpx_codec_enc_cfg *enccfg, + char *key, char *value, enum AVCodecID codec_id) +{ + size_t value_len = strlen(value); + int ss_number_layers = enccfg->ss_number_layers; + vpx_svc_ref_frame_config_t *ref_frame_config = &ctx->ref_frame_config; + + if (!value_len) + return -1; + + if (codec_id != AV_CODEC_ID_VP9) + return -1; + + if (!strcmp(key, "rfc_update_buffer_slot")) { + vp8_ts_parse_int_array(ref_frame_config->update_buffer_slot, value, value_len, ss_number_layers); + } else if (!strcmp(key, "rfc_update_last")) { + vp8_ts_parse_int_array(ref_frame_config->update_last, value, value_len, ss_number_layers); + } else if (!strcmp(key, "rfc_update_golden")) { + vp8_ts_parse_int_array(ref_frame_config->update_golden, value, value_len, ss_number_layers); + } else if (!strcmp(key, "rfc_update_alt_ref")) { + vp8_ts_parse_int_array(ref_frame_config->update_alt_ref, value, value_len, ss_number_layers); + } else if (!strcmp(key, "rfc_lst_fb_idx")) { + vp8_ts_parse_int_array(ref_frame_config->lst_fb_idx, value, value_len, ss_number_layers); + } else if (!strcmp(key, "rfc_gld_fb_idx")) { + vp8_ts_parse_int_array(ref_frame_config->gld_fb_idx, value, value_len, ss_number_layers); + } else if (!strcmp(key, "rfc_alt_fb_idx")) { + vp8_ts_parse_int_array(ref_frame_config->alt_fb_idx, value, value_len, ss_number_layers); + } else if (!strcmp(key, "rfc_reference_last")) { + vp8_ts_parse_int_array(ref_frame_config->reference_last, value, value_len, ss_number_layers); + } else if (!strcmp(key, "rfc_reference_golden")) { + vp8_ts_parse_int_array(ref_frame_config->reference_golden, value, value_len, ss_number_layers); + } else if (!strcmp(key, "rfc_reference_alt_ref")) { + vp8_ts_parse_int_array(ref_frame_config->reference_alt_ref, value, value_len, ss_number_layers); + } else if (!strcmp(key, "rfc_reference_duration")) { + vp8_ts_parse_int64_array(ref_frame_config->duration, value, value_len, ss_number_layers); + } + + return 0; +} +#endif + #if CONFIG_LIBVPX_VP9_ENCODER static int set_pix_fmt(AVCodecContext *avctx, vpx_codec_caps_t codec_caps, struct vpx_codec_enc_cfg *enccfg, vpx_codec_flags_t *flags, @@ -1528,6 +1588,23 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt, #endif layer_id_valid = 1; } +#if (VPX_ENCODER_ABI_VERSION >= 12) && CONFIG_LIBVPX_VP9_ENCODER + en = av_dict_get(frame->metadata, "ref-frame-config", NULL, 0); + + if (en) { + AVDictionaryEntry* en2 = NULL; + av_dict_parse_string(&ctx->vpx_ref_frame_config, en->value, "=", ":", 0); + + while ((en2 = av_dict_get(ctx->vpx_ref_frame_config, "", en2, AV_DICT_IGNORE_SUFFIX))) { + if (vpx_ref_frame_config_parse(ctx, enccfg, en2->key, en2->value, avctx->codec_id) < 0) + av_log(avctx, AV_LOG_WARNING, + "Error parsing option '%s = %s'.\n", + en2->key, en2->value); + } + + codecctl_intp(avctx, VP9E_SET_SVC_REF_FRAME_CONFIG, (int *)&ctx->ref_frame_config); + } +#endif } if (sd) {