From patchwork Sun Dec 4 17:12:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Zhili X-Patchwork-Id: 39583 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp2708457pzb; Sun, 4 Dec 2022 09:13:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf7JQsmhrKhrotczp3qPQ/wy+d4vyuLa0ZBS1qN6oMuw+c2ryHfaG8nnWY5/rsfctH3i83/V X-Received: by 2002:a05:6402:2993:b0:462:845:ba98 with SMTP id eq19-20020a056402299300b004620845ba98mr1209512edb.12.1670174021575; Sun, 04 Dec 2022 09:13:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670174021; cv=none; d=google.com; s=arc-20160816; b=iNnn1B++IM+YFis7p6oZYCWvbpNjjl5FNaFew+99jb2N8hF+/DwhDyoQ3A8LhWz+ge dj0FvFPTDjECT03Xccpsrh0IkDdTDjdNRxvIod+YG0zx7LzZ4ajT/CsO0q/TaRKFBSlX y1wFR2WDw8xf/9yBNC2IyBtbtGSGS+NdMFHddLcfGVQCImflLL2h0aHqrLzZtx2apa4W gjQ5Hi3LNu2Fn/itCGs+mJ3sSu37wZFXiFqUhhQDPZh/kiGnFiSioTSc5Q9QfeIpGcUZ ZotXfZ95HBTIBxXA/30/MENL4W70GD24X0qKO2U/WfR4x5+Ymk+ZPgli3rizpBo7ya0R pIbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to:date :to:from:message-id:dkim-signature:delivered-to; bh=vDXYdQOIZFUH8jyUzFP9rF8E/VnNiA6V5uwf2LG7Omc=; b=tXHdNDDRfd6FTKzfdmL/XPu14o8Fj5PoMKD/sBv2SNPcfSUFekgQpeWkMpW21hc9w5 2+PWkb6cwZ1dms9W49PslyInJXvuB3xICS890t8g2M8tRBbAbV5hoE5tLuQnSDdgz2ER MZScJoxjo0cg/qHdg5SM44TYsdFoTsfaJ5sFOxhrodQiPWQ5IwMHKPe/PDe7w3bDeLEl NMIqIwgKOpWFaQhB/kd+wZFaaMUNKs4FGtKz1GqLvjVOT13ucZRxsVro32TFIRl8BLwg EnIHznlKxjm785pAHgVgjMj9zh3Iv0L2hauFxSTLBhTSx9czcz2dkJ54bhzh9y3TTYGW OeLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b=Ws9QHtCo; 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=foxmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id qo14-20020a170907874e00b007a92b00c094si8907986ejc.421.2022.12.04.09.13.41; Sun, 04 Dec 2022 09:13:41 -0800 (PST) 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=@foxmail.com header.s=s201512 header.b=Ws9QHtCo; 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=foxmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1694968BB94; Sun, 4 Dec 2022 19:13:09 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out203-205-221-205.mail.qq.com (out203-205-221-205.mail.qq.com [203.205.221.205]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CC1BF68B8BE for ; Sun, 4 Dec 2022 19:12:58 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1670173975; bh=/Jq+jWRoBNqhAJgtRRX2Dmf+D6tGdOXhOsDQTzj5vNM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Ws9QHtCoOEE9GNrx5QoRjtiQAE6iVwTjPPGXmKDK30yGDfB81JDJpaec0462lUHwU jqEAcCZYwPPjRy5EjxNdQbN9q5dwvEJWLUvddpM/5KSi65GdQXZgC2wiQEDWhl8kOz C3vSFUK0mGXaNwnH1eSwcdHrdEARsUREMqn7h2mw= Received: from localhost.localdomain ([14.153.79.182]) by newxmesmtplogicsvrszb1-0.qq.com (NewEsmtp) with SMTP id 334B3853; Mon, 05 Dec 2022 01:12:52 +0800 X-QQ-mid: xmsmtpt1670173974twmv9rf6z Message-ID: X-QQ-XMAILINFO: NrEcP6Y4Tjd7F2NSb5OS0k3uoyquotMyLYUZ/9DThWsYBlh4y17epFM4Fc3+IQ Q3gm/hrxW9JLJ17iFYvxxhoYF5PND/+3muzmrvquRhZHDzllT5ft6Y48gpxC8Tf9UO1ngpM//pwJ s3T/AY3T0S6NTQ2vTzhp6pLSFP0hJzS21fhyFH6eyzchyYKsz9w4xLdotPy91uu5Mu8iqj1nOlbD Gmy2ec5Lz9nf3mGrIywaEv96y0LUbGPNI9U3ZrqjODYXtojGh/qQIDet0wiZNUmgqNFirkfG2yOH Lr1knxQ8lYro9+8vn4dWYMWz52jslRXa5NnbdAS3s9hw8nSkiBrcMrFEn+S6ggf5QwJm+lkuV3rT pFV9oLbFMvNCb3/ib6rHwHfDqFEB+SIbIC8owAPbdl6Z5cUNwQCZDeTXRAksGCBRuWR3EVi0Nufl QWa80dT3xj0pVT/7dUm+IiAoBahQWoY2lRkE/ml667LlavWmTZxV+302aLaRHa2qIGJ8kd3dGmaV nPkpWrpOUqGITIwL7s0cP4ZQ5lr0C1dDRNOswWRVyaK4M/iu2ErvdRXWsN/2tyiu7JzgPDfdJyvd +FuEmgU33fR/wMnvTKER3SWdh3Tt2GOUGpa1F2W3ybt+B/zGpP/Kebans6PbZxiUZRPO+p2jYqFL uqq6Q5m6ukj0uMz/NkNmsxvVqd1pC19ThBOpMwrDbl1jfOXStuQjDUWGTPj8xvk0sO716mDqo4kn PWKA20Hm8IB76/USd9feOv4yH0RKLNQgIF5FWy05uREOlaNxBmPAb62Lhagn6L5W2U8ppsSwsKts 9W1lVPQb0uvdoBJv+A0JPWQGYKYkoTJdK9yg6xtUJRwAGq5QSXdhd82ZzkNeQ/5pymxoJyGYvCIy GZyktwkNjVxPOGrjS9erCU2QVgyuSkmc6a8r+PAzf9bmKGS9oVr3htZtpfg5TouedbDI/YZ2+7se EYeP+hT7cPGiBK4FwgIF0PPXiN2hbhqQnA5RwTy8pG8POPBSaqRDa0LI5HFeg7qwVGngBycSk= From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Mon, 5 Dec 2022 01:12:24 +0800 X-OQ-MSGID: <20221204171228.50160-3-quinkblack@foxmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221204171228.50160-1-quinkblack@foxmail.com> References: <20221204171228.50160-1-quinkblack@foxmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/7] avcodec/mediacodecenc: add level option 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: Zhao Zhili Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: As1RRd3+7uKM From: Zhao Zhili --- libavcodec/mediacodecenc.c | 143 ++++++++++++++++++++++++++++++++++++- libavcodec/version.h | 2 +- 2 files changed, 142 insertions(+), 3 deletions(-) diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c index c28cce56c6..d098880941 100644 --- a/libavcodec/mediacodecenc.c +++ b/libavcodec/mediacodecenc.c @@ -80,6 +80,7 @@ typedef struct MediaCodecEncContext { AVFrame *frame; int bitrate_mode; + int level; } MediaCodecEncContext; enum { @@ -233,6 +234,10 @@ static av_cold int mediacodec_init(AVCodecContext *avctx) av_log(avctx, AV_LOG_DEBUG, "set profile to 0x%x\n", ret); ff_AMediaFormat_setInt32(format, "profile", ret); } + if (s->level > 0) { + av_log(avctx, AV_LOG_DEBUG, "set level to 0x%x\n", s->level); + ff_AMediaFormat_setInt32(format, "level", s->level); + } ret = ff_AMediaCodec_getConfigureFlagEncode(s->codec); ret = ff_AMediaCodec_configure(s->codec, format, s->window, NULL, ret); @@ -540,17 +545,151 @@ const FFCodec ff_ ## short_name ## _mediacodec_encoder = { \ }; \ #if CONFIG_H264_MEDIACODEC_ENCODER + +enum MediaCodecAvcLevel { + AVCLevel1 = 0x01, + AVCLevel1b = 0x02, + AVCLevel11 = 0x04, + AVCLevel12 = 0x08, + AVCLevel13 = 0x10, + AVCLevel2 = 0x20, + AVCLevel21 = 0x40, + AVCLevel22 = 0x80, + AVCLevel3 = 0x100, + AVCLevel31 = 0x200, + AVCLevel32 = 0x400, + AVCLevel4 = 0x800, + AVCLevel41 = 0x1000, + AVCLevel42 = 0x2000, + AVCLevel5 = 0x4000, + AVCLevel51 = 0x8000, + AVCLevel52 = 0x10000, + AVCLevel6 = 0x20000, + AVCLevel61 = 0x40000, + AVCLevel62 = 0x80000, +}; + static const AVOption h264_options[] = { COMMON_OPTION + { "level", "Specify level", + OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, "level" }, + { "1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel1 }, 0, 0, VE, "level" }, + { "1b", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel1b }, 0, 0, VE, "level" }, + { "1.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel11 }, 0, 0, VE, "level" }, + { "1.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel12 }, 0, 0, VE, "level" }, + { "1.3", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel13 }, 0, 0, VE, "level" }, + { "2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel2 }, 0, 0, VE, "level" }, + { "2.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel21 }, 0, 0, VE, "level" }, + { "2.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel22 }, 0, 0, VE, "level" }, + { "3", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel3 }, 0, 0, VE, "level" }, + { "3.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel31 }, 0, 0, VE, "level" }, + { "3.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel32 }, 0, 0, VE, "level" }, + { "4", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel4 }, 0, 0, VE, "level" }, + { "4.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel41 }, 0, 0, VE, "level" }, + { "4.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel42 }, 0, 0, VE, "level" }, + { "5", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel5 }, 0, 0, VE, "level" }, + { "5.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel51 }, 0, 0, VE, "level" }, + { "5.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel52 }, 0, 0, VE, "level" }, + { "6.0", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel6 }, 0, 0, VE, "level" }, + { "6.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel61 }, 0, 0, VE, "level" }, + { "6.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel62 }, 0, 0, VE, "level" }, { NULL, } }; + DECLARE_MEDIACODEC_ENCODER(h264, "H.264", AV_CODEC_ID_H264) -#endif + +#endif // CONFIG_H264_MEDIACODEC_ENCODER #if CONFIG_HEVC_MEDIACODEC_ENCODER + +enum MediaCodecHevcLevel { + HEVCMainTierLevel1 = 0x1, + HEVCHighTierLevel1 = 0x2, + HEVCMainTierLevel2 = 0x4, + HEVCHighTierLevel2 = 0x8, + HEVCMainTierLevel21 = 0x10, + HEVCHighTierLevel21 = 0x20, + HEVCMainTierLevel3 = 0x40, + HEVCHighTierLevel3 = 0x80, + HEVCMainTierLevel31 = 0x100, + HEVCHighTierLevel31 = 0x200, + HEVCMainTierLevel4 = 0x400, + HEVCHighTierLevel4 = 0x800, + HEVCMainTierLevel41 = 0x1000, + HEVCHighTierLevel41 = 0x2000, + HEVCMainTierLevel5 = 0x4000, + HEVCHighTierLevel5 = 0x8000, + HEVCMainTierLevel51 = 0x10000, + HEVCHighTierLevel51 = 0x20000, + HEVCMainTierLevel52 = 0x40000, + HEVCHighTierLevel52 = 0x80000, + HEVCMainTierLevel6 = 0x100000, + HEVCHighTierLevel6 = 0x200000, + HEVCMainTierLevel61 = 0x400000, + HEVCHighTierLevel61 = 0x800000, + HEVCMainTierLevel62 = 0x1000000, + HEVCHighTierLevel62 = 0x2000000, +}; + static const AVOption hevc_options[] = { COMMON_OPTION + { "level", "Specify tier and level", + OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, "level" }, + { "m1", "Main tier level 1", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel1 }, 0, 0, VE, "level" }, + { "h1", "High tier level 1", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel1 }, 0, 0, VE, "level" }, + { "m2", "Main tier level 2", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel2 }, 0, 0, VE, "level" }, + { "h2", "High tier level 2", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel2 }, 0, 0, VE, "level" }, + { "m2.1", "Main tier level 2.1", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel21 }, 0, 0, VE, "level" }, + { "h2.1", "High tier level 2.1", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel21 }, 0, 0, VE, "level" }, + { "m3", "Main tier level 3", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel3 }, 0, 0, VE, "level" }, + { "h3", "High tier level 3", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel3 }, 0, 0, VE, "level" }, + { "m3.1", "Main tier level 3.1", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel31 }, 0, 0, VE, "level" }, + { "h3.1", "High tier level 3.1", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel31 }, 0, 0, VE, "level" }, + { "m4", "Main tier level 4", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel4 }, 0, 0, VE, "level" }, + { "h4", "High tier level 4", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel4 }, 0, 0, VE, "level" }, + { "m4.1", "Main tier level 4.1", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel41 }, 0, 0, VE, "level" }, + { "h4.1", "High tier level 4.1", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel41 }, 0, 0, VE, "level" }, + { "m5", "Main tier level 5", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel5 }, 0, 0, VE, "level" }, + { "h5", "High tier level 5", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel5 }, 0, 0, VE, "level" }, + { "m5.1", "Main tier level 5.1", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel51 }, 0, 0, VE, "level" }, + { "h5.1", "High tier level 5.1", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel51 }, 0, 0, VE, "level" }, + { "m5.2", "Main tier level 5.2", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel52 }, 0, 0, VE, "level" }, + { "h5.2", "High tier level 5.2", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel52 }, 0, 0, VE, "level" }, + { "m6", "Main tier level 6", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel6 }, 0, 0, VE, "level" }, + { "h6", "High tier level 6", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel6 }, 0, 0, VE, "level" }, + { "m6.1", "Main tier level 6.1", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel61 }, 0, 0, VE, "level" }, + { "h6.1", "High tier level 6.1", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel61 }, 0, 0, VE, "level" }, + { "m6.2", "Main tier level 6.2", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel62 }, 0, 0, VE, "level" }, + { "h6.2", "High tier level 6.2", + 0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel62 }, 0, 0, VE, "level" }, { NULL, } }; + DECLARE_MEDIACODEC_ENCODER(hevc, "H.265", AV_CODEC_ID_HEVC) -#endif + +#endif // CONFIG_HEVC_MEDIACODEC_ENCODER diff --git a/libavcodec/version.h b/libavcodec/version.h index 527b4dbd0b..61bdf5806b 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -30,7 +30,7 @@ #include "version_major.h" #define LIBAVCODEC_VERSION_MINOR 54 -#define LIBAVCODEC_VERSION_MICRO 102 +#define LIBAVCODEC_VERSION_MICRO 103 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \