[FFmpeg-devel] [PATCH] avcodec/ffv1: NOT FOR GIT experiment seperately coding sign bits of float16
Michael Niedermayer
michael at niedermayer.cc
Sun Jan 19 01:01:10 EET 2025
The float sign bits seem to take about 1% of space in the compressed
bitstream. Storing it separately in a RC symbol each is worse
---
libavcodec/ffv1.c | 1 +
libavcodec/ffv1.h | 1 +
libavcodec/ffv1enc_template.c | 24 ++++++++++++++++--------
3 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index f303ed769f0..a9fa2959087 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -105,6 +105,7 @@ av_cold int ff_ffv1_init_slice_state(const FFV1Context *f,
sc->c.zero_state[256 - j] = 256 - sc->c.one_state[j];
}
}
+ memset(sc->newstate, 128, sizeof(sc->newstate));
return 0;
}
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index 2c2df154037..f2cc5a63d5e 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -104,6 +104,7 @@ typedef struct FFV1SliceContext {
uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];
};
};
+ uint8_t newstate[65536];
} FFV1SliceContext;
typedef struct FFV1Context {
diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c
index bc14926ab95..c6535373024 100644
--- a/libavcodec/ffv1enc_template.c
+++ b/libavcodec/ffv1enc_template.c
@@ -62,9 +62,17 @@ RENAME(encode_line)(FFV1Context *f, FFV1SliceContext *sc,
for (x = 0; x < w; x++) {
int diff, context;
+ int signstate = (1&(sample[0][x-1]>>15)) + 2*(sample[1][x]>>15) + 4*(sample[1][x-1]>>15) + 8*(sample[1][x+1]>>15);
+ put_rac(c, sc->newstate+signstate, 1&(sample[0][x]>>15));
+
context = RENAME(get_context)(f->quant_tables[p->quant_table_index],
sample[0] + x, sample[1] + x, sample[2] + x);
- diff = sample[0][x] - RENAME(predict)(sample[0] + x, sample[1] + x);
+ int64_t L = (sample[0][x-1]) & 0x7FFF;
+ int64_t T = (sample[1][x]) & 0x7FFF;
+ int64_t LT = (sample[1][x-1]) & 0x7FFF;
+
+ diff = (sample[0][x] & 0x7FFF) - mid_pred((L), (L + T - LT), (T));
+// diff = sample[0][x] - RENAME(predict)(sample[0] + x, sample[1] + x);
if (context < 0) {
context = -context;
@@ -180,13 +188,13 @@ static int RENAME(encode_rgb_frame)(FFV1Context *f, FFV1SliceContext *sc,
r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
}
- if (sc->slice_coding_mode != 1) {
- b -= g;
- r -= g;
- g += (b * sc->slice_rct_by_coef + r * sc->slice_rct_ry_coef) >> 2;
- b += offset;
- r += offset;
- }
+// if (sc->slice_coding_mode != 1) {
+// b -= g;
+// r -= g;
+// g += (b * sc->slice_rct_by_coef + r * sc->slice_rct_ry_coef) >> 2;
+// b += offset;
+// r += offset;
+// }
sample[0][0][x] = g;
sample[1][0][x] = b;
--
2.48.1
More information about the ffmpeg-devel
mailing list