[FFmpeg-devel] [PATCH 3/4] avcodec/ffv1: Basic float16 support
Michael Niedermayer
michael at niedermayer.cc
Sat Jan 18 06:59:59 EET 2025
This can be used as a reference for bitstream and compression improvements
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
---
libavcodec/ffv1.h | 2 ++
libavcodec/ffv1dec.c | 12 ++++++++++--
libavcodec/ffv1enc.c | 9 ++++++++-
3 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index 576769ae1e0..2c2df154037 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -132,6 +132,8 @@ typedef struct FFV1Context {
uint8_t state_transition[256];
uint8_t (*initial_states[MAX_QUANT_TABLES])[32];
int colorspace;
+ int flt;
+
int use32bit;
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 5aec6cdce26..def95ff411f 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -508,6 +508,8 @@ static int read_extra_header(FFV1Context *f)
f->crcref = 0x7a8c4079;
if (f->combined_version >= 0x30003)
f->intra = get_symbol(&c, state, 0);
+ if (f->combined_version >= 0x40004)
+ f->flt = get_symbol(&c, state, 0);
}
if (f->version > 2) {
@@ -738,11 +740,17 @@ static int read_header(FFV1Context *f)
else if (f->avctx->bits_per_raw_sample == 14 && f->transparency)
f->avctx->pix_fmt = AV_PIX_FMT_GBRAP14;
else if (f->avctx->bits_per_raw_sample == 16 && !f->transparency) {
- f->avctx->pix_fmt = AV_PIX_FMT_GBRP16;
+ if (f->flt) {
+ f->avctx->pix_fmt = AV_PIX_FMT_GBRPF16;
+ } else
+ f->avctx->pix_fmt = AV_PIX_FMT_GBRP16;
f->use32bit = 1;
}
else if (f->avctx->bits_per_raw_sample == 16 && f->transparency) {
- f->avctx->pix_fmt = AV_PIX_FMT_GBRAP16;
+ if (f->flt) {
+ f->avctx->pix_fmt = AV_PIX_FMT_GBRAPF16;
+ } else
+ f->avctx->pix_fmt = AV_PIX_FMT_GBRAP16;
f->use32bit = 1;
}
} else {
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index c952065e443..8e9f41fea8f 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -419,7 +419,7 @@ av_cold int ff_ffv1_write_extradata(AVCodecContext *avctx)
if (f->version == 3) {
f->micro_version = 4;
} else if (f->version == 4)
- f->micro_version = 3;
+ f->micro_version = 4;
f->combined_version += f->micro_version;
put_symbol(&c, state, f->micro_version, 0);
}
@@ -867,6 +867,8 @@ av_cold int ff_ffv1_encode_setup_plane_info(AVCodecContext *avctx,
s->bits_per_raw_sample = 14;
case AV_PIX_FMT_GBRP16:
case AV_PIX_FMT_GBRAP16:
+ case AV_PIX_FMT_GBRPF16:
+ case AV_PIX_FMT_GBRAPF16:
if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample)
s->bits_per_raw_sample = 16;
else if (!s->bits_per_raw_sample)
@@ -877,7 +879,11 @@ av_cold int ff_ffv1_encode_setup_plane_info(AVCodecContext *avctx,
if (s->bits_per_raw_sample >= 16) {
s->use32bit = 1;
}
+ s->flt = !!(desc->flags & AV_PIX_FMT_FLAG_FLOAT);
s->version = FFMAX(s->version, 1);
+
+ if (s->flt)
+ s->version = FFMAX(s->version, 4);
break;
default:
av_log(avctx, AV_LOG_ERROR, "format %s not supported\n",
@@ -1398,6 +1404,7 @@ const FFCodec ff_ffv1_encoder = {
AV_PIX_FMT_GRAY9,
AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14,
AV_PIX_FMT_YUV440P10, AV_PIX_FMT_YUV440P12,
+ AV_PIX_FMT_GBRPF16,
AV_PIX_FMT_NONE
},
--
2.48.1
More information about the ffmpeg-devel
mailing list