[FFmpeg-cvslog] avcodec/ffv1: Implement jeromes idea of making remap flip optional
Michael Niedermayer
git at videolan.org
Fri Mar 14 03:06:11 EET 2025
ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Tue Mar 11 15:00:01 2025 +0100| [437cbd25e0894b69e6706136366ce4252a5ba6f6] | committer: Michael Niedermayer
avcodec/ffv1: Implement jeromes idea of making remap flip optional
This also makes remap optional (which is a good idea even if we decide to keep flip fixed)
Effect on compression (using 2 rawlsb, golomb rice, large context model with ACES_OT_VWG_SampleFrames
-rw-r----- 1 michael michael 499101306 Mär 11 14:58 float-303503-try3d-m2.nut
-rw-r----- 1 michael michael 503700199 Mär 11 14:57 float-303503-try3d-m1.nut
-rw-r----- 1 michael michael 518150578 Mär 11 14:57 float-303503-try3d-m0.nut
(the test above used the rawlsb patch, which is not applied yet)
Reviewed-by: Jerome Martinez <jerome at mediaarea.net>
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=437cbd25e0894b69e6706136366ce4252a5ba6f6
---
libavcodec/ffv1.h | 1 +
libavcodec/ffv1dec.c | 9 +++++----
libavcodec/ffv1enc.c | 20 +++++++++++++++++---
3 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index c23d64d54a..6e0e035895 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -137,6 +137,7 @@ typedef struct FFV1Context {
uint8_t (*initial_states[MAX_QUANT_TABLES])[32];
int colorspace;
int flt;
+ int remap_mode;
int use32bit;
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 37b14c0410..b731f11297 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -222,8 +222,8 @@ static int decode_slice_header(const FFV1Context *f,
}
if (f->combined_version >= 0x40004) {
sc->remap = ff_ffv1_get_symbol(c, state, 0);
- if (sc->remap > 1U ||
- sc->remap == 1 && !f->flt) {
+ if (sc->remap > 2U ||
+ sc->remap && !f->flt) {
av_log(f->avctx, AV_LOG_ERROR, "unsupported remap %d\n", sc->remap);
return AVERROR_INVALIDDATA;
}
@@ -246,6 +246,7 @@ static void slice_set_damaged(FFV1Context *f, FFV1SliceContext *sc)
static int decode_remap(FFV1Context *f, FFV1SliceContext *sc)
{
int transparency = f->transparency;
+ int flip = sc->remap == 2 ? 0x7FFF : 0;
for (int p= 0; p<3 + transparency; p++) {
int j = 0;
@@ -260,13 +261,13 @@ static int decode_remap(FFV1Context *f, FFV1SliceContext *sc)
if (lu) {
lu ^= !run;
while (run--) {
- sc->fltmap[p][j++] = i ^ ((i&0x8000) ? 0 : 0x7FFF);
+ sc->fltmap[p][j++] = i ^ ((i&0x8000) ? 0 : flip);
i++;
}
} else {
i += run;
if (i != 65536)
- sc->fltmap[p][j++] = i ^ ((i&0x8000) ? 0 : 0x7FFF);
+ sc->fltmap[p][j++] = i ^ ((i&0x8000) ? 0 : flip);
lu ^= !run;
}
}
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index e89e4c9e2c..406cc052ae 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -903,6 +903,9 @@ av_cold int ff_ffv1_encode_setup_plane_info(AVCodecContext *avctx,
}
av_assert0(s->bits_per_raw_sample >= 8);
+ if (s->remap_mode < 0)
+ s->remap_mode = s->flt ? 2 : 0;
+
return av_pix_fmt_get_chroma_sub_sample(pix_fmt, &s->chroma_h_shift, &s->chroma_v_shift);
}
@@ -958,7 +961,7 @@ static int encode_init_internal(AVCodecContext *avctx)
ff_build_rac_states(&s->slices[j].c, 0.05 * (1LL << 32), 256 - 8);
- s->slices[j].remap = s->flt;
+ s->slices[j].remap = s->remap_mode;
}
if ((ret = ff_ffv1_init_slices_state(s)) < 0)
@@ -1115,6 +1118,7 @@ static void choose_rct_params(const FFV1Context *f, FFV1SliceContext *sc,
static void encode_remap(FFV1Context *f, FFV1SliceContext *sc)
{
int transparency = f->transparency;
+ int flip = sc->remap == 2 ? 0x7FFF : 0;
for (int p= 0; p<3 + transparency; p++) {
int j = 0;
@@ -1123,7 +1127,7 @@ static void encode_remap(FFV1Context *f, FFV1SliceContext *sc)
int run = 0;
memset(state, 128, sizeof(state));
for (int i= 0; i<65536; i++) {
- int ri = i ^ ((i&0x8000) ? 0 : 0x7FFF);
+ int ri = i ^ ((i&0x8000) ? 0 : flip);
int u = sc->fltmap[p][ri];
sc->fltmap[p][ri] = j;
j+= u;
@@ -1249,7 +1253,7 @@ size_t ff_ffv1_encode_buffer_size(AVCodecContext *avctx)
maxsize += f->slice_count * 800; //for slice header
if (f->version > 3) {
maxsize *= f->bits_per_raw_sample + 1;
- if (f->flt) //remap table
+ if (f->remap_mode)
maxsize += f->slice_count * 70000 * (1 + 2*f->chroma_planes + f->transparency);
} else {
maxsize += f->slice_count * 2 * (avctx->width + avctx->height); //for bug with slices that code some pixels more than once
@@ -1432,6 +1436,16 @@ static const AVOption options[] = {
{ .i64 = QTABLE_8BIT }, INT_MIN, INT_MAX, VE, .unit = "qtable" },
{ "greater8bit", NULL, 0, AV_OPT_TYPE_CONST,
{ .i64 = QTABLE_GT8BIT }, INT_MIN, INT_MAX, VE, .unit = "qtable" },
+ { "remap_mode", "Remap Mode", OFFSET(remap_mode), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 2, VE, .unit = "remap_mode" },
+ { "auto", "Automatic", 0, AV_OPT_TYPE_CONST,
+ { .i64 = -1 }, INT_MIN, INT_MAX, VE, .unit = "remap_mode" },
+ { "off", "Disabled", 0, AV_OPT_TYPE_CONST,
+ { .i64 = 0 }, INT_MIN, INT_MAX, VE, .unit = "remap_mode" },
+ { "dualrle", "Dual RLE", 0, AV_OPT_TYPE_CONST,
+ { .i64 = 1 }, INT_MIN, INT_MAX, VE, .unit = "remap_mode" },
+ { "flipdualrle", "Dual RLE", 0, AV_OPT_TYPE_CONST,
+ { .i64 = 2 }, INT_MIN, INT_MAX, VE, .unit = "remap_mode" },
+
{ NULL }
};
More information about the ffmpeg-cvslog
mailing list