Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/5] avcodec/ffv1enc: Eliminate encode_mul()
@ 2025-03-25 14:06 Michael Niedermayer
  2025-03-25 14:06 ` [FFmpeg-devel] [PATCH 2/5] avcodec/ffv1dec: Fix end handling Michael Niedermayer
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Michael Niedermayer @ 2025-03-25 14:06 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/ffv1enc.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 6818de92494..162bf7b804f 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -1289,15 +1289,6 @@ static inline void copy_state(RemapEncoderState *dst, const RemapEncoderState *s
     dst->run1start_last_val = src->run1start_last_val;
 }
 
-static inline void encode_mul(RemapEncoderState *s, int mul_index)
-{
-    av_assert2(s->mul[ mul_index ]);
-    if (s->mul[ mul_index ] < 0) {
-        s->mul[ mul_index ] *= -1;
-        put_symbol_inline(&s->rc, s->state[0][2], s->mul[ mul_index ], 0, NULL, NULL);
-    }
-}
-
 static int encode_float32_remap_segment(FFV1SliceContext *sc,
                                         RemapEncoderState *state_arg, int update, int final)
 {
@@ -1386,7 +1377,11 @@ static int encode_float32_remap_segment(FFV1SliceContext *sc,
             s.last_val = val;
             s.current_mul_index = ((s.last_val + 1) * s.mul_count) >> 32;
             if (!s.run || s.run1final) {
-                encode_mul(&s, s.current_mul_index);
+                av_assert2(s.mul[ s.current_mul_index ]);
+                if (s.mul[ s.current_mul_index ] < 0) {
+                    s.mul[ s.current_mul_index ] *= -1;
+                    put_symbol_inline(&s.rc, s.state[0][2], s.mul[ s.current_mul_index ], 0, NULL, NULL);
+                }
                 s.compact_index ++;
             }
         }
-- 
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".

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [FFmpeg-devel] [PATCH 2/5] avcodec/ffv1dec: Fix end handling
  2025-03-25 14:06 [FFmpeg-devel] [PATCH 1/5] avcodec/ffv1enc: Eliminate encode_mul() Michael Niedermayer
@ 2025-03-25 14:06 ` Michael Niedermayer
  2025-03-25 14:06 ` [FFmpeg-devel] [PATCH 3/5] avcodec/ffv1enc: " Michael Niedermayer
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Michael Niedermayer @ 2025-03-25 14:06 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/ffv1dec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 25b55864107..3395f514f42 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -324,9 +324,9 @@ static int decode_remap(FFV1Context *f, FFV1SliceContext *sc)
                         return AVERROR_INVALIDDATA; //not sure we should check this
                     i += current_mul - 1 + delta;
                 }
-                if (i == end)
+                if (i - 1 >= end)
                     break;
-                if (i - 1 > end || j >= FF_ARRAY_ELEMS(sc->fltmap[p]))
+                if (j >= FF_ARRAY_ELEMS(sc->fltmap[p]))
                     return AVERROR_INVALIDDATA;
                 if (end <= 0xFFFF) {
                     sc->fltmap  [p][j++] = i ^ ((i&    0x8000) ? 0 : flip);
-- 
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".

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [FFmpeg-devel] [PATCH 3/5] avcodec/ffv1enc: Fix end handling
  2025-03-25 14:06 [FFmpeg-devel] [PATCH 1/5] avcodec/ffv1enc: Eliminate encode_mul() Michael Niedermayer
  2025-03-25 14:06 ` [FFmpeg-devel] [PATCH 2/5] avcodec/ffv1dec: Fix end handling Michael Niedermayer
@ 2025-03-25 14:06 ` Michael Niedermayer
  2025-03-25 14:06 ` [FFmpeg-devel] [PATCH 4/5] avcodec/ffv1enc: Fix off by 1 in assert Michael Niedermayer
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Michael Niedermayer @ 2025-03-25 14:06 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

