Showing the changes to libavfilter (2 of 2 files). Show all
Unified · Split
| @@ -64,6 +64,7 @@ DNNReturnType proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *log_ · 63 unmodified lines | ||
| 64 | 64 | case AV_PIX_FMT_YUV410P: |
| 65 | 65 | case AV_PIX_FMT_YUV411P: |
| 66 | 66 | case AV_PIX_FMT_GRAY8: |
| 67 | + case AV_PIX_FMT_NV12: | |
| 67 | 68 | sws_ctx = sws_getContext(frame->width, |
| 68 | 69 | frame->height, |
| 69 | 70 | AV_PIX_FMT_GRAYF32, |
| @@ -135,6 +136,7 @@ DNNReturnType proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_c · 65 unmodified lines | ||
| 135 | 136 | case AV_PIX_FMT_YUV410P: |
| 136 | 137 | case AV_PIX_FMT_YUV411P: |
| 137 | 138 | case AV_PIX_FMT_GRAY8: |
| 139 | + case AV_PIX_FMT_NV12: | |
| 138 | 140 | sws_ctx = sws_getContext(frame->width, |
| 139 | 141 | frame->height, |
| 140 | 142 | AV_PIX_FMT_GRAY8, |
| @@ -113,6 +113,7 @@ static int query_formats(AVFilterContext *context) · 112 unmodified lines | ||
| 113 | 113 | AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAYF32, |
| 114 | 114 | AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, |
| 115 | 115 | AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, |
| 116 | + AV_PIX_FMT_NV12, | |
| 116 | 117 | AV_PIX_FMT_NONE |
| 117 | 118 | }; |
| 118 | 119 | AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts); |
| @@ -161,6 +162,7 @@ static int check_modelinput_inlink(const DNNData *model_input, const AVFilterLin · 42 unmodified lines | ||
| 161 | 162 | case AV_PIX_FMT_YUV444P: |
| 162 | 163 | case AV_PIX_FMT_YUV410P: |
| 163 | 164 | case AV_PIX_FMT_YUV411P: |
| 165 | + case AV_PIX_FMT_NV12: | |
| 164 | 166 | if (model_input->channels != 1) { |
| 165 | 167 | LOG_FORMAT_CHANNEL_MISMATCH(); |
| 166 | 168 | return AVERROR(EIO); |
| @@ -212,15 +214,22 @@ static int prepare_uv_scale(AVFilterLink *outlink) · 45 unmodified lines | ||
| 212 | 214 | |
| 213 | 215 | if (isPlanarYUV(fmt)) { |
| 214 | 216 | if (inlink->w != outlink->w || inlink->h != outlink->h) { |
| 215 | − const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt); | |
| 216 | − int sws_src_h = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h); | |
| 217 | − int sws_src_w = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w); | |
| 218 | − int sws_dst_h = AV_CEIL_RSHIFT(outlink->h, desc->log2_chroma_h); | |
| 219 | − int sws_dst_w = AV_CEIL_RSHIFT(outlink->w, desc->log2_chroma_w); | |
| 220 | − ctx->sws_uv_scale = sws_getContext(sws_src_w, sws_src_h, AV_PIX_FMT_GRAY8, | |
| 221 | − sws_dst_w, sws_dst_h, AV_PIX_FMT_GRAY8, | |
| 222 | − SWS_BICUBIC, NULL, NULL, NULL); | |
| 223 | − ctx->sws_uv_height = sws_src_h; | |
| 217 | + if (fmt == AV_PIX_FMT_NV12) { | |
| 218 | + ctx->sws_uv_scale = sws_getContext(inlink->w >> 1, inlink->h >> 1, AV_PIX_FMT_YA8, | |
| 219 | + outlink->w >> 1, outlink->h >> 1, AV_PIX_FMT_YA8, | |
| 220 | + SWS_BICUBIC, NULL, NULL, NULL); | |
| 221 | + ctx->sws_uv_height = inlink->h >> 1; | |
| 222 | + } else { | |
| 223 | + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt); | |
| 224 | + int sws_src_h = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h); | |
| 225 | + int sws_src_w = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w); | |
| 226 | + int sws_dst_h = AV_CEIL_RSHIFT(outlink->h, desc->log2_chroma_h); | |
| 227 | + int sws_dst_w = AV_CEIL_RSHIFT(outlink->w, desc->log2_chroma_w); | |
| 228 | + ctx->sws_uv_scale = sws_getContext(sws_src_w, sws_src_h, AV_PIX_FMT_GRAY8, | |
| 229 | + sws_dst_w, sws_dst_h, AV_PIX_FMT_GRAY8, | |
| 230 | + SWS_BICUBIC, NULL, NULL, NULL); | |
| 231 | + ctx->sws_uv_height = sws_src_h; | |
| 232 | + } | |
| 224 | 233 | } |
| 225 | 234 | } |
| 226 | 235 | |
| @@ -262,6 +271,9 @@ static int copy_uv_planes(DnnProcessingContext *ctx, AVFrame *out, const AVFrame · 35 unmodified lines | ||
| 262 | 271 | in->data[i], in->linesize[i], |
| 263 | 272 | bytewidth, uv_height); |
| 264 | 273 | } |
| 274 | + } else if (in->format == AV_PIX_FMT_NV12) { | |
| 275 | + sws_scale(ctx->sws_uv_scale, (const uint8_t **)(in->data + 1), in->linesize + 1, | |
| 276 | + 0, ctx->sws_uv_height, out->data + 1, out->linesize + 1); | |
| 265 | 277 | } else { |
| 266 | 278 | sws_scale(ctx->sws_uv_scale, (const uint8_t **)(in->data + 1), in->linesize + 1, |
| 267 | 279 | 0, ctx->sws_uv_height, out->data + 1, out->linesize + 1); |