From patchwork Wed Dec 7 09:31:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Zhili X-Patchwork-Id: 39638 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp415470pzb; Wed, 7 Dec 2022 01:32:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf5Chl0FCTWQ35Se6sS6qDqdMekFS5xUVBfDnqtE+YDW6ScVyZagh9xp/RmAnaN6XWehiJKr X-Received: by 2002:a17:906:c1d0:b0:7b4:64d3:e6f4 with SMTP id bw16-20020a170906c1d000b007b464d3e6f4mr28949587ejb.594.1670405558891; Wed, 07 Dec 2022 01:32:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670405558; cv=none; d=google.com; s=arc-20160816; b=lEGOW7uifWeFmFN1XQU5P/NI7GpD0KK7WPwdAHtzRCJFStmZxu4n/RhvPGcilEOAQM 8u4ffn1kFEEbeRBVs8GDm7PzrQ5rU5ETe4FkYiNkcPDB1vxDmpjlI2gTVjjrRKFYtyTq nPKb/GXeuMpeSGlnH8dTGOmDFBbUXcdu/EjiJH8MlLv9ElRgqLVoH3dpz3zm5zSmyYTP pdOjtpnB+spYPKK9yCVww8ofVjCvSY3UaA2dc998izJdvkB4C24xf5rESWfbU/dvT5o+ FhevFFxeERdFNqpppRmM64+zUg56Rv3u4g5wNF1SeArJoperknZhAgiZhEg5iHBZJGxB o+cg== 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=kWg/sUF0kU0FfabDQ9HQBDauj1hDHeNj+381gUhXrpc=; b=l1Y61Bh6s/bGkpqT4+pQufAbQLCUG3h9rm/bPoYN2f82wsoaCxWvd5grS21ehYji84 W8QnfZ8Bk9/60nEJyeZ240B8JQo25suk0clPQqv9BPLMxHZNcYoAWlrRHBAGJ3AcZfaP gppoF/SfifAWGhRSSmlQlIKK/wdYzd9c8H/Qduf0IBC4rmx9nXuR0LZ1Ei9ks4N+dtm9 pzrCv91b9woqF+rA7KMudvm3INQrlmCxB7QAeX89HeKRHylMy23wegw5NPWMPfQl/06N yNUQJcg9uF25WwwX2vZZbRPqS0dT45v5y2uB7EdFJ+XXiFBCFR4mTQzRkHX2LIymdP9g Pgrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b=K86NwpBl; 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 nd27-20020a170907629b00b0078a19032c70si17727196ejc.334.2022.12.07.01.32.38; Wed, 07 Dec 2022 01:32:38 -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=K86NwpBl; 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 23E1D68BD55; Wed, 7 Dec 2022 11:32:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out203-205-221-155.mail.qq.com (out203-205-221-155.mail.qq.com [203.205.221.155]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5B5A968BD38 for ; Wed, 7 Dec 2022 11:32:04 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1670405520; bh=w2lltVFjK8AJLqciCftvj3M75KTn9UYnbA3OKDg5Wf0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=K86NwpBl3KTzh3ryEBQq5xN5CURKxJkcGAWQvWUtSggpuw2rE0iw4k7RA3vUgzmpi ruaR1W9gStqurJe6OS0+WTmFOBa20EtnrZy4gA3+l57C3SWIvYTO3N3alAvQ2NQaqS oR03sDJ6v3kRIgyx+sAAyKHAlDAbpfyn/7sLrODU= Received: from localhost.localdomain ([59.37.125.102]) by newxmesmtplogicsvrszb1-0.qq.com (NewEsmtp) with SMTP id 7F9B046E; Wed, 07 Dec 2022 17:31:57 +0800 X-QQ-mid: xmsmtpt1670405520tys0ufr9f Message-ID: X-QQ-XMAILINFO: Mg/0DM1Zd+nHItQktWwJQNLgSEXfSt50pyuBMVIGVNCcrmF4FpKB+QCMjBwg5p mCpIOGsz700XIBbiGwoRQHsJL4Rqyibw7pY5klGIixUkSR8hrDJFF6fqwVTzPBTLochS6/UykFsB m70rt3c0bEBfs627i7f6fiuQiOlMlBIQh1jaejvn00faoXmHM8MNmOgbQkfDRU/ZIr4fNBQFFZNy gPqqFyUZ9tYcAQ87BGKnU9WKckbK3CUGBGSgponDV9yYd8PQGh0EIEIMtCqcmIUEohy4KkKPfHUU zE0IAagoRL5q8GK6Ze2K7QA2N5FKJEcyr74/FOX8+4tL2KT5ROSnyJ2V+pTFCN8MEmdVgLVO/vca OCuHyS4RK9wXkxZ41Tol73j1/i6/rFcoC31nTBUBlfEK+Oc90v0I97qfNvya/sRVw3+bwwE5/fMN 6SR4w3Bk2VwxEq4ZBB7ppc6K6Ck7vNeGjZMLHmJqp6yOEIHRe+gkGCYzVmTK2tlqlC43t3+C+t9P Mh7YJnFgcvFpPLNCy0qIkawTimvjQYgvti1t4kCcaof25L+eRxYHQym7ejfsqCkKcBhwr3WHhTBs iAoEqqBNOq5oFOeiRozFpyugp3sAiO6TVf+w9fz3FcvZ0ooN0bAwEAAAaSV0xSINNDxnPfRcp7RH 6p9ij10WtMGioZY36CQyclryXb90NbMPv5v5djO6K541tFSbW/WzORpro3Y5wLkdv8yWNwOwpXwf CVJ20RQgk/dTv1HTEfJsiXw62umeAos9cW/KcdFYXTk/N6Ba2fHALDvC1ngqb1LEsrcYRAyF+xlq CkrHGfZ/Wvgj7nY+WazMXWqDejKmOYTusMprZeMqBGdksXgXKUc+r4L3SrmtsF5theR6RSFIHpb2 cJwPI14oTk8YEX3HT5G+j5wjhPu6t66uLE044LYqGCkSNgyG6OIc4Eao23CcvU95T5XurYO66gnT NDk7a9oAtch69XS8FY82gqSEwTt022zxtozJGLC64= From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Wed, 7 Dec 2022 17:31:18 +0800 X-OQ-MSGID: <20221207093122.553668-4-quinkblack@foxmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221207093122.553668-1-quinkblack@foxmail.com> References: <20221207093122.553668-1-quinkblack@foxmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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: xfPqDdT1k6lh 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 ec0e0b3a86..2f78567451 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); @@ -541,17 +546,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, \