From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id C1557431C7 for ; Mon, 25 Jul 2022 04:31:30 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B8BCB68B8B1; Mon, 25 Jul 2022 07:31:26 +0300 (EEST) 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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; -- 2.17.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".