From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 900044DE9B for ; Wed, 5 Mar 2025 02:21:43 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C302D68EC31; Wed, 5 Mar 2025 04:21:29 +0200 (EET) Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B459768EA94 for ; Wed, 5 Mar 2025 04:21:23 +0200 (EET) Received: by mail.gandi.net (Postfix) with ESMTPSA id 1A3144428E for ; Wed, 5 Mar 2025 02:21:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1741141283; 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=FlaTZHkw2x3MzRNu0gOEPMeARBx25epK49+jYUyGoOk=; b=HIyGiiO5lTmY9Xg1q9iwrObN/Gp3elBmvxfFe3PDRvg+rfea4BMBItudO/Jkuldq/ebP1+ tQOnKMZBCMifQLWI97edJtJU0NVh3fYVehuPBqwLiye6CgDUBu//YUH8C0BJbQb1mCnNqX UqY8RLme+eo3fXHgrX4hA48X3DZIGENX4uNeSBaEd7CMYMpZi5v+UPbiUzqhNdKsUnRz2w 2w3oe5I3nXnjx3hhaJ3lDq8v2UjuDVrqH9kRzZqK7fbVr8GDcVmBT3fPiEJnaEClp1IWom PZ5bdL4cpzcN32FYzAzKuCV2YD6+SNNmVRz/7GKY0NX0QEZmnTEKCcdAKEHDMg== From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Wed, 5 Mar 2025 03:21:20 +0100 Message-ID: <20250305022120.1706478-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250305022120.1706478-1-michael@niedermayer.cc> References: <20250305022120.1706478-1-michael@niedermayer.cc> MIME-Version: 1.0 X-GND-State: clean X-GND-Score: -70 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddutdefieefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfghrlhcuvffnffculdeftddmnecujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefoihgthhgrvghlucfpihgvuggvrhhmrgihvghruceomhhitghhrggvlhesnhhivgguvghrmhgrhigvrhdrtggtqeenucggtffrrghtthgvrhhnpedvgfefudeijeetieejkefgfffhtdeludeuffdvfeelieevjeetvedufeetfeejfeenucfkphepgedurdeiiedrieejrdduudefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepgedurdeiiedrieejrdduudefpdhhvghloheplhhotggrlhhhohhsthdpmhgrihhlfhhrohhmpehmihgthhgrvghlsehnihgvuggvrhhmrgihvghrrdgttgdpnhgspghrtghpthhtohepuddprhgtphhtthhopehffhhmphgvghdquggvvhgvlhesfhhfmhhpvghgrdhorhhg X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/ffv1: Use dual run coder for fltmap 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: This improves compression by 0.1% overall I tried several other things but so far this is the best compromise between complexity and compression Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer --- libavcodec/ffv1dec_template.c | 10 ++++++++-- libavcodec/ffv1enc_template.c | 13 +++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c index 1fa9933d984..1f8aeb52a2d 100644 --- a/libavcodec/ffv1dec_template.c +++ b/libavcodec/ffv1dec_template.c @@ -159,9 +159,15 @@ static int RENAME(decode_rgb_frame)(FFV1Context *f, FFV1SliceContext *sc, for (int p= 0; p<3 + transparency; p++) { int j = 0; int lu = 0; - uint8_t state[2] = {128, 128}; + uint8_t state[2][32]; + int run = -1; + memset(state, 128, sizeof(state)); for (int i= 0; i<65536; i++) { - int u = get_rac(&sc->c, state + lu); + int u; + if (run < 0) + run = get_symbol_inline(&sc->c, state[lu], 0); + u = lu ^ !run; + run --; sc->fltmap[p][j] = i ^ ((i&0x8000) ? 0 : 0x7FFF); j+= u; lu = u; diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c index 4c7cd2e647c..e62fa140bee 100644 --- a/libavcodec/ffv1enc_template.c +++ b/libavcodec/ffv1enc_template.c @@ -177,15 +177,24 @@ static int RENAME(encode_rgb_frame)(FFV1Context *f, FFV1SliceContext *sc, for (int p= 0; p<3 + transparency; p++) { int j = 0; int lu = 0; - uint8_t state[2] = {128, 128}; + uint8_t state[2][32]; + int run = 0; + memset(state, 128, sizeof(state)); for (int i= 0; i<65536; i++) { int ri = i ^ ((i&0x8000) ? 0 : 0x7FFF); int u = sc->fltmap[p][ri]; sc->fltmap[p][ri] = j; j+= u; - put_rac(&sc->c, state + lu, u); + + if (lu == u) { + run ++; + } else { + put_symbol_inline(&sc->c, state[lu], run, 0, NULL, NULL); + run = 0; + } lu = u; } + put_symbol(&sc->c, state[lu], run, 0); } } -- 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".