Commit Graph

109506 Commits

Author SHA1 Message Date
Clément Bœsch
1340fe7caf avfilter/paletteuse: move r,g,b computation in a more local scope 2023-01-03 17:18:55 +01:00
Clément Bœsch
1ae1b707e2 avfilter/paletteuse: remove mean error tool
This belongs in another filter.
2023-01-03 17:18:55 +01:00
Clément Bœsch
8789a9e05b avfilter/paletteuse: remove alternative search methods
This is a maintenance pain more than anything. It appears to make the
code slightly faster as a side effect.
2023-01-03 17:18:55 +01:00
Clément Bœsch
0f7942afa6 avfilter/paletteuse: switch to recursive method
It appears faster than the iterative method on my machine (1.06x
faster), so I'm guessing compilers improved over time (the iterative
version was slightly faster in the past).
2023-01-03 17:18:55 +01:00
Clément Bœsch
6c7b54e962 avfilter/paletteuse: use lowbias32 for color hashing
Impact is more negligible than previous commit but still faster (1.02x).
2023-01-03 17:18:55 +01:00
Clément Bœsch
c9084cd0e2 avfilter/palettegen: use lowbias32 for color hashing
1.12x faster overall in palettegen on my machine.
2023-01-03 17:18:55 +01:00
Clément Bœsch
3cafbdc083 avfilter/palette: add lowbias32 hashing 2023-01-03 17:18:55 +01:00
Clément Bœsch
051926868c avfilter/palette{gen,use}: update Copyright after recent changes 2023-01-03 17:18:55 +01:00
Clément Bœsch
3a4a6c7815 avfilter/palettegen: use libc qsort
Now that the sort function is deterministic, we can rely on the libc
sorting function.
2023-01-03 17:18:55 +01:00
Clément Bœsch
8057e1a618 avfilter/palettegen: make refs order deterministic
Currently, in case of equality on the first color channel, the order of
the ref colors is defined by the hashing function. This commit makes the
sorting deterministic and improve the hierarchical ordering.
2023-01-03 17:18:55 +01:00
Clément Bœsch
2441e53c0a avfilter/palettegen: add a warning about supporting only sRGB 2023-01-03 17:18:55 +01:00
Clément Bœsch
9026d92c13 avfilter/palettegen: base box split decision on a perceptual model
Similar to the change in paletteuse, we rely on a perceptual model to
decide how and where to split the box.
2023-01-03 17:18:55 +01:00
Clément Bœsch
724f52b906 avfilter/palettegen: switch to signed arithmetic
This prevents mixed sign arithmetic (typically because we have signed
color channel differences), which has nasty side effects in C.
2023-01-03 17:18:55 +01:00
Clément Bœsch
67ce6ad9a2 avfilter/palettegen: rename local variable box_weight to weight
This variable is used only for the running weight (used to reach the
target median). The places where we actually need the box weight are
changed to use box->weight.
2023-01-03 17:18:55 +01:00
Clément Bœsch
61d334d8c3 avfilter/palettegen: misc cosmetics 2023-01-03 17:18:55 +01:00
Clément Bœsch
efb0a6f6ce avfilter/palettegen: compute average color within compute_box_stats() 2023-01-03 17:18:55 +01:00
Clément Bœsch
dafd43b78d avfilter/palettegen: change cut score from ∑e² to max e²
This is following the results from personal research¹.

¹: https://github.com/ubitux/research/tree/main/color-quantization#results
2023-01-03 17:18:55 +01:00
Clément Bœsch
187f5e7f90 avfilter/palettegen: rename variance to cut_score
"Variance" wasn't exactly the correct word; "cut score" is more
agnostic, which will be useful when changing the algorithm in the next
commit.
2023-01-03 17:18:55 +01:00
Clément Bœsch
e49fc1a6ef avfilter/palettegen: always compute the box variance
The variance computation is simple enough now (since we can use the axis
squared errors) that it doesn't need to have a complex lazy computation
logic.
2023-01-03 17:18:55 +01:00
Clément Bœsch
9e5f494d26 avfilter/palettegen: use box->major_axis without intermediate variable 2023-01-03 17:18:55 +01:00
Clément Bœsch
86bced7c65 avfilter/palettegen: define the best axis to cut using the squared error
This is following the results from personal research¹.

¹: https://github.com/ubitux/research/tree/main/color-quantization#results
2023-01-03 17:18:55 +01:00
Clément Bœsch
21f7814238 avfilter/palettegen: move box stats computation to a dedicated function 2023-01-03 17:18:55 +01:00
Clément Bœsch
a0587c0219 avfilter/paletteuse: switch to a perceptual model
Now the selection of the color is based on a distance built around human
perception of color instead of the unreliable sRGB triplet one.
2023-01-03 17:18:55 +01:00
Clément Bœsch
1159c36d6d avfilter/paletteuse: remove redundant alpha condition
This is redundant with a != 0xff below.
2023-01-03 17:18:55 +01:00
Clément Bœsch
4c061bc837 avfilter/paletteuse: remove unused alpha split dimension
The equalities in the w{r,g,b} range checks make sure longest is never
0. Even if the alpha ended up being selected in get_next_color() it
would cause underread memory accesses in its caller (colormap_insert).
2023-01-03 17:18:55 +01:00
Clément Bœsch
71ed92e9c4 avfilter/paletteuse: name target color arg consistently in colormap functions 2023-01-03 17:18:55 +01:00
Clément Bœsch
755c427f7a avfilter/paletteuse: switch from u8[4] to u32 for color code
This change simplifies the code quite a bit and make it consistent with
how it's done in palettegen.
2023-01-03 17:18:55 +01:00
Clément Bœsch
31c5f26a46 avfilter/palette{gen,use}: add palette utils
These color management helpers will be shared by palettegen and
paletteuse in the following commits.

Note that it probably makes sense to share at least the sRGB/linear
functions with other filters at some point.

More information on OkLab can be found here: https://bottosson.github.io/posts/oklab/

For the arithmetic integer version, see:
http://blog.pkh.me/p/38-porting-oklab-colorspace-to-integer-arithmetic.html
and https://github.com/ubitux/oklab-int
2023-01-03 17:18:55 +01:00
Clément Bœsch
7bc054e63c avfilter/palette{gen,use}: simplify a few alpha masks 2023-01-03 17:18:55 +01:00
Clément Bœsch
320fbf5f24 avfilter/palette{gen,use}: revert support palettes with alpha
This reverts commit dea673d0d5.

This change cannot work for several reasons, the most obvious ones are:

- the alpha is being part of the scoring of the color difference, even
  though we can not interpret the alpha as part of the perception of the
  color (we don't even know if it's premultiplied or postmultiplied)
- the colors are averaged with their alpha value which simply cannot
  work

The command proposed in the original thread of the patch actually
produces a completely broken file:

    ffmpeg -y -loglevel verbose -i fate-suite/apng/o_sample.png -filter_complex "split[split1][split2];[split1]palettegen=max_colors=254:use_alpha=1[pal1];[split2][pal1]paletteuse=use_alpha=1" -frames:v 1 out.png

We can see that many color pixels are off, but more importantly some
colors have a random alpha value: https://imgur.com/eFQ2UK7

I don't see any easy fix for this unfortunately, the approach appears to
be flawed by design.
2023-01-03 17:18:55 +01:00
Clément Bœsch
cad9d7fc85 avfilter/palettegen: allow a minimum of 2 colors 2023-01-03 17:18:55 +01:00
Paul B Mahol
c94988a781 avfilter/af_afade: add options to control unity/silence gains 2023-01-03 10:25:06 +01:00
Zhao Zhili
f0d2ed135c avcodec/mediacodecdec: add AV1 decoding support
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-01-03 19:23:03 +08:00
Paul B Mahol
cc2b1a3251 avformat/bonk: add support for ID3 metadata 2023-01-02 19:54:56 +01:00
Paul B Mahol
5852682dbd avcodec/bonk: increase level limit as joint encodings needs more 2023-01-02 18:42:35 +01:00
Paul B Mahol
3879555cd5 avfilter/afir_template: make IR transitions artifacts free 2023-01-02 15:33:57 +01:00
Lynne
62da0b4a74
configure: update copyright year 2023-01-01 00:24:04 +01:00
Gyan Doshi
d39b34123d avformat/segment: add option min_seg_duration
New option can be used to avoid creating very short segments with inputs
whose GOP size is variable or unharmonic with segment_time.

