From patchwork Wed Sep 22 07:42:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xiang, Haihao" X-Patchwork-Id: 30454 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp263087iob; Wed, 22 Sep 2021 00:42:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNAc8qc5b+bVuVP0v4ubWfaSZGOXtiH6PTAjsZAoqPojmdZVQH36pKw/AHzrLaAFkx6+VV X-Received: by 2002:a05:6402:1e90:: with SMTP id f16mr39758667edf.136.1632296573173; Wed, 22 Sep 2021 00:42:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632296573; cv=none; d=google.com; s=arc-20160816; b=wcs+fFI0BMnO1NPlWTUoh7350Bw+jh1hHxexlf1PnLl/ziq4HdoaC8QYHQmXXUQ+yN FGKfGyVQz7GtPBk0DzKWB6G1yhNGivRi2N+J41p0S94K0P/6tUoZIMap1u5BC8eHIFna pKlXhkyZrh3ns5IIP2n5YQLYpwPy5ann/BoZl8teOWRYlaVIyn7MGUsbOKiqYTIGeNNE Wb+0U6q8/IefVwidlJjBAzHPBoCoCPtrTShXGaap5rnFXa3QvndMQCnZlh++MmFO3i1D wRy2Phb6bNYAsj8ND5a3/tMuQosRpBQ5AUuogDnWSMOtXevQW9clQQ7yNB2dMww18Jlp 8ygQ== 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:delivered-to; bh=IfE09vv8urZWe/IX7JwLq9iMWGN7zB1y8oqG60VYNyI=; b=uh4bmNKvu5hvK5lqWoxZHFEvTSK/7n9Ca+N2cDjtANXy4XaWpj2VXLDB24rq10Nx7B H3IWOrep1cjhpQgfpyy3NDMAnLOxYOPpiIO1x/j+Z4DdRw+8zVWCxonXdR4W7cgNInJH kSs7sbyfBxSzofzdCNvd3CZmX7pbw32fYdYOhDscLfVT8tuGyG59M7B8KhnDYoqlT1ri GaRl3GmhzDRVH9OCgWEvyhv4bP1+sDmXN3pNg2AGGCXX2svT/HDxWKW5pZGN0y+7AAXp KfspoLk2yYi5YSSu/9yMVG+EaiN1xwL7eGwL5f4VLciw53lgv8+zISK7hfW6xW9iV03P nlsQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i23si1778028edv.93.2021.09.22.00.42.52; Wed, 22 Sep 2021 00:42:53 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F14D868AF0C; Wed, 22 Sep 2021 10:42:44 +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 C040268A4C5 for ; Wed, 22 Sep 2021 10:42:37 +0300 (EEST) X-IronPort-AV: E=McAfee;i="6200,9189,10114"; a="221651665" X-IronPort-AV: E=Sophos;i="5.85,313,1624345200"; d="scan'208";a="221651665" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2021 00:42:29 -0700 X-IronPort-AV: E=Sophos;i="5.85,313,1624345200"; d="scan'208";a="474420205" Received: from xhh-dg164.sh.intel.com ([10.239.159.167]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2021 00:42:28 -0700 From: Haihao Xiang To: ffmpeg-devel@ffmpeg.org Date: Wed, 22 Sep 2021 15:42:07 +0800 Message-Id: <20210922074207.19451-2-haihao.xiang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210922074207.19451-1-haihao.xiang@intel.com> References: <20210922074207.19451-1-haihao.xiang@intel.com> Subject: [FFmpeg-devel] [PATCH 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: KbXL721OiFCe 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.ivf -f null - ... Stream #0:0 -> #0:0 (av1 (libdav1d) -> wrapped_avframe (native)) libdav1d is selected in this case even if vaapi is specified. After applying this patch, the native av1 decoder (with vaapi support) is selected. ... Stream #0:0 -> #0:0 (av1 (native) -> wrapped_avframe (native)) --- 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 2d9a8a2ea0..914078add9 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -804,6 +804,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) @@ -932,7 +974,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;