From: Jaroslav Kysela Date: Sat, 2 Sep 2017 10:42:08 +0000 (+0200) Subject: transcode: vaapi - use vaapi deinterlace instead yadif X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=05b81dbe6da4e5486005b6f66ace9961e26a37e3;p=thirdparty%2Ftvheadend.git transcode: vaapi - use vaapi deinterlace instead yadif --- diff --git a/Makefile.ffmpeg b/Makefile.ffmpeg index 96a574146..d94ce6e6b 100644 --- a/Makefile.ffmpeg +++ b/Makefile.ffmpeg @@ -556,7 +556,7 @@ ifeq (yes,$(CONFIG_VAAPI)) EXTLIBS += vaapi ENCODERS += h264_vaapi hevc_vaapi HWACCELS += mpeg2_vaapi h264_vaapi hevc_vaapi -FILTERS += scale_vaapi +FILTERS += deinterlace_vaapi scale_vaapi FFMPEG_DIFFS += ffmpeg.vaapi_encode.diff endif diff --git a/src/transcoding/codec/profile_video_class.c b/src/transcoding/codec/profile_video_class.c index ceb744328..7768db731 100644 --- a/src/transcoding/codec/profile_video_class.c +++ b/src/transcoding/codec/profile_video_class.c @@ -111,7 +111,7 @@ codec_profile_video_class_deinterlace_set(void *obj, const void *val) if (self && (avcodec = tvh_codec_profile_get_avcodec((TVHCodecProfile *)self))) { - self->deinterlace = (avcodec->id == AV_CODEC_ID_HEVC) ? 1 : *(int *)val; + self->deinterlace = *(int *)val; return 1; } return 0; diff --git a/src/transcoding/memutils.c b/src/transcoding/memutils.c index f44efce52..3313fd815 100644 --- a/src/transcoding/memutils.c +++ b/src/transcoding/memutils.c @@ -30,8 +30,10 @@ str_add(const char *sep, const char *str) char *result = NULL; if ((result = calloc(1, sep_len + str_len + 1))) { - strncpy(result, sep, sep_len); - strncat(result, str, str_len); + if (str_len > 0) { + strncpy(result, sep, sep_len); + strncat(result, str, str_len); + } } return result; } diff --git a/src/transcoding/transcode/hwaccels/hwaccels.c b/src/transcoding/transcode/hwaccels/hwaccels.c index 75195dde9..44f1db106 100644 --- a/src/transcoding/transcode/hwaccels/hwaccels.c +++ b/src/transcoding/transcode/hwaccels/hwaccels.c @@ -105,6 +105,24 @@ hwaccels_decode_close_context(AVCodecContext *avctx) } +int +hwaccels_get_deint_filter(AVCodecContext *avctx, char *filter, size_t filter_len) +{ + if (avctx->hwaccel_context) { + switch (avctx->pix_fmt) { +#if ENABLE_VAAPI + case AV_PIX_FMT_VAAPI: + return vaapi_get_deint_filter(avctx, filter, filter_len); +#endif + default: + break; + } + } + + return -1; +} + + /* encoding ================================================================= */ int diff --git a/src/transcoding/transcode/hwaccels/hwaccels.h b/src/transcoding/transcode/hwaccels/hwaccels.h index aaa3733a6..6b6f1f49b 100644 --- a/src/transcoding/transcode/hwaccels/hwaccels.h +++ b/src/transcoding/transcode/hwaccels/hwaccels.h @@ -36,6 +36,9 @@ hwaccels_decode_get_format(AVCodecContext *avctx, void hwaccels_decode_close_context(AVCodecContext *avctx); +int +hwaccels_get_deint_filter(AVCodecContext *avctx, char *filter, size_t filter_len); + /* encoding ================================================================= */ diff --git a/src/transcoding/transcode/hwaccels/vaapi.c b/src/transcoding/transcode/hwaccels/vaapi.c index 11652fce1..4ac20006a 100644 --- a/src/transcoding/transcode/hwaccels/vaapi.c +++ b/src/transcoding/transcode/hwaccels/vaapi.c @@ -530,6 +530,14 @@ vaapi_decode_close_context(AVCodecContext *avctx) } +int +vaapi_get_deint_filter(AVCodecContext *avctx, char *filter, size_t filter_len) +{ + snprintf(filter, filter_len, "deinterlace_vaapi"); + return 0; +} + + /* encoding ================================================================= */ int diff --git a/src/transcoding/transcode/hwaccels/vaapi.h b/src/transcoding/transcode/hwaccels/vaapi.h index af3944887..acbd3e14f 100644 --- a/src/transcoding/transcode/hwaccels/vaapi.h +++ b/src/transcoding/transcode/hwaccels/vaapi.h @@ -35,6 +35,9 @@ vaapi_decode_setup_context(AVCodecContext *avctx); void vaapi_decode_close_context(AVCodecContext *avctx); +int +vaapi_get_deint_filter(AVCodecContext *avctx, char *filter, size_t filter_len); + /* encoding ================================================================= */ diff --git a/src/transcoding/transcode/video.c b/src/transcoding/transcode/video.c index ce73b2d5c..8679ec1c4 100644 --- a/src/transcoding/transcode/video.c +++ b/src/transcoding/transcode/video.c @@ -41,10 +41,11 @@ _video_filters_hw_pix_fmt(enum AVPixelFormat pix_fmt) static int _video_filters_get_filters(TVHContext *self, AVDictionary **opts, char **filters) { - static char download[48]; - static char deint[8]; - static char scale[24]; - static char upload[48]; + char download[48]; + char deint[8]; + char hw_deint[64]; + char scale[24]; + char upload[48]; int ihw = _video_filters_hw_pix_fmt(self->iavctx->pix_fmt); int ohw = _video_filters_hw_pix_fmt(self->oavctx->pix_fmt); int filter_scale = (self->iavctx->height != self->oavctx->height); @@ -64,8 +65,11 @@ _video_filters_get_filters(TVHContext *self, AVDictionary **opts, char **filters } memset(deint, 0, sizeof(deint)); - if (filter_deint && str_snprintf(deint, sizeof(deint), "yadif")) { - return -1; + memset(hw_deint, 0, sizeof(hw_deint)); + if (filter_deint && hwaccels_get_deint_filter(self->iavctx, hw_deint, sizeof(hw_deint))) { + if (str_snprintf(deint, sizeof(deint), "yadif")) { + return -1; + } } memset(scale, 0, sizeof(scale)); @@ -83,7 +87,7 @@ _video_filters_get_filters(TVHContext *self, AVDictionary **opts, char **filters return -1; } - if (!(*filters = str_join(",", download, deint, scale, upload, NULL))) { + if (!(*filters = str_join(",", download, deint, scale, upload, hw_deint, NULL))) { return -1; }