ffmpeg.git
2 years agovvcdec: add vvc decoder
Nuo Mi [Thu, 28 Dec 2023 06:17:29 +0000 (14:17 +0800)]
vvcdec: add vvc decoder

vvc decoder plug-in to avcodec.
split frames into slices/tiles and send them to vvc_thread for further decoding
reorder and wait for the frame decoding to be done and output the frame

Features:
    + Support I, P, B frames
    + Support 8/10/12 bits, chroma 400, 420, 422, and 444 and range extension
    + Support VVC new tools like MIP, CCLM, AFFINE, GPM, DMVR, PROF, BDOF, LMCS, ALF
    + 295 conformace clips passed
    - Not support RPR, IBC, PALETTE, and other minor features yet

Performance:
    C code FPS on an i7-12700K (x86):
        BQTerrace_1920x1080_60_10_420_22_RA.vvc      93.0
        Chimera_8bit_1080P_1000_frames.vvc          184.3
        NovosobornayaSquare_1920x1080.bin           191.3
        RitualDance_1920x1080_60_10_420_32_LD.266   150.7
        RitualDance_1920x1080_60_10_420_37_RA.266   170.0
        Tango2_3840x2160_60_10_420_27_LD.266         33.7

    C code FPS on a M1 Mac Pro (ARM):
        BQTerrace_1920x1080_60_10_420_22_RA.vvc     58.7
        Chimera_8bit_1080P_1000_frames.vvc          153.3
        NovosobornayaSquare_1920x1080.bin           150.3
        RitualDance_1920x1080_60_10_420_32_LD.266   105.0
        RitualDance_1920x1080_60_10_420_37_RA.266   133.0
        Tango2_3840x2160_60_10_420_27_LD.266        21.7

    Asm optimizations still working in progress. please check
    https://github.com/ffvvc/FFmpeg/wiki#performance-data for the latest

Contributors (based on code merge order):
    Nuo Mi <nuomi2021@gmail.com>
    Xu Mu <toxumu@outlook.com>
    Frank Plowman <post@frankplowman.com>
    Shaun Loo <shaunloo10@gmail.com>
    Wu Jianhua <toqsxw@outlook.com>

Thank you for reporting issues and providing performance reports:
    Łukasz Czech <lukaszcz18@wp.pl>
    Xu Fulong <839789740@qq.com>

Thank you for providing review comments:
    Ronald S. Bultje <rsbultje@gmail.com>
    James Almer <jamrial@gmail.com>
    Andreas Rheinhardt <andreas.rheinhardt@outlook.com>

Co-authored-by: Xu Mu <toxumu@outlook.com>
Co-authored-by: Frank Plowman <post@frankplowman.com>
Co-authored-by: Shaun Loo <shaunloo10@gmail.com>
Co-authored-by: Wu Jianhua <toqsxw@outlook.com>
2 years agovvcdec: add CTU thread logical
Nuo Mi [Tue, 5 Dec 2023 14:45:18 +0000 (22:45 +0800)]
vvcdec: add CTU thread logical

This is the main entry point for the CTU (Coding Tree Unit) decoder.
The code will divide the CTU decoder into several stages.
It will check the stage dependencies and run the stage decoder.

Co-authored-by: Xu Mu <toxumu@outlook.com>
Co-authored-by: Frank Plowman <post@frankplowman.com>
Co-authored-by: Shaun Loo <shaunloo10@gmail.com>
Co-authored-by: Wu Jianhua <toqsxw@outlook.com>
2 years agovvcdec: add CTU parser
Nuo Mi [Tue, 5 Dec 2023 14:45:17 +0000 (22:45 +0800)]
vvcdec: add CTU parser

Co-authored-by: Xu Mu <toxumu@outlook.com>
Co-authored-by: Frank Plowman <post@frankplowman.com>
Co-authored-by: Shaun Loo <shaunloo10@gmail.com>
Co-authored-by: Wu Jianhua <toqsxw@outlook.com>
2 years agovvcdec: add dsp init and inv transform
Nuo Mi [Tue, 5 Dec 2023 14:45:16 +0000 (22:45 +0800)]
vvcdec: add dsp init and inv transform

Co-authored-by: Xu Mu <toxumu@outlook.com>
Co-authored-by: Frank Plowman <post@frankplowman.com>
Co-authored-by: Shaun Loo <shaunloo10@gmail.com>
Co-authored-by: Wu Jianhua <toqsxw@outlook.com>
2 years agovvcdec: add LMCS, Deblocking, SAO, and ALF filters
Nuo Mi [Tue, 5 Dec 2023 14:45:15 +0000 (22:45 +0800)]
vvcdec: add LMCS, Deblocking, SAO, and ALF filters

Co-authored-by: Xu Mu <toxumu@outlook.com>
Co-authored-by: Frank Plowman <post@frankplowman.com>
Co-authored-by: Shaun Loo <shaunloo10@gmail.com>
Co-authored-by: Wu Jianhua <toqsxw@outlook.com>
2 years agovvcdec: add intra prediction
Nuo Mi [Tue, 5 Dec 2023 14:45:14 +0000 (22:45 +0800)]
vvcdec: add intra prediction

Co-authored-by: Xu Mu <toxumu@outlook.com>
Co-authored-by: Frank Plowman <post@frankplowman.com>
Co-authored-by: Shaun Loo <shaunloo10@gmail.com>
Co-authored-by: Wu Jianhua <toqsxw@outlook.com>
2 years agovvcdec: add inv transform 1d
Nuo Mi [Tue, 5 Dec 2023 14:45:13 +0000 (22:45 +0800)]
vvcdec: add inv transform 1d

