Commit graph

264 commits

Author SHA1 Message Date
Timo Rothenpieler
262d41c804 all: fix typos found by codespell 2025-08-03 13:48:47 +02:00
Andreas Rheinhardt
bdb4cd44e2 avcodec/ffv1enc: Use dummies to avoid UB pointer arithmetic
Fixes the following FATE-tests when run under Clang-UBSan:
ffmpeg-loopback-decoding, lavf-mxf_ffv1,
vsynth{1,2,3,_lena}-ffv1-v{0,2}, vsynth1-ffv{1,2,3,_lena},
vsynth{1,2,3,_lena}-ffv1-v3-yuv{420p,422p10,444p16}

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-07-03 18:17:56 +02:00
Andreas Rheinhardt
a6bcc773b5 avcodec/ffv1enc: Fix explicitly set -slicecrc 2
crcref needs to be set properly iff ec is two, regardless
of whether it has been explicitly set by the user or set
by default based on level/version.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-27 13:45:21 +02:00
Lynne
707c04fe06
ffv1enc_vulkan: support 8 and 16-bit 2-plane YUV formats
This adds support for all 8-bit and 16-bit 2-plane formats.
P010 and others require more work as the data's LSB-padded.
2025-05-01 09:34:44 +02:00
Michael Niedermayer
fb36f170de
avcodec/ffv1enc: Eliminate fabs()
Fixes: warning: using floating point absolute value function 'fabs' when argument is of integer type
No change in output
Changing variables to float worsens compression significantly

Found-by: ePirat
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-04-27 05:04:35 +02:00
Michael Niedermayer
935a52c887
avcodec/ffv1enc: Use version 3 by default (CRCs by default)
Version 3 is since 2013 (FFmpeg 2.1) non experimental so should be widely supported

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-04-16 13:09:04 +02:00
Jerome Martinez
0c28059b81
avcodec/ffv1enc: avoid repeating the same warning forever
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-04-16 13:09:04 +02:00
Jerome Martinez
3aec1f87c9
avcodec/ffv1enc: permit 1024 slices
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-04-10 03:01:32 +02:00
Michael Niedermayer
89df6d4068
avcodec/ffv1enc: Fix remap > 0 with gbrp12, that is non float
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-04-07 01:02:43 +02:00
Michael Niedermayer
175cd4ced0
avcodec/ffv1enc: avoid slices larger than 360x288 if no value is specified
This improves speed by providing more independent things for more CPUs

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-04-07 01:02:43 +02:00
Michael Niedermayer
1b04fb385c
avcodec/ffv1enc: Remove 65536 pixel per slice limit for remap
About 1% better compression with large slices

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-04-07 01:02:42 +02:00
Michael Niedermayer
feceed9222
avcodec/ffv1: Store slices*planes with the minimum bits needed after remap
This also means that if a plane*slice has only 1 color nothing
is stored after the remap table

This also corrects the RCT offset to the exact value after remap
not a fixed 65536

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-04-07 01:02:42 +02:00
Michael Niedermayer
37a319fb95
avcodec/ffv1enc: Consider 2s x s slice configurations
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-04-04 20:30:42 +02:00
Michael Niedermayer
06c00f9355
avcodec/ffv1: Only allocate fltmap* and bitmap when needed
This reduces memory requirements

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-04-04 20:30:42 +02:00
Michael Niedermayer
b67cf79683
avcodec/ffv1: Allocate unit only when needed and only as large as needed
That is instead of a fixed 65536, we now allocate only as many as there
are pixels.
We also allocate only for the encoder and only when remapping is enabled
and only for 32bit per sample

This should reduce memory consumption, the 2nd array will be
dealt with in a future commit

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-04-04 20:30:41 +02:00
Michael Niedermayer
f1235f4bc1
avcodec/ffv1enc: run1start variables should fit in 32bit
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-04-04 20:30:41 +02:00
Michael Niedermayer
4aeaee1f4e
avcodec/ffv1enc: replace the remaining log2() by magic
big secret, reading a float as the corresponding integer is a good
approximation of log2() for numbers not too close to 1.0. At the same
time it maintains strict monotonicity

this reduces run time from 19sec to 17sec for the slowest of my testcases
(with default remap_optimizer 3)

Compression is about the same:

-rw-r----- 1 michael michael  497603370 Mar 30 15:23 float-303503-fixed-40-optim-3-1log2F.nut
-rw-r----- 1 michael michael  497603374 Mar 28 11:27 float-303503-fixed-40-optim-3b.nut
-rw-r----- 1 michael michael  549938852 Mar 28 11:27 float-303503-float16-40-optim-3b.nut
-rw-r----- 1 michael michael  549938857 Mar 30 15:23 float-303503-float16-40-optim-3-1log2F.nut
-rw-r----- 1 michael michael 1150827841 Mar 28 11:28 float-303503-float-40-optim-3b.nut
-rw-r----- 1 michael michael 1150832913 Mar 30 15:22 float-303503-float-40-optim-3ref-log2F2.nut

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-04-03 01:58:07 +02:00
Michael Niedermayer
98c1788370
avcodec/ffv1enc: replace 3 double precision log2() by 1 single precision log2()
This makes the remap finding heuristic much faster

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-04-03 01:58:06 +02:00
Michael Niedermayer
1d2c391005
avcodec/ffv1enc: Add -remap_optimizer option
This allows tuning how much effort (time) the encoder spends on
optimizing the remap table

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-31 02:42:20 +02:00
Michael Niedermayer
f765085115
avcodec/ffv1enc: Eliminate RemapEncoderState
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-31 02:42:20 +02:00
Michael Niedermayer
3faee894fc
avcodec/ffv1enc: Eliminate copy_state
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-31 02:42:19 +02:00
Michael Niedermayer
2f0500f22c
avcodec/ffv1enc: Better heuristic for selecting mul values.
This increases the search space from the hardcoded 17 tables
to ~ 23^512 tables

