From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <ffmpeg-devel-bounces@ffmpeg.org> Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 4F0884A175 for <ffmpegdev@gitmailbox.com>; Mon, 24 Mar 2025 17:41:47 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0676B687C34; Mon, 24 Mar 2025 19:40:08 +0200 (EET) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 59CEA687C12 for <ffmpeg-devel@ffmpeg.org>; Mon, 24 Mar 2025 19:39:56 +0200 (EET) Received: by mail.gandi.net (Postfix) with ESMTPSA id 7DCFC20452 for <ffmpeg-devel@ffmpeg.org>; Mon, 24 Mar 2025 17:39:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1742837995; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=n2K0PPtZZXYCmNUmWPgzCxv6POhKl98VDicx28Db3no=; b=g5P4PNhV1Ha3OXfRXaDSYMunW5f35JkMjOsAAvQzj0KOLw6y6Vx/wdhomZ6o+zSY55t7Jk RfDcfpO/JRgKl0draLF33Gy+sTSh2kxrWDHN0005HyPUK4mOQ5yuFlJ9QcDN5k87uOrXrm xwIARIhTaE0bD4GwRzouOOV+8sw6AUF00cnAn/Ir6++ksniQAyhpCHlP0pC2cyxjdsC38u UTk74feH5BR4sIPZTa3jZBC2EOUPfRUvzF98FGrs04vBiKDj23xZ2kA7fsxHDnRRwQTr4N jUNINGwdGYjsK+ANI5e7Vc3b6Ru3I/3X8oxCGSy17i6PpqIqtidwToenqnFQag== From: Michael Niedermayer <michael@niedermayer.cc> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Date: Mon, 24 Mar 2025 18:39:45 +0100 Message-ID: <20250324173945.2574461-11-michael@niedermayer.cc> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250324173945.2574461-1-michael@niedermayer.cc> References: <20250324173945.2574461-1-michael@niedermayer.cc> MIME-Version: 1.0 X-GND-State: clean X-GND-Score: -70 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduiedtfeelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfghrlhcuvffnffculdeftddmnecujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefoihgthhgrvghlucfpihgvuggvrhhmrgihvghruceomhhitghhrggvlhesnhhivgguvghrmhgrhigvrhdrtggtqeenucggtffrrghtthgvrhhnpedvgfefudeijeetieejkefgfffhtdeludeuffdvfeelieevjeetvedufeetfeejfeenucfkphepgedurdeiiedrieejrdduudefnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehinhgvthepgedurdeiiedrieejrdduudefpdhhvghloheplhhotggrlhhhohhsthdpmhgrihhlfhhrohhmpehmihgthhgrvghlsehnihgvuggvrhhmrgihvghrrdgttgdpnhgspghrtghpthhtohepuddprhgtphhtthhopehffhhmphgvghdquggvvhgvlhesfhhfmhhpvghgrdhorhhg X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 11/11] avcodec/ffv1enc: Heuristic to select fixed in float multipliers X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org> List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>, <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe> List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel> List-Post: <mailto:ffmpeg-devel@ffmpeg.org> List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help> List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>, <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe> Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org> Archived-At: <https://master.gitmailbox.com/ffmpegdev/20250324173945.2574461-11-michael@niedermayer.cc/> List-Archive: <https://master.gitmailbox.com/ffmpegdev/> List-Post: <mailto:ffmpegdev@gitmailbox.com> Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- libavcodec/ffv1enc.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index c3b3b926adf..004ea73e06b 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -1408,17 +1408,30 @@ static void encode_float32_remap(FFV1Context *f, FFV1SliceContext *sc, s.i = 0; s.p = p; - s.mul_count = 1; - + for(int v = 0; v< 512; v++) { + if (v >= 0x378/8 && v <= 23 + 0x378/8) { + s.mul[v] = -(0x800080 >> (v - 0x378/8)); + } else + s.mul[v] = -1; + } for (int i= 0; i<s.pixel_num; i++) { int64_t val = unit[p][i].val; if (val != last_val) { av_assert2(last_val < val); for(int si= 0; si < FF_ARRAY_ELEMS(score_tab); si++) { int64_t delta = val - last_val; - int mul = last_val < 0 ? 1 : (1<<si); - int64_t cost = FFMAX((delta + mul/2) / mul, 1); - score_tab[si] += log2(cost) + fabs(delta - cost*mul); + int mul; + int64_t cost; + + if (last_val < 0) { + mul = 1; + } else if (si + 1 == FF_ARRAY_ELEMS(score_tab)) { + mul = -s.mul[ (last_val + 1) >> (32-9) ]; + } else + mul = 1<<si; + + cost = FFMAX((delta + mul/2) / mul, 1); + score_tab[si] += log2(cost) + log2(fabs(delta - cost*mul)+1); } last_val = val; } @@ -1428,7 +1441,12 @@ static void encode_float32_remap(FFV1Context *f, FFV1SliceContext *sc, if (score_tab[si] < score_tab[ best_index ]) best_index = si; } - s.mul[0] = -1 << best_index; + if (best_index + 1 < FF_ARRAY_ELEMS(score_tab)) { + s.mul[0] = -1 << best_index; + s.mul_count = 1; + } else { + s.mul_count = 512; + } s.mul[s.mul_count] = 1; encode_float32_remap_segment(sc, unit, &s, 1, 1); -- 2.48.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".