Co-authored-by: Xu Mu <toxumu@outlook.com>
Co-authored-by: Frank Plowman <post@frankplowman.com>
Co-authored-by: Shaun Loo <shaunloo10@gmail.com>
Co-authored-by: Wu Jianhua <toqsxw@outlook.com>
2 years agovvcdec: add inter prediction
Nuo Mi [Tue, 5 Dec 2023 14:45:12 +0000 (22:45 +0800)]
vvcdec: add inter prediction

Co-authored-by: Xu Mu <toxumu@outlook.com>
Co-authored-by: Frank Plowman <post@frankplowman.com>
Co-authored-by: Shaun Loo <shaunloo10@gmail.com>
Co-authored-by: Wu Jianhua <toqsxw@outlook.com>
2 years agovvcdec: add motion vector decoder
Nuo Mi [Tue, 5 Dec 2023 14:45:11 +0000 (22:45 +0800)]
vvcdec: add motion vector decoder

Co-authored-by: Xu Mu <toxumu@outlook.com>
Co-authored-by: Frank Plowman <post@frankplowman.com>
Co-authored-by: Shaun Loo <shaunloo10@gmail.com>
Co-authored-by: Wu Jianhua <toqsxw@outlook.com>
2 years agovvcdec: add reference management
Nuo Mi [Tue, 5 Dec 2023 14:45:10 +0000 (22:45 +0800)]
vvcdec: add reference management

Co-authored-by: Xu Mu <toxumu@outlook.com>
Co-authored-by: Frank Plowman <post@frankplowman.com>
Co-authored-by: Shaun Loo <shaunloo10@gmail.com>
Co-authored-by: Wu Jianhua <toqsxw@outlook.com>
2 years agovvcdec: add cabac decoder
Nuo Mi [Tue, 5 Dec 2023 14:45:09 +0000 (22:45 +0800)]
vvcdec: add cabac decoder

add Context-based Adaptive Binary Arithmetic Coding (CABAC) decoder

Co-authored-by: Xu Mu <toxumu@outlook.com>
Co-authored-by: Frank Plowman <post@frankplowman.com>
Co-authored-by: Shaun Loo <shaunloo10@gmail.com>
Co-authored-by: Wu Jianhua <toqsxw@outlook.com>
2 years agovvcdec: add parameter parser for sps, pps, ph, sh
Nuo Mi [Thu, 28 Dec 2023 06:14:49 +0000 (14:14 +0800)]
vvcdec: add parameter parser for sps, pps, ph, sh

Co-authored-by: Xu Mu <toxumu@outlook.com>
Co-authored-by: Frank Plowman <post@frankplowman.com>
Co-authored-by: Shaun Loo <shaunloo10@gmail.com>
Co-authored-by: Wu Jianhua <toqsxw@outlook.com>
2 years agovvcdec: add vvc_data
Nuo Mi [Thu, 28 Dec 2023 06:15:38 +0000 (14:15 +0800)]
vvcdec: add vvc_data

Co-authored-by: Xu Mu <toxumu@outlook.com>
Co-authored-by: Frank Plowman <post@frankplowman.com>
Co-authored-by: Shaun Loo <shaunloo10@gmail.com>
Co-authored-by: Wu Jianhua <toqsxw@outlook.com>
2 years agodoc/filters/drawtext: apply second level of escaping on colon
Stefano Sabatini [Tue, 2 Jan 2024 21:01:14 +0000 (22:01 +0100)]
doc/filters/drawtext: apply second level of escaping on colon

Fix escaping on example.

2 years agodoc/filters/setpts: add random jitter generation example
Stefano Sabatini [Fri, 29 Dec 2023 11:48:08 +0000 (12:48 +0100)]
doc/filters/setpts: add random jitter generation example

2 years agolavu/eval: add randomi function to compute random value in interval
Stefano Sabatini [Thu, 28 Dec 2023 18:09:22 +0000 (19:09 +0100)]
lavu/eval: add randomi function to compute random value in interval

2 years agolavfi/setpts: use macro to access variables array
Stefano Sabatini [Wed, 27 Dec 2023 19:12:51 +0000 (20:12 +0100)]
lavfi/setpts: use macro to access variables array

2 years agolavfi: add quirc filter
Stefano Sabatini [Tue, 26 Dec 2023 15:19:10 +0000 (16:19 +0100)]
lavfi: add quirc filter

2 years agolavfi: add qrencode source and filter
Stefano Sabatini [Tue, 28 Nov 2023 22:58:15 +0000 (23:58 +0100)]
lavfi: add qrencode source and filter

2 years agolavfi: introduce textutils
Stefano Sabatini [Mon, 20 Nov 2023 00:13:17 +0000 (01:13 +0100)]
lavfi: introduce textutils

Generalize drawtext utilities to make them usable in other filters.
This will be needed to introduce the QR code source and filter without
duplicating functionality.

2 years agolavfi/overlay: factorize definition of planar and packed blending functions
Stefano Sabatini [Sat, 16 Dec 2023 14:24:02 +0000 (15:24 +0100)]
lavfi/overlay: factorize definition of planar and packed blending functions

2 years agoavcodec/d3d12va_mpeg2: change the type for the ID3D12Resource_Map input data argument
James Almer [Sun, 31 Dec 2023 20:21:49 +0000 (17:21 -0300)]
avcodec/d3d12va_mpeg2: change the type for the ID3D12Resource_Map input data argument

Fixes -Wincompatible-pointer-types warnings.

Reviewed-by: Wu Jianhua <toqsxw@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2 years agoavcodec/d3d12va_mpeg2: remove unused variables
James Almer [Sun, 31 Dec 2023 20:14:01 +0000 (17:14 -0300)]
avcodec/d3d12va_mpeg2: remove unused variables

Reviewed-by: Wu Jianhua <toqsxw@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2 years agoconfigure: correct lensfun header function check
Gyan Doshi [Sun, 31 Dec 2023 07:14:20 +0000 (12:44 +0530)]
configure: correct lensfun header function check

The function lf_db_new was deprecated in lensfun 09dcd3e7ad in 2017
in favour of lf_db_create. The AVfilter was adjusted in 8b78eb312d
but the configure check wasn't changed.

lensfun removed lf_db_new declaration in lf 35c0017593 so configure
fails to find lensfun.

2 years agoconfigure: update copyright year
Lynne [Mon, 1 Jan 2024 00:00:00 +0000 (00:00 +0000)]
configure: update copyright year

2 years agoavfilter/vf_format: allow empty pix_fmts list
Niklas Haas [Wed, 25 Oct 2023 11:43:28 +0000 (13:43 +0200)]
avfilter/vf_format: allow empty pix_fmts list

Which will impose no restriction. This makes sense when using e.g.
`color_ranges=pc` to limit the color range, without also limiting the
pixel format.

2 years agoavfilter/vf_format: add color_ranges/spaces
Niklas Haas [Wed, 25 Oct 2023 11:42:24 +0000 (13:42 +0200)]
avfilter/vf_format: add color_ranges/spaces

Needed for fftools/ffmpeg_filter to be able to force specific output
formats via the filter chain.

2 years agoavfilter/vf_format: re-use AVFilterFormats for pix_fmt parsing
Niklas Haas [Sat, 21 Oct 2023 14:51:51 +0000 (16:51 +0200)]
avfilter/vf_format: re-use AVFilterFormats for pix_fmt parsing

Rewrite the format parsing code to make it more easily generalizable. In
particular, `invert_formats` does not depend on the type of format list
passed to it, which allows me to re-use this helper in an upcoming
commit.

Slightly shortens the code, at the sole cost of doing several malloc
(ff_add_format) instead of a single malloc.

2 years agoavfilter/buffersink: add color space/range accessors
Niklas Haas [Sun, 31 Dec 2023 21:36:12 +0000 (13:36 -0800)]
avfilter/buffersink: add color space/range accessors

Needed for fftools.

2 years agoavfilter/vf_libplacebo: switch to colorspace negotiation API
Niklas Haas [Mon, 30 Oct 2023 13:05:53 +0000 (14:05 +0100)]
avfilter/vf_libplacebo: switch to colorspace negotiation API

2 years agoavfilter/vf_libplacebo: don't force dovi frames to bt.2020-ncl
Niklas Haas [Mon, 30 Oct 2023 13:07:43 +0000 (14:07 +0100)]
avfilter/vf_libplacebo: don't force dovi frames to bt.2020-ncl

This is at odds with the YUV matrix negotiation API, in which such
dynamic changes in YUV encoding are no longer easily possible. There is
also no really strong motivating reason to do this, since the choice of
YUV matrix is essentially arbitrary and not actually related to the
Dolby Vision decoding process.

2 years agoavfilter/vf_zscale: switch to colorspace negotiation API
Niklas Haas [Mon, 30 Oct 2023 12:51:18 +0000 (13:51 +0100)]
avfilter/vf_zscale: switch to colorspace negotiation API

Following the same design as vf_scale.

2 years agoavfilter/vf_zscale: remove unused variables
Niklas Haas [Mon, 30 Oct 2023 12:53:57 +0000 (13:53 +0100)]
avfilter/vf_zscale: remove unused variables

Only assigned, never read.

2 years agovf_scale: use colorspace negotiation API
Niklas Haas [Tue, 31 Oct 2023 12:52:53 +0000 (13:52 +0100)]
vf_scale: use colorspace negotiation API

This filter will always accept any input format, even if the user sets
a specific in_range/in_color_matrix. This is to preserve status quo with
current behavior, where passing a specific in_color_matrix merely
overrides the incoming frames' attributes. (Use `vf_format` to force
a specific input range)

Because changing colorspace and color_range now requires reconfiguring
the link, we can lift sws_setColorspaceDetails out of scale_frame and
into config_props. (This will also get re-called if the input frame
properties change)

2 years agofftools/ffmpeg_filter: configure buffersrc with csp/range
Niklas Haas [Fri, 20 Oct 2023 15:14:20 +0000 (17:14 +0200)]
fftools/ffmpeg_filter: configure buffersrc with csp/range

Propagates input metadata to the input filter graph.

2 years agoavfilter/buffersrc: add color_space/range parameters
Niklas Haas [Fri, 20 Oct 2023 14:55:43 +0000 (16:55 +0200)]
avfilter/buffersrc: add color_space/range parameters

To allow adding proper negotiation, in particular, to fftools.

These values will simply be negotiated downstream for YUV formats, and
ignored otherwise.

2 years agofftools/ffmpeg_filter: don't clear buffersrc params
Niklas Haas [Sat, 28 Oct 2023 12:45:18 +0000 (14:45 +0200)]
fftools/ffmpeg_filter: don't clear buffersrc params

