From patchwork Wed Nov 6 12:31:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Zhili X-Patchwork-Id: 52613 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:2fe5:b0:4a6:1c7:11b7 with SMTP id kw5csp617804vqb; Wed, 6 Nov 2024 04:39:08 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVDtlxbff4Jc9fLFYKxhyYYgUOaSjLW7H3MJ+Q3olyUwgKSyv1ymVkugmi6/E/22uvUyxJ5yzBBACv9QVPX6gOT@gmail.com X-Google-Smtp-Source: AGHT+IGe9E4H6SK2QetjXreFldG0x0B6vQHuGSaDPUi5LSBXODhM01ea4PAI4zfvAA0iG1gazRby X-Received: by 2002:a17:907:9608:b0:a99:4a35:2400 with SMTP id a640c23a62f3a-a9de5fa8260mr1363328266b.7.1730896747959; Wed, 06 Nov 2024 04:39:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1730896747; cv=none; d=google.com; s=arc-20240605; b=WYVSBdiYkLJovdLA+srK+ac94QTQXV2x2tjvADN3GBYqoGanOI1byhP+fR5zdovUYJ 99LExrUIewtMzqWRt9zqvyGksHUmExp89sTqrYFHaESnITHh+WQE6kEviwCVqdneChbG ZqlIwXgNmzxwK30XMGTpCSsoN5cqB7sHGFwBwsAyA9lkYNyTiIA2qMMzLNT755OlX1+B Ji7s7wUw5Sc6w1iqJtIsxEneTmI4PkE2eE3qkuRAUKxRAzAUsyDusih+Bii4mRrXpbzy n6QhtpaV/iejE1138HQyapL9xmADw+NqM9ER7d+KxhOG6L60NAX4oiG9hjGpxI4O4G9h 0RaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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:date:to:from:message-id :dkim-signature:delivered-to; bh=QxNUt4gvH/i6n/ew10pFtaPRRoAwzatrH/8wm3q0GBY=; fh=HnHYuZ9XgUo86ZRXTLWWmQxhslYEI9B9taZ5X1DLFfc=; b=BP8nglfIcqkFx2MvsZ+7zL245dXShG/Ntz5zs9uBOkg52vXhzN87k2g1Sm3r/Z0imC VocE7TnPnBpYKVK82XuR+A0FUwNf3oHILxXaKn6E2ZAmEbNt4+ODdi5OpKiOXyB/Z6l0 QntxgHZ71LpFA8pZjlf/hliGccchEgLBqs+gdZ2bVjMHJfYfFz9j3Lg/j/oCqNyAqKWY 0lB3HxLDZdKeO7XsHU5hbi1aXp9wonKeCCahP9wc365ItYTkc3xxzCltqyuhIDvwzhuG da3Lh6t5xnVKmXsrp5JvQXDVoW6+0acR/l2N+QADc9GRGyCHdk2SlRpEeTrFz1l3eIhm suEg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b=MQ5Fl6O4; 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 a640c23a62f3a-a9eb17ce0c2si126106266b.346.2024.11.06.04.39.07; Wed, 06 Nov 2024 04:39:07 -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=MQ5Fl6O4; 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 8B5BF68DC62; Wed, 6 Nov 2024 14:31:42 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out203-205-221-236.mail.qq.com (out203-205-221-236.mail.qq.com [203.205.221.236]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5417D68DD1F for ; Wed, 6 Nov 2024 14:31:34 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1730896286; bh=HKu1VOJlE5p1rQtHReJmqjqsJOSyy4OgbUc0r/6UeNk=; h=From:To:Cc:Subject:Date; b=MQ5Fl6O4vVaU/vx3aY02+svMieuu9QSwoIyofvfsqwbK4KTIpJwCo+B133puMJ3ej ZcCiaz5BC/JLQVB06ue2bDAMGtf+kfO8aWdcK8WhNfvq1tuK0kmXq0qY2p54dqG4al 87mYRaldDxMbExzatB3KfROnynf/4nm3BoS6zaOc= Received: from ZHILIZHAO-MB1.tencent.com ([59.37.125.101]) by newxmesmtplogicsvrsza36-0.qq.com (NewEsmtp) with SMTP id 7D8B0E0D; Wed, 06 Nov 2024 20:31:24 +0800 X-QQ-mid: xmsmtpt1730896284tjigj7a1m Message-ID: X-QQ-XMAILINFO: NkHKfw09D6j8Mr3e6EuYzqu22Zhec5siHINJxBJ4cCZT8gst6tr6n5lXqpV5wR GdQR7+Ny7fbnAgoTg8xOxrN25xACWRZYUhxK2I7VtSTzzXrSpy3A7/zYORYkkbe3kok4obqW1iqt 3+0qK9bdJ4mIAtyPLiLMm6pDLiheMnlqELaH6l04Y3V0T7wqMiEfK3NTEDrPItfF3o4jtn77VIWu ZQIgzQ8wyYS/GR1MYyubPjvUu0fZwEyvHpTPh5ruH427PqVGFyPvGyYBMb6KWX8ubFjRJcmoik63 ank4Up73gCFZ4zUqRfLCjODOwhFG2+Wx2U1+okAzKQzMPBiEhdgruX3S6P1MlXLUgsXDozNLSHx6 peHDV25zo4rKOQPPELsSZS66MD0uU+d48QFyImn2tjwuCvepDpIMeFAemFrI03+7vRlhJQvpxCS0 AxUEfTSB5+ph27gCa7i4+m9vyh6c693D3JMbhzJ6Cq/vONS4wCi239t2EImd2dQeTntSAM+/QfU8 V38mSja0qayY6BSSRc5SGq6HV8vYcQnwauBCfuMhD7XGB470H1Q/yMJQB5o4noUKhXLXY3eCPFMt EGmxFsNDwfvXqG6bhGPAfDVKl4DZU4XyJAse7QmfW2ojzL2JMGaRDpXLsllusgRgMu4NoxvSfHiP Qszht4ESi1i4nxPE0LuJBZWGjpAgDuwCnnjxjQxLi2TivPa6DSg4WO5nmGcEyFXsj5blG6miA/S7 gH+oeMB6ZTkS2BvXOedZr+AyBjN9WGzpcBf91aoxQyD0bqaMggaWAC/ngXh7f9P/hCeYeWLjeORz 5UTQWtV9R4FbTqcGan/vxOGtweUkG8SlhWU0SWGwzFKnTlIeXXg9jP5igEZsIonjLIdw40Fvm+bx mBzbgJlKdqf4nqISxB2O3jZazG3psk+pLi1Ee6YjKv2p16TEkGjjW0KCXfJg0gqzZHk58rCDaNyD x6LXIGEysf+zHGQfUq8v2Gn71DnM49grOOQUv3leb+z0Cl6lzen2ppdK3gnfvj9oIl4ICdKdk4pd KvU4IBsw== X-QQ-XMRINFO: Nq+8W0+stu50PRdwbJxPCL0= From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Nov 2024 20:31:21 +0800 X-OQ-MSGID: <20241106123121.17284-1-quinkblack@foxmail.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/4] avcodec/mediacodecenc: Add operating_rate 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: 26M+9Q/brtvq From: Zhao Zhili For example, with ./ffmpeg -operating_rate 400 -hwaccel mediacodec -i test.mp4 -an \ -c:v h264_mediacodec -operating_rate 400 -b:v 5M -f null - The transcoding speed is 254 FPS. Without -operating_rate on dec/enc, the speed is 148 FPS. With -operating_rate on decoder only, the speed is 239 FPS. --- libavcodec/mediacodecenc.c | 7 ++++++- libavcodec/version.h | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c index 3880ea2fe9..e79fe29964 100644 --- a/libavcodec/mediacodecenc.c +++ b/libavcodec/mediacodecenc.c @@ -76,6 +76,8 @@ typedef struct MediaCodecEncContext { int level; int pts_as_dts; int extract_extradata; + // Ref. MediaFormat KEY_OPERATING_RATE + int operating_rate; } MediaCodecEncContext; enum { @@ -354,6 +356,8 @@ static av_cold int mediacodec_init(AVCodecContext *avctx) } if (s->pts_as_dts == -1) s->pts_as_dts = avctx->max_b_frames <= 0; + if (s->operating_rate > 0) + ff_AMediaFormat_setInt32(format, "operating-rate", s->operating_rate); ret = ff_AMediaCodec_getConfigureFlagEncode(s->codec); ret = ff_AMediaCodec_configure(s->codec, format, s->window, NULL, ret); @@ -764,7 +768,8 @@ static const AVCodecHWConfigInternal *const mediacodec_hw_configs[] = { { "pts_as_dts", "Use PTS as DTS. It is enabled automatically if avctx max_b_frames <= 0, " \ "since most of Android devices don't output B frames by default.", \ OFFSET(pts_as_dts), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE }, \ - + { "operating_rate", "The desired operating rate that the codec will need to operate at, zero for unspecified", \ + OFFSET(operating_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE }, \ #define MEDIACODEC_ENCODER_CLASS(name) \ static const AVClass name ## _mediacodec_class = { \ diff --git a/libavcodec/version.h b/libavcodec/version.h index 9411511e04..9f55381cf1 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -30,7 +30,7 @@ #include "version_major.h" #define LIBAVCODEC_VERSION_MINOR 22 -#define LIBAVCODEC_VERSION_MICRO 100 +#define LIBAVCODEC_VERSION_MICRO 101 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \