diff options
author | Guo, Yejun <yejun.guo@intel.com> | 2020-09-11 22:15:04 +0800 |
---|---|---|
committer | Guo, Yejun <yejun.guo@intel.com> | 2020-09-21 21:26:56 +0800 |
commit | e71d73b09652f4fc96e512a7d6d4c2ab41860f27 (patch) | |
tree | 07b84f09dceed8083e0985390f0258e780c4c742 /libavfilter/vf_sr.c | |
parent | fce3e3e137843d86411f8868f18e1c3f472de0e5 (diff) |
dnn: add a new interface DNNModel.get_output
for some cases (for example, super resolution), the DNN model changes
the frame size which impacts the filter behavior, so the filter needs
to know the out frame size at very beginning.
Currently, the filter reuses DNNModule.execute_model to query the
out frame size, it is not clear from interface perspective, so add
a new explict interface DNNModel.get_output for such query.
Diffstat (limited to 'libavfilter/vf_sr.c')
-rw-r--r-- | libavfilter/vf_sr.c | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/libavfilter/vf_sr.c b/libavfilter/vf_sr.c index 72a3137262..fe6c5d3c0d 100644 --- a/libavfilter/vf_sr.c +++ b/libavfilter/vf_sr.c @@ -111,23 +111,20 @@ static int config_output(AVFilterLink *outlink) SRContext *ctx = context->priv; DNNReturnType result; AVFilterLink *inlink = context->inputs[0]; - AVFrame *out = NULL; - const char *model_output_name = "y"; + int out_width, out_height; // have a try run in case that the dnn model resize the frame - AVFrame *fake_in = ff_get_video_buffer(inlink, inlink->w, inlink->h); - out = ff_get_video_buffer(inlink, inlink->w, inlink->h); - result = (ctx->dnn_module->execute_model)(ctx->model, "x", fake_in, - (const char **)&model_output_name, 1, out); - if (result != DNN_SUCCESS){ - av_log(context, AV_LOG_ERROR, "failed to execute loaded model\n"); + result = ctx->model->get_output(ctx->model->model, "x", inlink->w, inlink->h, + "y", &out_width, &out_height); + if (result != DNN_SUCCESS) { + av_log(ctx, AV_LOG_ERROR, "could not get output from the model\n"); return AVERROR(EIO); } - if (fake_in->width != out->width || fake_in->height != out->height) { + if (inlink->w != out_width || inlink->h != out_height) { //espcn - outlink->w = out->width; - outlink->h = out->height; + outlink->w = out_width; + outlink->h = out_height; if (inlink->format != AV_PIX_FMT_GRAY8){ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); int sws_src_h = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h); @@ -141,15 +138,13 @@ static int config_output(AVFilterLink *outlink) } } else { //srcnn - outlink->w = out->width * ctx->scale_factor; - outlink->h = out->height * ctx->scale_factor; + outlink->w = out_width * ctx->scale_factor; + outlink->h = out_height * ctx->scale_factor; ctx->sws_pre_scale = sws_getContext(inlink->w, inlink->h, inlink->format, outlink->w, outlink->h, outlink->format, SWS_BICUBIC, NULL, NULL, NULL); } - av_frame_free(&fake_in); - av_frame_free(&out); return 0; } |