This memset is bogus, it accomplishes nothing in the best case and
regresses future additions to AVBufferSrcParameters in the worst case.

2 years agoavfilter: add negotiation API for color space/range
Niklas Haas [Sun, 31 Dec 2023 21:35:03 +0000 (13:35 -0800)]
avfilter: add negotiation API for color space/range

Motivated by YUVJ removal. This change will allow full negotiation
between color ranges and matrices as needed. By default, all ranges and
matrices are marked as supported.

Because grayscale formats are currently handled very inconsistently (and
in particular, assumed as forced full-range by swscale), we exclude them
from negotiation altogether for the time being, to get this API merged.

After filter negotiation is available, we can relax the
grayscale-is-forced-jpeg restriction again, when it will be more
feasible to do so without breaking a million test cases.

Note that this commit updates one FATE test as a consequence of the
sanity fallback for non-YUV formats. In particular, the test case now
writes rgb24(pc, gbr/unspecified/unspecified) to the matroska file,
instead of rgb24(unspecified/unspecified/unspecified) as before.

2 years agoavfilter/formats: set audio fmt lists for vaf filters
Niklas Haas [Thu, 14 Dec 2023 14:15:58 +0000 (15:15 +0100)]
avfilter/formats: set audio fmt lists for vaf filters

Currently, the logic inside the FF_FILTER_FORMATS_QUERY_FUNC branch
prevents this code from running in the event that we have a filter with
a single video input and a single audio output, as the resulting audio
output link will not have its channel counts / samplerates correctly
initialized to their default values, possibly triggering a segfault
downstream.

An example of such a filter is vaf_spectrumsynth. Although this
particular filter already sets up the channel counts and samplerates as
part of the query function and therefore avoids triggering this bug, the
bug still exists in principle. (And importantly, sets a wrong precedent)

2 years agoavfilter: always call ff_default_query_formats
Niklas Haas [Fri, 20 Oct 2023 13:33:16 +0000 (15:33 +0200)]
avfilter: always call ff_default_query_formats

Even if a query func is set. This is safe to do, because
ff_default_query_formats is documented not to touch any filter lists
that were already set by the query func.

The reason to do this is because it allows us to extend
AVFilterFormatsConfig without having to touch every filter in existence.
An alternative implementation of this commit would be to explicitly add
a `ff_default_query_formats` call at the end of every query_formats
function, but that would end up functionally equivalent to this change
while touching a whole lot more code paths for no reason.

As a bonus, eliminates some code/logic duplication from this function.

2 years agoavfilter/formats: document ff_default_query_formats
Niklas Haas [Fri, 20 Oct 2023 13:29:33 +0000 (15:29 +0200)]
avfilter/formats: document ff_default_query_formats

In particular, make it clear that this function will not touch format
lists which were already set by the caller before calling into this
function.

2 years agoAdd jpeg2000 subdescriptor (V2).
Cedric Le Barz [Fri, 8 Dec 2023 15:24:42 +0000 (16:24 +0100)]
Add jpeg2000 subdescriptor (V2).

Signed-off-by: Cedric Le Barz <clebarz@ektacom.com>
2 years agoavcodec/mpegvideo_enc: Use ptrdiff_t for stride
Michael Niedermayer [Sat, 30 Dec 2023 02:09:52 +0000 (03:09 +0100)]
avcodec/mpegvideo_enc: Use ptrdiff_t for stride

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavcodec/mpegvideo_enc: Dont copy beyond the image
Michael Niedermayer [Sat, 30 Dec 2023 02:06:39 +0000 (03:06 +0100)]
avcodec/mpegvideo_enc: Dont copy beyond the image

Fixes: out of array access
Fixes: tickets/10754/poc17ffmpeg

Discovered by Zeng Yunxiang.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavfilter/vf_minterpolate: Check pts before division
Michael Niedermayer [Sat, 30 Dec 2023 01:51:32 +0000 (02:51 +0100)]
avfilter/vf_minterpolate: Check pts before division

Fixes: FPE
Fixes: tickets/10758/poc20ffmpeg

Discovered by Zeng Yunxiang

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavfilter/avf_showwaves: Check history_nb_samples
Michael Niedermayer [Sat, 30 Dec 2023 01:39:58 +0000 (02:39 +0100)]
avfilter/avf_showwaves: Check history_nb_samples

Fixes: out of array access
Fixes: tickets/10756/poc18ffmpeg

Discovered by Zeng Yunxiang
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agolibavfilter/vf_dnn_detect: Add two outputs ssd support
Wenbin Chen [Wed, 27 Dec 2023 04:16:58 +0000 (12:16 +0800)]
libavfilter/vf_dnn_detect: Add two outputs ssd support

For this kind of model, we can directly use its output as final result
just like ssd model. The difference is that it splits output into two
tensors. [x_min, y_min, x_max, y_max, confidence] and [lable_id].

Model example refer to: https://github.com/openvinotoolkit/open_model_zoo/tree/master/models/intel/person-detection-0106

Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
Reviewed-by: Guo Yejun <yejun.guo@intel.com>
2 years agolibavfilter/dnn_backend_openvino: Add dynamic output support
Wenbin Chen [Wed, 27 Dec 2023 04:16:57 +0000 (12:16 +0800)]
libavfilter/dnn_backend_openvino: Add dynamic output support