This also produces smaller files

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/ffv1enc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 162bf7b804f..f8db3dc2c7d 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -1315,7 +1315,9 @@ static int encode_float32_remap_segment(FFV1SliceContext *sc,
             if (s.last_val == 0xFFFFFFFF) {
                 break;
             } else {
-                val = 1LL<<32;
+                val = s.last_val + ((1LL<<32) - s.last_val + current_mul - 1) / current_mul * current_mul;
+                av_assert2(val >= (1LL<<32));
+                val += s.lu * current_mul; //ensure a run1 ends
             }
         } else
             val = sc->unit[s.p][s.i].val;
@@ -1379,6 +1381,7 @@ static int encode_float32_remap_segment(FFV1SliceContext *sc,
             if (!s.run || s.run1final) {
                 av_assert2(s.mul[ s.current_mul_index ]);
                 if (s.mul[ s.current_mul_index ] < 0) {
+                    av_assert2(s.i < s.pixel_num);
                     s.mul[ s.current_mul_index ] *= -1;
                     put_symbol_inline(&s.rc, s.state[0][2], s.mul[ s.current_mul_index ], 0, NULL, NULL);
                 }
-- 
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".

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [FFmpeg-devel] [PATCH 4/5] avcodec/ffv1enc: Fix off by 1 in assert
  2025-03-25 14:06 [FFmpeg-devel] [PATCH 1/5] avcodec/ffv1enc: Eliminate encode_mul() Michael Niedermayer
  2025-03-25 14:06 ` [FFmpeg-devel] [PATCH 2/5] avcodec/ffv1dec: Fix end handling Michael Niedermayer
  2025-03-25 14:06 ` [FFmpeg-devel] [PATCH 3/5] avcodec/ffv1enc: " Michael Niedermayer
@ 2025-03-25 14:06 ` Michael Niedermayer
  2025-03-25 14:06 ` [FFmpeg-devel] [PATCH 5/5] avcodec/ffv1enc: Store run1start_mul_index instead of computing Michael Niedermayer
  2025-03-26 13:10 ` [FFmpeg-devel] [PATCH 1/5] avcodec/ffv1enc: Eliminate encode_mul() Michael Niedermayer
  4 siblings, 0 replies; 6+ messages in thread
From: Michael Niedermayer @ 2025-03-25 14:06 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/ffv1enc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index f8db3dc2c7d..d28cb8f5700 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -1355,7 +1355,7 @@ static int encode_float32_remap_segment(FFV1SliceContext *sc,
                         put_symbol_inline(&s.rc, s.state[s.lu][0], s.run, 0, NULL, NULL);
                         s.i                 = s.run1start_i;
                         s.last_val          = s.run1start_last_val; // we could compute this instead of storing
-                        av_assert2(s.last_val >= 0 && s.i > 0); // first state is zero run so we cant have this in a one run and current_mul_index would be -1
+                        av_assert2(s.last_val >= 0 && s.i >= 0); // first state is zero run so we cant have this in a one run and current_mul_index would be -1
                         if (s.run)
                             s.current_mul_index = ((s.last_val + 1) * s.mul_count) >> 32;
                     }
-- 
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".

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [FFmpeg-devel] [PATCH 5/5] avcodec/ffv1enc: Store run1start_mul_index instead of computing
  2025-03-25 14:06 [FFmpeg-devel] [PATCH 1/5] avcodec/ffv1enc: Eliminate encode_mul() Michael Niedermayer
                   ` (2 preceding siblings ...)
  2025-03-25 14:06 ` [FFmpeg-devel] [PATCH 4/5] avcodec/ffv1enc: Fix off by 1 in assert Michael Niedermayer
@ 2025-03-25 14:06 ` Michael Niedermayer
  2025-03-26 13:10 ` [FFmpeg-devel] [PATCH 1/5] avcodec/ffv1enc: Eliminate encode_mul() Michael Niedermayer
  4 siblings, 0 replies; 6+ messages in thread
From: Michael Niedermayer @ 2025-03-25 14:06 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Theres a special case I missed, its simpler to just store

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/ffv1enc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index d28cb8f5700..bc59f96746c 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -1268,6 +1268,7 @@ typedef struct RemapEncoderState {
     int run1final;
     int64_t run1start_i;
     int64_t run1start_last_val;
+    int run1start_mul_index;
 } RemapEncoderState;
 
 static inline void copy_state(RemapEncoderState *dst, const RemapEncoderState *src)
@@ -1287,6 +1288,7 @@ static inline void copy_state(RemapEncoderState *dst, const RemapEncoderState *s
     dst->run1final      = src->run1final;
     dst->run1start_i    = src->run1start_i;
     dst->run1start_last_val = src->run1start_last_val;
+    dst->run1start_mul_index = src->run1start_mul_index;
 }
 
 static int encode_float32_remap_segment(FFV1SliceContext *sc,
@@ -1337,6 +1339,7 @@ static int encode_float32_remap_segment(FFV1SliceContext *sc,
                 if (!s.run) {
                     s.run1start_i        = s.i - 1;
                     s.run1start_last_val = s.last_val;
+                    s.run1start_mul_index= s.current_mul_index;
                 }
                 if (step == 1) {
                     if (s.run1final) {
@@ -1355,9 +1358,7 @@ static int encode_float32_remap_segment(FFV1SliceContext *sc,
                         put_symbol_inline(&s.rc, s.state[s.lu][0], s.run, 0, NULL, NULL);
                         s.i                 = s.run1start_i;
                         s.last_val          = s.run1start_last_val; // we could compute this instead of storing
-                        av_assert2(s.last_val >= 0 && s.i >= 0); // first state is zero run so we cant have this in a one run and current_mul_index would be -1
-                        if (s.run)
-                            s.current_mul_index = ((s.last_val + 1) * s.mul_count) >> 32;
+                        s.current_mul_index = s.run1start_mul_index;
                     }
                     s.run1final ^= 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".

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/5] avcodec/ffv1enc: Eliminate encode_mul()
  2025-03-25 14:06 [FFmpeg-devel] [PATCH 1/5] avcodec/ffv1enc: Eliminate encode_mul() Michael Niedermayer
                   ` (3 preceding siblings ...)
  2025-03-25 14:06 ` [FFmpeg-devel] [PATCH 5/5] avcodec/ffv1enc: Store run1start_mul_index instead of computing Michael Niedermayer
@ 2025-03-26 13:10 ` Michael Niedermayer
  4 siblings, 0 replies; 6+ messages in thread
From: Michael Niedermayer @ 2025-03-26 13:10 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 590 bytes --]

On Tue, Mar 25, 2025 at 03:06:51PM +0100, Michael Niedermayer wrote:
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/ffv1enc.c | 15 +++++----------
>  1 file changed, 5 insertions(+), 10 deletions(-)

will apply patchset

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Many that live deserve death. And some that die deserve life. Can you give
it to them? Then do not be too eager to deal out death in judgement. For
even the very wise cannot see all ends. -- Gandalf

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-03-26 13:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-25 14:06 [FFmpeg-devel] [PATCH 1/5] avcodec/ffv1enc: Eliminate encode_mul() Michael Niedermayer
2025-03-25 14:06 ` [FFmpeg-devel] [PATCH 2/5] avcodec/ffv1dec: Fix end handling Michael Niedermayer
2025-03-25 14:06 ` [FFmpeg-devel] [PATCH 3/5] avcodec/ffv1enc: " Michael Niedermayer
2025-03-25 14:06 ` [FFmpeg-devel] [PATCH 4/5] avcodec/ffv1enc: Fix off by 1 in assert Michael Niedermayer
2025-03-25 14:06 ` [FFmpeg-devel] [PATCH 5/5] avcodec/ffv1enc: Store run1start_mul_index instead of computing Michael Niedermayer
2025-03-26 13:10 ` [FFmpeg-devel] [PATCH 1/5] avcodec/ffv1enc: Eliminate encode_mul() Michael Niedermayer

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git