The mul_count choice is chosen by bruteforce

All testcases tried, improve

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-31 02:42:19 +02:00
Michael Niedermayer
226fcc7258
avcodec/ffv1enc: Store run1start_mul_index instead of computing
There is a special case I missed, its simpler to just store

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-27 22:02:51 +01:00
Michael Niedermayer
f334eadd36
avcodec/ffv1enc: Fix off by 1 in assert
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-27 22:02:46 +01:00
Michael Niedermayer
d4a23e6640
avcodec/ffv1enc: Fix end handling
This also produces smaller files

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-27 22:02:42 +01:00
Michael Niedermayer
ffd537bcc2
avcodec/ffv1enc: Eliminate encode_mul()
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-27 21:50:14 +01:00
Michael Niedermayer
8af28d2eb1
avcodec/ffv1enc: Eliminate index_stack and delta_stack
This reduces stack space requirements my 1.5 mb and should fix fate

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-25 11:38:20 +01:00
Michael Niedermayer
051fd03f6c
avcodec/ffv1enc: Heuristic to select fixed in float multipliers
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-25 11:32:14 +01:00
Michael Niedermayer
a33908d051
avcodec/ffv1enc: Factorize s.last_val update out
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-25 11:32:14 +01:00
Michael Niedermayer
836add03a8
avcodec/ffv1enc: Simplify last_val update
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-25 11:32:11 +01:00
Michael Niedermayer
4b24c5ba69
avcodec/ffv1enc: introduce step to simplify code
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-25 11:31:08 +01:00
Michael Niedermayer
e9cfed35a5
avcodec/ffv1enc: eliminate if()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-25 11:24:13 +01:00
Michael Niedermayer
3813559660
avcodec/ffv1enc: remap table size is 1<<bits_per_raw_sample not fixed 65536
not a bugfix as this path was only used for float16 but it makes sense
to allow using this for integers too

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-25 11:24:12 +01:00
Michael Niedermayer
e619b0d817
avcodec/ffv1enc: remap mode 2 is for floats only
(you could use it for others but it makes no sense)

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-25 11:24:12 +01:00
James Almer
044664ac3b avcodec/ffv1enc: remove mixed declarations and code
Signed-off-by: James Almer <jamrial@gmail.com>
2025-03-24 16:34:24 -03:00
James Almer
a4cf0979a4 avcodec/ffv1enc: update missing Unit accesses inside av_assert2
Fixes compilation with assert-level=2.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-03-24 16:32:47 -03:00
James Almer
702239bc50 avcodec/ffv1enc: reduce stack usage
Fixes failures in some systems since 171060d5dc.
This can be further improved by only allocating the arrays when needed.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-03-24 13:55:56 -03:00
Michael Niedermayer
5dcf566f69
avcodec/ffv1: Implement 2D RLE for remap
ATM this performs as well or better as any other algorithm tried.
Its simple for the decoder.
On the encoder side complexity depends on how parameters are
chosen. But with a fixed mul_count of 1 and basic heuristic
it performs as well as any more complex choice i tried so far.

The encoder code here is flexible and allows mul_count > 1
and also can easily be used to exactly test various parameters.

With mul_count=512 we can gain another 6% in remap table size
for fixed point in float data. (this is not implemented in this
patch though)

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-24 13:46:59 +01:00
Michael Niedermayer
e19496fe71
avcodec/ffv1enc: remap allows using rice golomb with more bits
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-24 13:46:58 +01:00
Michael Niedermayer
171060d5dc
avcodec/ffv1: 32-bit float sample support
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-24 13:46:58 +01:00
Michael Niedermayer
62c7d08947
avcodec/ffv1: Fix remap ordering
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-24 13:46:57 +01:00
Michael Niedermayer
276854e183
avcodec/ffv1: Add GRAYF16 support
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-17 15:26:12 +01:00
Michael Niedermayer
b57f71f716
avcodec/ffv1: Add YAF16 support
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-17 15:26:12 +01:00
Michael Niedermayer
d7fa6a388b
avcodec/ffv1: fix remap without chroma planes
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-17 15:26:11 +01:00
Michael Niedermayer
a8892c5400
avcodec/ffv1: implement remap for encode/decode_plane()
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-17 15:26:11 +01:00
Andreas Rheinhardt
5ad86d5fbc avcodec: Mark init and close functions as av_cold
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-17 04:33:11 +01:00
Michael Niedermayer
437cbd25e0
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@mediaarea.net>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-14 02:04:25 +01:00
Michael Niedermayer
dcf6142794
avcodec/ffv1enc: add space for the remap table to max_size
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-14 02:03:59 +01:00
Michael Niedermayer
a90ff81287
avcodec/ffv1enc: Factor set_micro_version() out of ff_ffv1_write_extradata()
and call it from ff_ffv1_encode_init()

setting micro version from code writing the extradata is messy, this should
be cleaner

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-14 02:03:59 +01:00
Michael Niedermayer
a8a83e06f9
avcodec/ffv1: Fix remap and float with golomb rice
Sponsored-by: Sovereign Tech Fund
Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-03-11 14:17:02 +01:00