Add dynamic outputs support. Some models don't have fixed output size.
Its size changes according to result. Now openvino can run these kinds of
models.

Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
Reviewed-by: Guo Yejun <yejun.guo@intel.com>
2 years agoavformat/flacdec: Avoid double AVERRORS
Michael Niedermayer [Mon, 2 Oct 2023 14:10:22 +0000 (16:10 +0200)]
avformat/flacdec: Avoid double AVERRORS

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavfilter/vf_vidstabdetect: Avoid double AVERRORS
Michael Niedermayer [Mon, 2 Oct 2023 14:09:31 +0000 (16:09 +0200)]
avfilter/vf_vidstabdetect: Avoid double AVERRORS

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavcodec/vaapi_encode: Avoid double AVERRORS
Michael Niedermayer [Mon, 2 Oct 2023 14:09:31 +0000 (16:09 +0200)]
avcodec/vaapi_encode: Avoid double AVERRORS

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavfilter/vf_swaprect: round coordinates down
Michael Niedermayer [Fri, 22 Dec 2023 21:27:08 +0000 (22:27 +0100)]
avfilter/vf_swaprect: round coordinates down

Fixes: out of array access:
Fixes: tickets/10745/poc12ffmpeg

Found-by: Li Zeyuan and Zeng Yunxiang.
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavfilter/vf_swaprect: Use height for vertical variables
Michael Niedermayer [Fri, 22 Dec 2023 21:26:22 +0000 (22:26 +0100)]
avfilter/vf_swaprect: Use height for vertical variables

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavfilter/vf_swaprect: assert that rectangles are within memory
Michael Niedermayer [Fri, 22 Dec 2023 21:25:25 +0000 (22:25 +0100)]
avfilter/vf_swaprect: assert that rectangles are within memory

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavfilter/af_alimiter: Check nextpos before use
Michael Niedermayer [Fri, 22 Dec 2023 20:49:48 +0000 (21:49 +0100)]
avfilter/af_alimiter: Check nextpos before use

Fixes: out of array read
Fixes: tickets/10744/poc11ffmpeg

Found-by: Li Zeyuan and Zeng Yunxiang.
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavfilter/f_reverse: Apply PTS compensation only when pts is available
Michael Niedermayer [Sat, 23 Dec 2023 17:04:32 +0000 (18:04 +0100)]
avfilter/f_reverse: Apply PTS compensation only when pts is available

Fixes: out of array access
Fixes: tickets/10753/poc16ffmpeg

Regression since: 45dc668aea0edac34969b5a1ff76cf9ad3a09be1
Found-by: Zeng Yunxiang
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavfilter/af_stereowiden: Check length
Michael Niedermayer [Sat, 23 Dec 2023 03:03:01 +0000 (04:03 +0100)]
avfilter/af_stereowiden: Check length

Fixes: out of array access
Fixes: tickets/10746/poc13ffmpeg

Found-by: Zeng Yunxiang
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavformat/mov: Fix MSAN issue with stsd_id
Thomas Guilbert [Wed, 15 Nov 2023 20:28:49 +0000 (20:28 +0000)]
avformat/mov: Fix MSAN issue with stsd_id

Fixes: use of uninitialized value
Fixes: bbb-320x240-2video-2audio.mp4

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavcodec/jpegxl_parser: Check get_vlc2()
Michael Niedermayer [Wed, 8 Nov 2023 00:48:27 +0000 (01:48 +0100)]
avcodec/jpegxl_parser: Check get_vlc2()

Fixes: shift exponent -1 is negative
Fixes: 63889/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-6009343056936960

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavfilter/vf_weave: Fix odd height handling
Michael Niedermayer [Fri, 22 Dec 2023 11:31:35 +0000 (12:31 +0100)]
avfilter/vf_weave: Fix odd height handling

Fixes: out of array access
Fixes: tickets/10743/poc10ffmpeg

Found-by: Zeng Yunxiang and Li Zeyuan
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavfilter/edge_template: Fix small inputs with gaussian_blur()
Michael Niedermayer [Fri, 22 Dec 2023 10:54:24 +0000 (11:54 +0100)]
avfilter/edge_template: Fix small inputs with gaussian_blur()

Fixes: out of array access
Fixes: Ticket10699
Fixes: poc5ffmpeg

Found-by: Zeng Yunxiang
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavfilter/af_stereotools: round-up max size of buffer
Paul B Mahol [Wed, 20 Dec 2023 08:48:19 +0000 (09:48 +0100)]
avfilter/af_stereotools: round-up max size of buffer

Fixes: out of array access
Fixes: tickets/10747/poc14ffmpeg

Found-by: Zeng Yunxiang and Song Jiaxuan
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavfilter/vf_gradfun: Do not overread last line
Michael Niedermayer [Sun, 24 Dec 2023 19:50:51 +0000 (20:50 +0100)]
avfilter/vf_gradfun: Do not overread last line

The code works in steps of 2 lines and lacks support for odd height
Implementing odd height support is better but for now this fixes the
out of array access

Fixes: out of array access
Fixes: tickets/10702/poc6ffmpe

Found-by: Zeng Yunxiang
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavfilter/avf_showspectrum: fix off by 1 error
Michael Niedermayer [Sun, 24 Dec 2023 19:31:02 +0000 (20:31 +0100)]
avfilter/avf_showspectrum: fix off by 1 error

Fixes: out of array access
Fixes: tickets/10749/poc15ffmpeg

Regression since: 81df787b53eb5c6433731f6eaaf7f2a94d8a8c80

