From patchwork Mon Jul 25 04:30:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xiang, Haihao" X-Patchwork-Id: 36952 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp1819710pzb; Sun, 24 Jul 2022 21:31:33 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v4+k2mMJswnwUK8mHfSRGBxn9jNYoyBmcH2lQ+LD9Nlyta1vZBJLTKPBAwjuLZFPHO/kGp X-Received: by 2002:a17:907:7632:b0:72b:4d5d:ecce with SMTP id jy18-20020a170907763200b0072b4d5deccemr8851581ejc.11.1658723492892; Sun, 24 Jul 2022 21:31:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658723492; cv=none; d=google.com; s=arc-20160816; b=PCTQWIBKo/8U1gdSQoQEaUV8cTJ4xRct8WtI63wIfar7lIyTYmfKLTRGD8jL2dW+OF A/ZZJ65Bad6JAjmv3lEpijxBrc7pmS0ou0HB3HwrY9RGr5lnYJwgBo1nd6kA0Q3uHGYz piuHlRejsUPbbIPGRGEX6+nNKAzu4tBfnLCIGil/bI3lwN6R5TVqSCDLIuFfbPGZ3mmS b2IaF4DCkbMrp2jtrqkDZjHISKR/zQLP4n1j6A3w14um9gFMlujzDXBXcRRkLGZgZJox dRKZ3TqyahMAa9d/GAZQXGPjooOTrehlNMBYJBHk3OgqSohL+GJo5ftM20RkxGlAS+B4 O78g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to; bh=IQ1J2bEIYGuSxvdSDZAI0ob5WXYtCiKqBOfVATNcvw4=; b=fC9RL6alzvvzjvP7K8WpgllZBCMZNNJ6YLVg0maHd5KGdforR/ykDXFPwiJs5/b5wz wdt61EB5YkFjSv+/0soUTGGWEBejAzt5pXbNdobRQCxabxf+mnb+mNsjxmFJX2FGKhY1 9V5G3Np6aKEMjn+oZNy0FE6xnA1HcEaC2jCtjBi4MTvqnB7SjWjAeVQrg6XJLIYx5rMw jnLN9N+FWxgy6KffNkAKPYeZKr87TEM6L1dwxDgqXbN4AoxSXBsCWHk+I0gG1qT0RkQ8 AyBUii0oztgPUOWleT5y+DeRGCBHeZ5eJ+Cd7BX7xxe4kh66uEF6IQOIZoxv2sx1MumA E+mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=OeEzlew5; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id dp15-20020a170906c14f00b0072b83e87339si13918535ejc.208.2022.07.24.21.31.32; Sun, 24 Jul 2022 21:31:32 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=OeEzlew5; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ED7D668B8B2; Mon, 25 Jul 2022 07:31:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 23E8968B88B for ; Mon, 25 Jul 2022 07:31:19 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658723485; x=1690259485; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=4B5pXOxqePiWBvOLkenJdwrWkVzJN9hRwOPkmYrRBO8=; b=OeEzlew5e/ZH4uTPAp6HA46OAa/UzOGUFAocrF476DzlfSNAvglQQGKM qVtwNHCsvRhJD2AEJDw4PVoEf/23Rfpz06AuR3Qi2347t7B6hyAmWWTuV IsCNd00DN85F5xuLD0PDPFXXVT0RPEdIXloBKs5k3IE+KtXYxcDXAg/Ec xXTrx5k+8vZ9Mrlj0D/gi5TTMD55WHaD7UfMoVg5Phsw9Do8/isBu06P6 vRy/9D7LfQcBnmk7LbgqsRo5hjur0IO76A4fSEA2MxdVO67wrKkJegQIC 2mL5xfDKLvWQCF90pdr2n1S1tGPBaC6BFpqQiHYBy4RJufq/N7JMsr0Ax w==; X-IronPort-AV: E=McAfee;i="6400,9594,10418"; a="286366650" X-IronPort-AV: E=Sophos;i="5.93,191,1654585200"; d="scan'208";a="286366650" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jul 2022 21:31:13 -0700 X-IronPort-AV: E=Sophos;i="5.93,191,1654585200"; d="scan'208";a="574889880" Received: from xhh-dg164.sh.intel.com ([10.238.5.169]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jul 2022 21:31:12 -0700 From: "Xiang, Haihao" To: ffmpeg-devel@ffmpeg.org Date: Mon, 25 Jul 2022 12:30:51 +0800 Message-Id: <20220725043051.9692-2-haihao.xiang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220725043051.9692-1-haihao.xiang@intel.com> References: <20220725043051.9692-1-haihao.xiang@intel.com> Subject: [FFmpeg-devel] [PATCH v3 2/2] ffmpeg_opt: consider HW acceleration method when selecting decoder X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Haihao Xiang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Sjcz8DP1yFP3 From: Haihao Xiang Usually a HW decoder is expected when user specifies a HW acceleration method via -hwaccel option, however the current implementation doesn't take HW acceleration method into account, it is possible to select a SW decoder. For example: $ ffmpeg -hwaccel vaapi -i av1.mp4 -f null - $ ffmpeg -hwaccel nvdec -i av1.mp4 -f null - $ ffmpeg -hwaccel vdpau -i av1.mp4 -f null - [...] Stream #0:0 -> #0:0 (av1 (libdav1d) -> wrapped_avframe (native)) libdav1d is selected in this case even if vaapi, nvdec or vdpau is specified. After applying this patch, the native av1 decoder (with vaapi, nvdec or vdpau support) is selected for decoding(libdav1d is still used for probing format). $ ffmpeg -hwaccel vaapi -i av1.mp4 -f null - $ ffmpeg -hwaccel nvdec -i av1.mp4 -f null - $ ffmpeg -hwaccel vdpau -i av1.mp4 -f null - [...] Stream #0:0 -> #0:0 (av1 (native) -> wrapped_avframe (native)) Tested-by: Mario Roy Signed-off-by: Haihao Xiang --- fftools/ffmpeg_opt.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 2771c5d993..614bfeea80 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -861,6 +861,48 @@ static const AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVSt return avcodec_find_decoder(st->codecpar->codec_id); } +static const AVCodec *choose_decoder2(InputStream *ist, OptionsContext *o, AVFormatContext *s, AVStream *st) +{ + char *codec_name = NULL; + + MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st); + if (codec_name) { + const AVCodec *codec = find_codec_or_die(codec_name, st->codecpar->codec_type, 0); + st->codecpar->codec_id = codec->id; + if (recast_media && st->codecpar->codec_type != codec->type) + st->codecpar->codec_type = codec->type; + return codec; + } else { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && + ist->hwaccel_id == HWACCEL_GENERIC && + ist->hwaccel_device_type != AV_HWDEVICE_TYPE_NONE) { + const AVCodec *p; + void *i = 0; + + while ((p = av_codec_iterate(&i))) { + int j; + + if (p->id != st->codecpar->codec_id || + !av_codec_is_decoder(p) || + !avcodec_get_hw_config(p, 0)) + continue; + + for (j = 0; ;j++) { + const AVCodecHWConfig *config = avcodec_get_hw_config(p, j); + + if (!config) + break; + + if (config->device_type == ist->hwaccel_device_type) + return p; + } + } + } + + return avcodec_find_decoder(st->codecpar->codec_id); + } +} + /* Add all the streams from the given input file to the global * list of input streams. */ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) @@ -973,7 +1015,7 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) ist->hwaccel_pix_fmt = AV_PIX_FMT_NONE; } - ist->dec = choose_decoder(o, ic, st); + ist->dec = choose_decoder2(ist, o, ic, st); ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, ic, st, ist->dec); ist->reinit_filters = -1;