From fab71806eb954b84a7bdb2bca2d3d2667f2fad1e Mon Sep 17 00:00:00 2001 From: Martin Piatka Date: Wed, 11 Aug 2021 14:13:59 +0200 Subject: [PATCH] Lavc: print warning about 422 subsampling hwaccel support --- src/libavcodec_common.h | 16 ++++++++++++++++ src/video_compress/libavcodec.cpp | 4 ++++ src/video_decompress/libavcodec.c | 15 +-------------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/libavcodec_common.h b/src/libavcodec_common.h index d78756db3..759e33df0 100644 --- a/src/libavcodec_common.h +++ b/src/libavcodec_common.h @@ -195,6 +195,22 @@ static void print_decoder_error(const char *mod_name, int rc) { } } +inline static bool pixfmt_has_422_subsampling(enum AVPixelFormat fmt){ + const AVPixFmtDescriptor *fmt_desc = av_pix_fmt_desc_get(fmt); + + return fmt_desc && !(fmt_desc->flags & AV_PIX_FMT_FLAG_HWACCEL) + && fmt_desc->log2_chroma_w == 1 && fmt_desc->log2_chroma_h == 0; +} + +inline static bool pixfmt_list_has_422_subsasmpling(const enum AVPixelFormat *fmt){ + for(const enum AVPixelFormat *it = fmt; *it != AV_PIX_FMT_NONE; it++){ + if(pixfmt_has_422_subsampling(*it)) + return true; + } + + return false; +} + void print_libav_error(int verbosity, const char *msg, int rc); bool libav_codec_has_extradata(codec_t codec); diff --git a/src/video_compress/libavcodec.cpp b/src/video_compress/libavcodec.cpp index 32831e7c3..7a0903cd9 100644 --- a/src/video_compress/libavcodec.cpp +++ b/src/video_compress/libavcodec.cpp @@ -1242,6 +1242,10 @@ static bool configure_with(struct state_video_compress_libav *s, struct video_de log_msg(LOG_LEVEL_INFO, "[lavc] Selected pixfmt: %s\n", av_get_pix_fmt_name(pix_fmt)); s->selected_pixfmt = pix_fmt; + if(pixfmt_has_422_subsampling(pix_fmt)){ + log_msg(LOG_LEVEL_WARNING, "[lavc] Selected pixfmt has 4:2:2 subsampling, " + "which is usually not supported by hw. decoders\n"); + } if(!find_decoder(desc, s->selected_pixfmt, &s->decoded_codec, &s->decoder)){ log_msg(LOG_LEVEL_ERROR, "[lavc] Failed to find a way to convert %s to %s\n", diff --git a/src/video_decompress/libavcodec.c b/src/video_decompress/libavcodec.c index 7f73822ef..dc6a93dd3 100644 --- a/src/video_decompress/libavcodec.c +++ b/src/video_decompress/libavcodec.c @@ -494,19 +494,6 @@ fail: } #endif -static bool is_422_subsasmpling(const enum AVPixelFormat *fmt){ - for(const enum AVPixelFormat *it = fmt; *it != AV_PIX_FMT_NONE; it++){ - const AVPixFmtDescriptor *fmt_desc = av_pix_fmt_desc_get(*it); - if(!fmt_desc || fmt_desc->flags & AV_PIX_FMT_FLAG_HWACCEL) - continue; - - if(fmt_desc->log2_chroma_w == 1 && fmt_desc->log2_chroma_h == 0) - return true; - } - - return false; -} - static enum AVPixelFormat get_format_callback(struct AVCodecContext *s __attribute__((unused)), const enum AVPixelFormat *fmt) { if (log_level >= LOG_LEVEL_VERBOSE) { @@ -542,7 +529,7 @@ static enum AVPixelFormat get_format_callback(struct AVCodecContext *s __attribu if (hwaccel && state->out_codec != VIDEO_CODEC_NONE) { // not probing internal format struct state_libavcodec_decompress *state = (struct state_libavcodec_decompress *) s->opaque; - if(is_422_subsasmpling(fmt)){ + if(pixfmt_list_has_422_subsasmpling(fmt)){ log_msg(LOG_LEVEL_WARNING, "[lavd] Hw. acceleration requested " "but incoming video has 4:2:2 subsampling, " "which is usually not supported by hw. accelerators\n");