Found-by: Zeng Yunxiang
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavfilter/af_stereowiden: Round length to nearest
Michael Niedermayer [Sun, 24 Dec 2023 18:54:27 +0000 (19:54 +0100)]
avfilter/af_stereowiden: Round length to nearest

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavcodec/leaddec: Check remaining bits in decode_block()
Michael Niedermayer [Fri, 15 Dec 2023 01:18:04 +0000 (02:18 +0100)]
avcodec/leaddec: Check remaining bits in decode_block()

Fixes: Timeout
Fixes: 64163/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_LEAD_fuzzer-6418925835124736

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavcodec/jpegxl_parser: Add padding to cs_buffer
Michael Niedermayer [Fri, 15 Dec 2023 01:07:56 +0000 (02:07 +0100)]
avcodec/jpegxl_parser: Add padding to cs_buffer

Fixes: out of array access
Fixes: 64081/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-6151006496620544

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agotools/target_dec_fuzzer: Adjust threshold for QPEG
Michael Niedermayer [Fri, 15 Dec 2023 00:48:07 +0000 (01:48 +0100)]
tools/target_dec_fuzzer: Adjust threshold for QPEG

Fixes: 63712/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_QPEG_fuzzer-456353017272729
Fixes: Timeout

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavformat/mov: do not set sign bit for chunk_offsets
Michael Niedermayer [Fri, 15 Dec 2023 21:37:49 +0000 (22:37 +0100)]
avformat/mov: do not set sign bit for chunk_offsets

Fixes: signed integer overflow: 2314885530818453536 - -7412889664301817824 cannot be represented in type 'long'
Fixes: 64296/clusterfuzz-testcase-minimized-ffmpeg_dem_MOV_fuzzer-6304027146846208

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavcodec/jpeglsdec: Check Jpeg-LS LSE
Michael Niedermayer [Fri, 15 Dec 2023 21:23:33 +0000 (22:23 +0100)]
avcodec/jpeglsdec: Check Jpeg-LS LSE

Fixes: signed integer overflow: 2147478526 + 33924 cannot be represented in type 'int'
Fixes: shift exponent 32 is too large for 32-bit type 'unsigned int'
Fixes: 64243/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEGLS_fuzzer-5195717848989696

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agotools/target_dec_fuzzer: Adjust Threshold for VP6A
Michael Niedermayer [Fri, 15 Dec 2023 20:07:33 +0000 (21:07 +0100)]
tools/target_dec_fuzzer: Adjust Threshold for VP6A

Fixes: Timeout
Fixes: 64220/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VP6A_fuzzer-5653856213925888

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavcodec/osq: Implement flush()
Michael Niedermayer [Wed, 20 Sep 2023 21:53:21 +0000 (23:53 +0200)]
avcodec/osq: Implement flush()

Fixes: out of array access
Fixes: 62164/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_OSQ_fuzzer-6227491892887552
Fixes: 62164/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_OSQ_fuzzer-6268561729126400
Fixes: 62164/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_OSQ_fuzzer-6414805046788096
Fixes: 62164/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_OSQ_fuzzer-6538151088488448
Fixes: 62164/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_OSQ_fuzzer-6608131540779008

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavcodec/hevc: Add init for sao_edge_filter
jinbo [Thu, 28 Dec 2023 08:20:59 +0000 (16:20 +0800)]
avcodec/hevc: Add init for sao_edge_filter

Forgot to init c->sao_edge_filter[idx] when idx=0/1/2/3.
After this patch, the speedup of decoding H265 4K 30FPS
30Mbps on 3A6000 is about 7% (42fps==>45fps).

Change-Id: I521999b397fa72b931a23c165cf45f276440cdfb
Reviewed-by: yinshiyou-hf@loongson.cn
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoavcodec/bitpacked_dec: optimize bitpacked_decode_yuv422p10
Devin Heitmueller [Fri, 5 May 2023 21:54:17 +0000 (17:54 -0400)]
avcodec/bitpacked_dec: optimize bitpacked_decode_yuv422p10

Rework the code a bit to speed up the 10-bit bitpacked decoding
routine.  This is probably about as fast as I can get it without
switching to assembly language.

Demonstratable with:

./ffmpeg -f lavfi -i "smptehdbars=size=3840x2160" -c bitpacked -f image2 -frames:v 1 source.yuv
./ffmpeg -f bitpacked -pix_fmt yuv422p10le -s 3840x2160 -c:v bitpacked -i source.yuv -pix_fmt yuv422p10le out.yuv

On my development system, it went from 80ms for a 2160p frame
down to 20ms (i.e. a 4X speedup).  Good enough for now, I hope...

Comments from Marton:

Originally on my system better performance could be achieved by simply
switching to the cached bitstream reader, but for Devin it was slower than
his direct byte operations.

I changed the order of writing output from u/y/v/y to u/v/y/y, and that made
the code faster than the cached bitstream reader on my system as well.

TIMER measurement of the decode loop on Ryzen 5 3600 with command line:

./ffmpeg -stream_loop 256 -threads 1 -f bitpacked -pix_fmt yuv422p10le -s 3840x2160 -c:v bitpacked -i source.yuv -pix_fmt yuv422p10le -f null none -loglevel error

Before: 823204127 decicycles in YUV,     256 runs,      0 skips
After:  315070524 decicycles in YUV,     256 runs,      0 skips

Signed-off-by: Devin Heitmueller <dheitmueller@ltnglobal.com>
Signed-off-by: Marton Balint <cus@passwd.hu>
2 years agoavcodec/mjpegdec: avoid indirection when accessing avctx
Marton Balint [Sun, 26 Nov 2023 20:40:27 +0000 (21:40 +0100)]
avcodec/mjpegdec: avoid indirection when accessing avctx

