diff options
author | Bradley Sepos <[email protected]> | 2021-02-20 15:07:23 -0500 |
---|---|---|
committer | Bradley Sepos <[email protected]> | 2021-02-20 16:22:33 -0500 |
commit | 983159719afa11a3b0992833ad69e6d48f31ffcd (patch) | |
tree | 4d8f094bd9b393df02d6a8f8d8d9d37cd5163208 /libhb | |
parent | abd8ec5a07fce1204bde8ca7752a945605eec792 (diff) |
libhb: Decode directly to NV12 for MediaFoundation encoder where possible.
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/encavcodec.c | 27 | ||||
-rw-r--r-- | libhb/work.c | 34 |
2 files changed, 49 insertions, 12 deletions
diff --git a/libhb/encavcodec.c b/libhb/encavcodec.c index 9370acefe..08e69362e 100644 --- a/libhb/encavcodec.c +++ b/libhb/encavcodec.c @@ -644,18 +644,21 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * job ) { av_dict_set(&av_opts, "hw_encoding", "1", 0); - pv->sws_context_to_nv12 = hb_sws_get_context( - job->width, job->height, - AV_PIX_FMT_YUV420P, - job->width, job->height, - AV_PIX_FMT_NV12, - SWS_LANCZOS|SWS_ACCURATE_RND, - SWS_CS_DEFAULT); - - pv->nv12_buf = hb_frame_buffer_init( - AV_PIX_FMT_NV12, job->width, job->height); - - context->pix_fmt = AV_PIX_FMT_NV12; + if (job->pix_fmt != AV_PIX_FMT_NV12) + { + pv->sws_context_to_nv12 = hb_sws_get_context( + job->width, job->height, + AV_PIX_FMT_YUV420P, + job->width, job->height, + AV_PIX_FMT_NV12, + SWS_LANCZOS|SWS_ACCURATE_RND, + SWS_CS_DEFAULT); + + pv->nv12_buf = hb_frame_buffer_init( + AV_PIX_FMT_NV12, job->width, job->height); + + context->pix_fmt = AV_PIX_FMT_NV12; + } } if (job->vcodec == HB_VCODEC_FFMPEG_MF_H265) diff --git a/libhb/work.c b/libhb/work.c index e65c42540..0bc696d08 100644 --- a/libhb/work.c +++ b/libhb/work.c @@ -838,6 +838,33 @@ static int bit_depth_is_supported(hb_job_t * job, int bit_depth) return 1; } +static int pix_fmt_is_supported(hb_job_t * job, int pix_fmt) +{ + for (int i = 0; i < hb_list_count(job->list_filter); i++) + { + hb_filter_object_t *filter = hb_list_item(job->list_filter, i); + + switch (filter->id) + { + case HB_FILTER_DETELECINE: + case HB_FILTER_COMB_DETECT: + case HB_FILTER_DECOMB: + case HB_FILTER_DENOISE: + case HB_FILTER_NLMEANS: + case HB_FILTER_CHROMA_SMOOTH: + case HB_FILTER_LAPSHARP: + case HB_FILTER_UNSHARP: + case HB_FILTER_GRAYSCALE: + if (pix_fmt != AV_PIX_FMT_YUV420P) + { + return 0; + } + } + } + + return 1; +} + static int get_best_pix_ftm(hb_job_t * job) { int bit_depth = hb_get_bit_depth(job->title->pix_fmt); @@ -862,6 +889,13 @@ static int get_best_pix_ftm(hb_job_t * job) } } #endif + if (job->vcodec == HB_VCODEC_FFMPEG_MF_H264 || job->vcodec == HB_VCODEC_FFMPEG_MF_H265) + { + if (pix_fmt_is_supported(job, AV_PIX_FMT_NV12)) + { + return AV_PIX_FMT_NV12; + } + } if (bit_depth >= 12 && bit_depth_is_supported(job, 12)) { return AV_PIX_FMT_YUV420P12; |