Only effective with segment_time.
2022-12-29 15:43:40 +05:30
Michael Niedermayer
aee0f320ac
avcodec/dts2pts_bsf: Avoid poc overflows in cmp_find()
Fixes: signed integer overflow: -2147483648 - 5 cannot be represented in type 'int'
Fixes: 54242/clusterfuzz-testcase-minimized-ffmpeg_BSF_DTS2PTS_fuzzer-472928339243827

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-12-28 00:25:35 +01:00
Michael Niedermayer
64a04fc165
avformat/mxfdec: Use 64bit in remainder
Fixes: signed integer overflow: 48000 * 223587 cannot be represented in type 'int'
Fixes: 54513/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5817594836025344

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Tomas Härdin <git@haerdin.se>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-12-28 00:25:34 +01:00
Michael Niedermayer
902a49c4cd
avcodec/hdrdec: Check for end of input in decompress()
Fixes: Timeout
Fixes: 54386/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HDR_fuzzer-5053598268784640

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-12-28 00:25:34 +01:00
James Almer
7fab58647c avcodec/proresdec2: set color information on frames instead of the decoder context
Similar to how the encoder looks at frame color information to write the frame
header bitstream.

Should workaround ticket #10091, where container level color parameters passed
to the decoder context were being overwritten.

Signed-off-by: James Almer <jamrial@gmail.com>
2022-12-27 11:03:22 -03:00
James Almer
18f24527eb avformat/oggenc: ignore empty packets
Some encoders, like flac, can send side data only packets at the end.
Eventually, said extradata update should ideally be used to update the header
when writting to seekable output, but for now, ignore them.

Should fix the undefined behavior of passing NULL to memcpy().

Signed-off-by: James Almer <jamrial@gmail.com>
2022-12-27 11:03:18 -03:00
Leo Izen
cd9dd03006 avcodec/pnm: avoid mirroring PFM images vertically
PFM (aka Portable FloatMap) encodes its scanlines from bottom-to-top,
not from top-to-bottom, unlike other NetPBM formats. Without this
patch, FFmpeg ignores this exception and decodes/encodes PFM images
mirrored vertically from their proper orientation.

For reference, see the NetPBM tool pfmtopam, which encodes a .pam
from a .pfm, using the correct orientation (and which FFmpeg reads
correctly). Also compare ffplay to magick display, which shows the
correct orientation as well.

See: http://www.pauldebevec.com/Research/HDR/PFM/ and see:
https://netpbm.sourceforge.net/doc/pfm.html for descriptions of this
image format.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
2022-12-27 10:41:25 -03:00
James Almer
64007595dc avcodec/mjpegbdec: return the amount of bytes consumed when discarding frames
EAGAIN is not correct in this scenario. FFCodec.cb.decode() callback decoders
always return the amount of bytes consumed from the input packet (if any), and
report if a frame was generated by setting got_frame.

Signed-off-by: James Almer <jamrial@gmail.com>
2022-12-27 10:40:00 -03:00
Martijn van Beurden
5b342d0005 fate/flac: Add test of 32 bps encoding/decoding 2022-12-26 21:15:36 +01:00
Martijn van Beurden
d8f1404c50 libavcodec/flacenc: Implement encoding of 32 bit-per-sample PCM
Add encoding of 32 bit-per-sample PCM to FLAC files to libavcodec.
Coding to this format is at this point considered experimental and
-strict experimental is needed to get ffmpeg to encode such files.
2022-12-26 21:15:36 +01:00
Martijn van Beurden
909cfdc205 libavcodec/flacdec: Implement decoding of 32 bit-per-sample PCM
Add decoding of FLAC files coding for 32 bit-per-sample PCM to libavcodec.
2022-12-26 21:15:36 +01:00
Paul B Mahol
eeb280f351 avfilter/af_afir: fix prev_selir variable change in private filter context 2022-12-25 20:39:54 +01:00
Paul B Mahol
eaba6bfc51 avfilter/afir_template: reduce memset overhead a little 2022-12-25 20:39:54 +01:00