Signed-off-by: Marton Balint <cus@passwd.hu>
2 years agoavcodec/mjpegdec: use memset to clear alpha
Marton Balint [Sat, 25 Nov 2023 18:55:46 +0000 (19:55 +0100)]
avcodec/mjpegdec: use memset to clear alpha

Signed-off-by: Marton Balint <cus@passwd.hu>
2 years agotests/dca: remove usage of deprecated request_channel_layout option
James Almer [Thu, 28 Dec 2023 18:31:50 +0000 (15:31 -0300)]
tests/dca: remove usage of deprecated request_channel_layout option

Signed-off-by: James Almer <jamrial@gmail.com>
2 years agotests/truehd: remove usage of deprecated request_channel_layout option
James Almer [Thu, 28 Dec 2023 18:31:36 +0000 (15:31 -0300)]
tests/truehd: remove usage of deprecated request_channel_layout option

Signed-off-by: James Almer <jamrial@gmail.com>
2 years agoavformat/riffenc: don't force WAVEFORMATEXTENSIBLE for flt/dbl LPCM
Gyan Doshi [Thu, 21 Dec 2023 05:15:58 +0000 (10:45 +0530)]
avformat/riffenc: don't force WAVEFORMATEXTENSIBLE for flt/dbl LPCM

2c2a167ca7 forced WAVEFORMATEXTENSIBLE for all LPCM streams with greater
than 16 bits per sample. However, WAVEFORMATEX allows IEEE Float samples
or any depth where raw depth == coded depth, see Remarks section at
https://learn.microsoft.com/en-us/windows/win32/api/mmreg/ns-mmreg-waveformatex
and samples M1F1-float32-AFsp, M1F1-float64-AFsp at
https://www.mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Samples.html

There are hardware devices and likely software players requiring float samples
that fail to qualify files with WAVEFORMATEXTENSIBLE headers.

2 years agoavfilter/vf_showinfo: add udu_sei_as_ascii option
Zhao Zhili [Wed, 13 Dec 2023 03:46:48 +0000 (11:46 +0800)]
avfilter/vf_showinfo: add udu_sei_as_ascii option

Some encoders (e.g., libx264) dump encoder configuration as user
data unregistered SEI message. This option try to print it as
ascii character when possible.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2 years agoavcodec/jpegxl_parser: check ANS cluster alphabet size vs bundle size
Leo Izen [Sat, 23 Dec 2023 02:50:44 +0000 (21:50 -0500)]
avcodec/jpegxl_parser: check ANS cluster alphabet size vs bundle size

The specification doesn't mention that clusters cannot have alphabet
sizes greater than 1 << bundle->log_alphabet_size, but the reference
implementation rejects these entropy streams as invalid, so we should
too. Refusing to do so can overflow a stack variable that should be
large enough otherwise.

Fixes #10738.

Found-by: Zeng Yunxiang and Li Zeyuan
Signed-off-by: Leo Izen <leo.izen@gmail.com>
2 years agox86/takdsp: add missing wrappers to AVX2 functions
James Almer [Tue, 26 Dec 2023 01:31:15 +0000 (22:31 -0300)]
x86/takdsp: add missing wrappers to AVX2 functions

Fixes compilation with old yasm.

Signed-off-by: James Almer <jamrial@gmail.com>
2 years agoconfigure: Enable section_data_rel_ro for FreeBSD and NetBSD aarch64 / arm
Brad Smith [Sun, 24 Dec 2023 19:33:31 +0000 (14:33 -0500)]
configure: Enable section_data_rel_ro for FreeBSD and NetBSD aarch64 / arm

Fixes the build. It's a requirement when utilizing PIE.

Signed-off-by: Brad Smith <brad@comstyle.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2 years agoRemove myself from maintainers.
Matt Oliver [Sat, 23 Dec 2023 12:15:55 +0000 (23:15 +1100)]
Remove myself from maintainers.

2 years agox86/takdsp: add avx2 versions of all functions
James Almer [Fri, 22 Dec 2023 23:34:52 +0000 (20:34 -0300)]
x86/takdsp: add avx2 versions of all functions

On an Intel Core i7 12700k:

decorrelate_ls_c: 814.3
decorrelate_ls_sse2: 165.8
decorrelate_ls_avx2: 101.3
decorrelate_sf_c: 1602.6
decorrelate_sf_sse4: 640.1
decorrelate_sf_avx2: 324.6
decorrelate_sm_c: 1564.8
decorrelate_sm_sse2: 379.3
decorrelate_sm_avx2: 203.3
decorrelate_sr_c: 785.3
decorrelate_sr_sse2: 176.3
decorrelate_sr_avx2: 99.8

Tested-by: Lynne <dev@lynne.ee>
Signed-off-by: James Almer <jamrial@gmail.com>
2 years agoavcodec/libjxlenc: Set AV_CODEC_CAP_DR1
Andreas Rheinhardt [Thu, 21 Dec 2023 23:03:03 +0000 (00:03 +0100)]
avcodec/libjxlenc: Set AV_CODEC_CAP_DR1

This encoder uses ff_get_encode_buffer() to allocate the packet buffer.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2 years agoavcodec/libjxlenc: Don't refer to decoder in comments
Andreas Rheinhardt [Thu, 21 Dec 2023 23:01:52 +0000 (00:01 +0100)]
avcodec/libjxlenc: Don't refer to decoder in comments

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2 years agoavcodec/libjxldec: emit proper PTS to decoded AVFrame
Leo Izen [Fri, 15 Dec 2023 21:06:33 +0000 (16:06 -0500)]
avcodec/libjxldec: emit proper PTS to decoded AVFrame

If a sequence of JXL images is encapsulated in a container that has PTS
information, we should use the PTS information from the container. At
this time there is no container that does this, but if JPEG XL support
is ever added to NUT, AVTransport, or some other container, this commit
should allow the PTS information those containers provide to work as
expected.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2 years agoavcodec/libjxlenc: accept rgbf32 and rgbaf32 frames
Leo Izen [Mon, 11 Dec 2023 12:02:33 +0000 (07:02 -0500)]
avcodec/libjxlenc: accept rgbf32 and rgbaf32 frames

These pixel formats have always been supported by libjxl, but at the
time this plugin was written, they were not in FFmpeg yet. Now that
they are in FFmpeg, we should support them.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2 years agoavcodec/libjxldec: produce rgbf32 and rgbaf32 frames
Leo Izen [Mon, 11 Dec 2023 12:02:32 +0000 (07:02 -0500)]
avcodec/libjxldec: produce rgbf32 and rgbaf32 frames

These pixel formats have always been supported by libjxl, but at the
time this plugin was written, they were not in FFmpeg yet. Now that
they are in FFmpeg, we should support them.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2 years agoavcodec/pngdec: improve handling of bad cICP range tags
Leo Izen [Tue, 12 Dec 2023 19:41:01 +0000 (14:41 -0500)]
avcodec/pngdec: improve handling of bad cICP range tags

FFmpeg doesn't support tv-range RGB throughout most of its pipeline, so
we should keep the warning. However, in case something does support it
we should at least keep it tagged properly. Additionally, the encoder
writes this tag if the space is tagged as such so this makes a round
trip work as it should.

Also, PNG doesn't support nonzero matrices but we only warn and ignore
in that case, so we have no reason to error out for illegal cICP ranges
either (i.e. greater than 1).

Signed-off-by: Leo Izen <leo.izen@gmail.com>
Reported-by: Kacper Michajłow <kasper93@gmail.com>
2 years agolavc/takdsp: R-V V decorrelate_sm
sunyuechi [Mon, 18 Dec 2023 14:53:39 +0000 (22:53 +0800)]
lavc/takdsp: R-V V decorrelate_sm

C908:
decorrelate_sm_c: 130.0
decorrelate_sm_rvv_i32: 43.2

Signed-off-by: Rémi Denis-Courmont <remi@remlab.net>
(with minor changes)

2 years agoall: Don't set AVClass.item_name to its default value
Andreas Rheinhardt [Fri, 22 Dec 2023 13:47:15 +0000 (14:47 +0100)]
all: Don't set AVClass.item_name to its default value

Unnecessary since acf63d5350adeae551d412db699f8ca03f7e76b9;
also avoids relocations.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2 years agoavcodec/takdsp: fix const correctness
James Almer [Fri, 22 Dec 2023 12:09:33 +0000 (09:09 -0300)]
avcodec/takdsp: fix const correctness

Signed-off-by: James Almer <jamrial@gmail.com>
2 years agocheckasm/takdsp: add decorrelate_sf test
James Almer [Fri, 22 Dec 2023 01:11:25 +0000 (22:11 -0300)]
checkasm/takdsp: add decorrelate_sf test

Signed-off-by: James Almer <jamrial@gmail.com>
2 years agocheckasm: Fix the takdsp tests
Martin Storsjö [Fri, 22 Dec 2023 09:39:57 +0000 (11:39 +0200)]
checkasm: Fix the takdsp tests

For memcpy and memcmp, we need to multiply by the element size,
otherwise we're copying and comparing only a fraction of the buffer.

For decorrelate_sr, the buffer p1 is the one that is mutated;
copy and check p1 instead of p2.

For decorrelate_sm, both buffers are mutated, so copy and check
both of them.

For decorrelate_sm, the memcpy initialization of p1 and p1_2 was
reversed - p1 is filled with randomize, but then memcpy copies from
p1_2 to p1. As p1_2 is uninitialized at this point, clang concluded
that the copy was bogus and omitted it entirely, triggering failures
in this test on x86 (where there was an existing assembly implementation
to test).

Signed-off-by: Martin Storsjö <martin@martin.st>
2 years agofftools/ffmpeg: remove deprecated -[av]bsf
Anton Khirnov [Mon, 18 Dec 2023 09:54:11 +0000 (10:54 +0100)]
fftools/ffmpeg: remove deprecated -[av]bsf

They were marked as deprecated over 10 years ago.

2 years agofftools/ffmpeg: mark -vsync for future removal
Anton Khirnov [Mon, 18 Dec 2023 09:50:44 +0000 (10:50 +0100)]
fftools/ffmpeg: mark -vsync for future removal

It has already been deprecated over a year ago.

2 years agofftools/ffmpeg_opt: fix -dn flags
Anton Khirnov [Mon, 18 Dec 2023 09:24:45 +0000 (10:24 +0100)]
fftools/ffmpeg_opt: fix -dn flags

It's a data, not video option.

2 years agofftools/ffmpeg_opt: print a section for data-stream options
Anton Khirnov [Mon, 18 Dec 2023 09:24:45 +0000 (10:24 +0100)]
fftools/ffmpeg_opt: print a section for data-stream options

Only show it with show_advanced (triggered by -h long), since data
streams themselves are an advanced topic.