ffmpeg.git
35 hours agoavfilter/vsrc_ddagrab: add options for more control over output format fallback master
Timo Rothenpieler [Sun, 7 Aug 2022 21:14:09 +0000 (23:14 +0200)]
avfilter/vsrc_ddagrab: add options for more control over output format fallback

35 hours agoavfilter/vsrc_ddagrab: add rgbaf16 output support
Timo Rothenpieler [Sun, 7 Aug 2022 19:50:12 +0000 (21:50 +0200)]
avfilter/vsrc_ddagrab: add rgbaf16 output support

35 hours agoavutil/hwcontext_d3d11va: add support for rgbaf16 pixel format
Timo Rothenpieler [Sun, 7 Aug 2022 20:16:28 +0000 (22:16 +0200)]
avutil/hwcontext_d3d11va: add support for rgbaf16 pixel format

35 hours agolavu/pixfmt: add packed RGBA float16 format
Timo Rothenpieler [Sun, 7 Aug 2022 19:03:59 +0000 (21:03 +0200)]
lavu/pixfmt: add packed RGBA float16 format

This is the default format of the Windows compositor and what DXGI
Desktop Duplication will give you for any kind of HDR output.

36 hours agocompat: add msvc windres wrapper
Timo Rothenpieler [Sun, 7 Aug 2022 14:31:51 +0000 (16:31 +0200)]
compat: add msvc windres wrapper

This is by no means a complete wrapper. It's only designed to fit the
usecase ffmpegs build system has.

36 hours agofftools: add DPI awareness manifest
Timo Rothenpieler [Sun, 7 Aug 2022 13:28:24 +0000 (15:28 +0200)]
fftools: add DPI awareness manifest

Some filters, like gdigrab, rely on this to be set to see and report
proper dimensions.

36 hours agoconfigure: always enable gnu_windres if available
Timo Rothenpieler [Sun, 7 Aug 2022 13:26:06 +0000 (15:26 +0200)]
configure: always enable gnu_windres if available

Use the appropiate Makefile variable to ensure the resource file is
only built into shared libraries instead.

38 hours agofftools/ffmpeg: move packet timestamp processing to demuxer thread
Anton Khirnov [Wed, 10 Aug 2022 15:15:06 +0000 (17:15 +0200)]
fftools/ffmpeg: move packet timestamp processing to demuxer thread

Discontinuity detection/correction is left in the main thread, as it is
entangled with InputStream.next_dts and related variables, which may be
set by decoding code.

Fixes races e.g. in fate-ffmpeg-streamloop after
aae9de0cb2887e6e0bbfda6ffdf85ab77d3390f0.

38 hours agofftools/ffmpeg: use a separate variable for discontinuity offset
Anton Khirnov [Wed, 10 Aug 2022 15:37:12 +0000 (17:37 +0200)]
fftools/ffmpeg: use a separate variable for discontinuity offset

This will allow to move normal offset handling to demuxer thread, since
discontinuities currently have to be processed in the main thread, as
the code uses some decoder-produced values.

38 hours agofftools/ffmpeg: simplify conditions in ts_discontinuity_process
Anton Khirnov [Wed, 10 Aug 2022 15:04:30 +0000 (17:04 +0200)]
fftools/ffmpeg: simplify conditions in ts_discontinuity_process

38 hours agofftools/ffmpeg: move inter-stream ts discontinuity handling to ts_discontinuity_process()
Anton Khirnov [Wed, 10 Aug 2022 14:48:03 +0000 (16:48 +0200)]
fftools/ffmpeg: move inter-stream ts discontinuity handling to ts_discontinuity_process()

38 hours agofftools/ffmpeg: move timestamp discontinuity correction out of process_input()
Anton Khirnov [Wed, 10 Aug 2022 14:33:43 +0000 (16:33 +0200)]
fftools/ffmpeg: move timestamp discontinuity correction out of process_input()

38 hours agofftools/ffmpeg: pre-compute the streamcopy start pts before transcoding starts
Anton Khirnov [Wed, 10 Aug 2022 08:44:30 +0000 (10:44 +0200)]
fftools/ffmpeg: pre-compute the streamcopy start pts before transcoding starts

InputFile.ts_offset can change during transcoding, due to discontinuity
correction. This should not affect the streamcopy starting timestamp.

Cf. bf2590aed3e64d44a5e2430fdbe89f91f5e55bfe

38 hours agofftools/ffmpeg: move stream-dependent starttime correction to transcode_init()
Anton Khirnov [Tue, 9 Aug 2022 07:51:25 +0000 (09:51 +0200)]
fftools/ffmpeg: move stream-dependent starttime correction to transcode_init()

Currently this code is located in the discontinuity handling block,
where it does not belong.

38 hours agofftools/ffmpeg_mux: avoid leaking pkt on errors
Anton Khirnov [Tue, 9 Aug 2022 13:19:41 +0000 (15:19 +0200)]
fftools/ffmpeg_mux: avoid leaking pkt on errors

38 hours agofftools/ffmpeg: mark all encode sync queues as done before flushing encoders
Anton Khirnov [Tue, 9 Aug 2022 13:01:33 +0000 (15:01 +0200)]
fftools/ffmpeg: mark all encode sync queues as done before flushing encoders

2 days agoavformat/avisynth: add missing avs_release_video_frame
Stephen Hutchinson [Sat, 23 Apr 2022 20:07:39 +0000 (16:07 -0400)]
avformat/avisynth: add missing avs_release_video_frame

The AviSynth C API requires using avs_release_video_frame
whenever avs_get_frame has been used, but the recent addition
of frameprop reading to the demuxer was missing this in
avisynth_create_stream_video.

Signed-off-by: Stephen Hutchinson <qyot27@gmail.com>
2 days agoavcodec/mimic: Fix undefined pointer arithmetic
Andreas Rheinhardt [Thu, 11 Aug 2022 22:27:41 +0000 (00:27 +0200)]
avcodec/mimic: Fix undefined pointer arithmetic

NULL + anything is UB.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2 days agoavformat/imfdec: preserve stream information
Pierre-Anthony Lemieux [Sat, 6 Aug 2022 23:35:20 +0000 (16:35 -0700)]
avformat/imfdec: preserve stream information

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2 days agoavformat: refactor ff_stream_encode_params_copy() to stream_params_copy()
Pierre-Anthony Lemieux [Sat, 6 Aug 2022 23:35:19 +0000 (16:35 -0700)]
avformat: refactor ff_stream_encode_params_copy() to stream_params_copy()

Addresses http://ffmpeg.org/pipermail/ffmpeg-devel/2022-August/299726.html

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2 days agoconfigure: add --enable-libvpl option
Haihao Xiang [Wed, 3 Feb 2021 06:49:46 +0000 (14:49 +0800)]
configure: add --enable-libvpl option

This allows user to build FFmpeg against Intel oneVPL. oneVPL 2.6
is the required minimum version when building Intel oneVPL code.

It will fail to run configure script if both libmfx and libvpl are
enabled.

It is recommended to use oneVPL for new work, even for currently available
hardwares [1]

Note the preferred child device type is d3d11va for libvpl on Windows.
The commands below will use d3d11va if d3d11va is available on Windows.
$ ffmpeg -hwaccel qsv -c:v h264_qsv ...
$ ffmpeg -qsv_device 0 -hwaccel qsv -c:v h264_qsv ...
$ ffmpeg -init_hw_device qsv=qsv:hw_any -hwaccel qsv -c:v h264_qsv ...
$ ffmpeg -init_hw_device qsv=qsv:hw_any,child_device=0 -hwaccel qsv -c:v h264_qsv ...

User may use child_device_type option to specify child device type to
dxva2 or derive a qsv device from a dxva2 device
$ ffmpeg -init_hw_device qsv=qsv:hw_any,child_device=0,child_device_type=dxva2 -hwaccel qsv -c:v h264_qsv ...
$ ffmpeg -init_hw_device dxva2=d3d9:0 -init_hw_device qsv=qsv@d3d9 -hwaccel qsv -c:v h264_qsv ...

[1] https://www.intel.com/content/www/us/en/develop/documentation/upgrading-from-msdk-to-onevpl/top.html

2 days agolavfi/qsv: create mfx session using oneVPL for qsv filters
Haihao Xiang [Mon, 4 Jan 2021 02:46:14 +0000 (10:46 +0800)]
lavfi/qsv: create mfx session using oneVPL for qsv filters

Use the mfxLoader handle in qsv hwdevice to create mfx session for qsv
filters.

This is in preparation for oneVPL support

2 days agolavc/qsv: create mfx session using oneVPL for decoding/encoding
Haihao Xiang [Mon, 4 Jan 2021 02:46:14 +0000 (10:46 +0800)]
lavc/qsv: create mfx session using oneVPL for decoding/encoding

If qsv hwdevice is available, use the mfxLoader handle in qsv hwdevice
to create mfx session. Otherwise create mfx session with a new mfxLoader
handle.

This is in preparation for oneVPL support

2 days agolavu/hwcontext_qsv: make qsv hwdevice works with oneVPL
Haihao Xiang [Mon, 4 Jan 2021 02:46:14 +0000 (10:46 +0800)]
lavu/hwcontext_qsv: make qsv hwdevice works with oneVPL

In oneVPL, MFXLoad() and MFXCreateSession() are required to create a
workable mfx session[1]

Add config filters for D3D9/D3D11 session (galinart)

The default device is changed to d3d11va for oneVPL when both d3d11va
and dxva2 are enabled on Microsoft Windows

This is in preparation for oneVPL support

[1] https://spec.oneapi.io/versions/latest/elements/oneVPL/source/programming_guide/VPL_prg_session.html#onevpl-dispatcher

Co-authored-by: galinart <artem.galin@intel.com>
Signed-off-by: galinart <artem.galin@intel.com>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2 days agolavu/hwcontext_qsv: add loader field to AVQSVDeviceContext
Haihao Xiang [Tue, 5 Jul 2022 03:04:49 +0000 (11:04 +0800)]
lavu/hwcontext_qsv: add loader field to AVQSVDeviceContext

In oneVPL, a valid mfxLoader handle is needed when creating mfx session
for decoding, encoding and processing[1], so add loader field to
AVQSVDeviceContext. User should fill this field before calling
av_hwdevice_ctx_init() if using oneVPL

This is in preparation for oneVPL support

[1]https://spec.oneapi.io/versions/latest/elements/oneVPL/source/programming_guide/VPL_prg_session.html#onevpl-dispatcher

2 days agoqsv: restrict OPAQUE memory to MFX_VERSION < 2.0
Haihao Xiang [Wed, 19 Aug 2020 01:43:12 +0000 (09:43 +0800)]
qsv: restrict OPAQUE memory to MFX_VERSION < 2.0

OPAQUE memory isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL support

[1] https://spec.oneapi.io/versions/latest/elements/oneVPL/source/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2] https://github.com/oneapi-src/oneVPL

2 days agoqsvenc: restrict MFX_RATECONTROL_LA_EXT to MFX_VERSION < 2.0
Haihao Xiang [Wed, 19 Aug 2020 04:49:14 +0000 (12:49 +0800)]
qsvenc: restrict MFX_RATECONTROL_LA_EXT to MFX_VERSION < 2.0

MFX_RATECONTROL_LA_EXT isn't supported for MFX_VERSION >= 2.0[1][2].
This is in preparation for oneVPL support

[1] https://spec.oneapi.io/versions/latest/elements/oneVPL/source/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2] https://github.com/oneapi-src/oneVPL

2 days agoqsvenc: restrict multi-frame encode to MFX_VERSION < 2.0
Haihao Xiang [Wed, 19 Aug 2020 04:41:16 +0000 (12:41 +0800)]
qsvenc: restrict multi-frame encode to MFX_VERSION < 2.0

Multi-frame encode isn't supported for MFX_VERSION >= 2.0[1][2]. This is
in preparation for oneVPL support

[1] https://spec.oneapi.io/versions/latest/elements/oneVPL/source/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2] https://github.com/oneapi-src/oneVPL

2 days agoqsv: restrict audio related code to MFX_VERSION < 2.0
Haihao Xiang [Tue, 18 Aug 2020 07:30:32 +0000 (15:30 +0800)]
qsv: restrict audio related code to MFX_VERSION < 2.0

Audio isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL support

[1] https://spec.oneapi.io/versions/latest/elements/oneVPL/source/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2] https://github.com/oneapi-src/oneVPL

2 days agoqsv: restrict user plugin to MFX_VERSION < 2.0
Haihao Xiang [Tue, 18 Aug 2020 07:20:38 +0000 (15:20 +0800)]
qsv: restrict user plugin to MFX_VERSION < 2.0

User plugin isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL Support

[1] https://spec.oneapi.io/versions/latest/elements/oneVPL/source/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2] https://github.com/oneapi-src/oneVPL

2 days agoqsv: remove mfx/ prefix from mfx headers
Haihao Xiang [Tue, 8 Sep 2020 03:17:27 +0000 (11:17 +0800)]
qsv: remove mfx/ prefix from mfx headers

The following Cflags has been added to libmfx.pc, so mfx/ prefix is no
longer needed when including mfx headers in FFmpeg.
   Cflags: -I${includedir} -I${includedir}/mfx

Some old versions of libmfx have the following Cflags in libmfx.pc
   Cflags: -I${includedir}

We may add -I${includedir}/mfx to CFLAGS when running 'configure
--enable-libmfx' for old versions of libmfx, if so, mfx headers without
mfx/ prefix can be included too.

If libmfx comes without pkg-config support, we may do a small change to
the settings of the environment(e.g. set -I/opt/intel/mediasdk/include/mfx
instead of -I/opt/intel/mediasdk/include to CFLAGS), then the build can
find the mfx headers without mfx/ prefix

After applying this change, we won't need to change #include for mfx
headers when mfx headers are installed under a new directory.

This is in preparation for oneVPL support (mfx headers in oneVPL are
installed under vpl directory)

2 days agoconfigure: fix the check for MFX_CODEC_VP9
Haihao Xiang [Fri, 19 Feb 2021 00:51:35 +0000 (08:51 +0800)]
configure: fix the check for MFX_CODEC_VP9

The data structures for VP9 in mfxvp9.h is wrapped by
MFX_VERSION_NEXT, which means those data structures have never been used
in a public release. Actually MFX_CODEC_VP9 and other VP9 stuffs are
added in mfxstructures.h. In addition, mfxdefs.h is included in
mfxvp9.h, so we may use the check in this patch for MFX_CODEC_VP9

This is in preparation for oneVPL support because mfxvp9.h is removed
from oneVPL [1]

[1]: https://github.com/oneapi-src/oneVPL

2 days agoconfigure: ensure --enable-libmfx uses libmfx 1.x
Haihao Xiang [Wed, 3 Feb 2021 01:08:27 +0000 (09:08 +0800)]
configure: ensure --enable-libmfx uses libmfx 1.x

Intel's oneVPL is a successor to MediaSDK, but removed some obsolete
features of MediaSDK[1], some early versions of oneVPL still use libmfx
as library name[2]. However some of obsolete features, including OPAQUE
memory, multi-frame encode, user plugins and LA_EXT rate control mode
etc, have been enabled in QSV, so user can not use --enable-libmfx to
enable QSV if using an early version of oneVPL SDK. In order to ensure
user builds FFmpeg against a right version of libmfx, this patch added a
check for version < 2.0 and warning message about the used obsolete
features.

[1] https://spec.oneapi.io/versions/latest/elements/oneVPL/source/VPL_intel_media_sdk.html
[2] https://github.com/oneapi-src/oneVPL

4 days agoavcodec/mpegvideo: Move setting mb_height to ff_mpv_init_context_frame
Andreas Rheinhardt [Mon, 8 Aug 2022 11:06:54 +0000 (13:06 +0200)]
avcodec/mpegvideo: Move setting mb_height to ff_mpv_init_context_frame

It is the proper place to set it, directly besides mb_width and
mb_stride. The reason for doing it the way it is done now seems
to be that the code does not create more slice contexts than necessary
(i.e. not more than one per row), so that this number needs to be
known before setting the number of slices. But this can always be
arranged by just moving the code that sets the number of slices.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
4 days agoavcodec/mpegvideo_enc: Remove redundant cast
Andreas Rheinhardt [Tue, 9 Aug 2022 16:49:01 +0000 (18:49 +0200)]
avcodec/mpegvideo_enc: Remove redundant cast

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
4 days agoavcodec/mpegvideo_enc: Remove redundant check
Andreas Rheinhardt [Tue, 9 Aug 2022 11:37:41 +0000 (13:37 +0200)]
avcodec/mpegvideo_enc: Remove redundant check

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
4 days agoavcodec/mpegvideo_enc: Don't copy Picture unnecessarily
Andreas Rheinhardt [Tue, 9 Aug 2022 11:34:25 +0000 (13:34 +0200)]
avcodec/mpegvideo_enc: Don't copy Picture unnecessarily

Also add const where possible.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
4 days agoavcodec/mpegpicture: Move encoding_error and mb_var_sum to MpegEncCtx
Andreas Rheinhardt [Tue, 9 Aug 2022 12:14:38 +0000 (14:14 +0200)]
avcodec/mpegpicture: Move encoding_error and mb_var_sum to MpegEncCtx

These fields are only ever set by the encoder for the current picture
and for no other picture. So only one set of these values needs to
exist, so move them to MpegEncContext.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
4 days agoavutil/buffer: Never poison returned buffers
Andreas Rheinhardt [Mon, 4 Oct 2021 14:44:46 +0000 (16:44 +0200)]
avutil/buffer: Never poison returned buffers

Poisoning returned buffers is based around the implicit assumption
that the contents of said buffers are transient. Yet this is not true
for the buffer pools used by the various hardware contexts which store
important state in there that needs to be preserved.
Furthermore, the current code is also based on the assumption
that the complete buffer pointed to by AVBuffer->data coincides with
AVBufferRef->data; yet an implementation might store some data of its
own before the actual user-visible data (accessible via AVBufferRef)
which would be broken by the current code.

(This is of course yet more proof that the AVBuffer API is not the right
tool for the hardware contexts.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
4 days agoavcodec/mpegpicture: Remove always-true checks
Andreas Rheinhardt [Mon, 8 Aug 2022 08:42:32 +0000 (10:42 +0200)]
avcodec/mpegpicture: Remove always-true checks

Of all the buffers that are made writable, three are always allocated
and the other four are allocated iff any one of them is allocated;
so one can replace the seven checks for existence with one.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
4 days agoavcodec/mpegutils: Constify ff_print_debug_info2, ff_draw_horiz_band
Andreas Rheinhardt [Tue, 9 Aug 2022 11:17:38 +0000 (13:17 +0200)]
avcodec/mpegutils: Constify ff_print_debug_info2, ff_draw_horiz_band

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
4 days agoavcodec/mpegutils: Combine multiple av_log statements
Andreas Rheinhardt [Mon, 8 Aug 2022 10:03:45 +0000 (12:03 +0200)]
avcodec/mpegutils: Combine multiple av_log statements

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
4 days agoavcodec/wmv2dec: Zero mb_type array for I pictures
Andreas Rheinhardt [Tue, 9 Aug 2022 14:36:16 +0000 (16:36 +0200)]
avcodec/wmv2dec: Zero mb_type array for I pictures

Up until now, ff_wmv2_decode_secondary_picture_header() only
set the mb_type array for non I-pictures, so that the decoding
process uses the earlier values of this array; this affects
the output of the wmv8-x8intra FATE-test (which this patch
therefore updates). These earlier values were set when decoding
earlier frames or when the buffer was initially zero-allocated.
A consequence of this is that the output of this test would be
random if ff_find_unused_picture() would select the unused picture
to return at random. Furthermore decoding from a keyframe onwards
depends upon the earlier state of the decoder.

This patch therefore zeroes said array when decoding an I picture.

(It is not claimed that zero is the right value to fill the array with.
I just don't know.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
4 days agoavcodec/vp9: Remove redundant reporting of progress on error
Andreas Rheinhardt [Wed, 10 Aug 2022 12:53:27 +0000 (14:53 +0200)]
avcodec/vp9: Remove redundant reporting of progress on error

Redundant since 5e03eea673a9da2253ed15152e46b1422b35d145.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
4 days agoavcodec/pthread_frame: Fix compiling with thread-unsafe-callbacks disabled
Andreas Rheinhardt [Wed, 10 Aug 2022 06:37:02 +0000 (08:37 +0200)]
avcodec/pthread_frame: Fix compiling with thread-unsafe-callbacks disabled

Forgotten in 02220b88fc38ef9dd4f2d519f5d3e4151258b60c.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
4 days agoavfilter/framesync: add a new option to set how to sync streams based on secondary...
James Almer [Tue, 2 Aug 2022 11:28:48 +0000 (08:28 -0300)]
avfilter/framesync: add a new option to set how to sync streams based on secondary input timestamps

Include two values for it, a default one that sets/keeps the current behavior,
where the frame event generated by the primary input will have a timestamp
equal or higher than frames in secondary input, plus a new one where the
secondary input frame will be that with the absolute closest timestamp to that
of the frame event one.

Addresses ticket #9689, where the new optional behavior produces better frame
syncronization.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: James Almer <jamrial@gmail.com>
5 days agoavformat/mov: Rework the AVIF parser to handle multiple items
Vignesh Venkatasubramanian [Thu, 28 Jul 2022 18:25:16 +0000 (11:25 -0700)]
avformat/mov: Rework the AVIF parser to handle multiple items

Stores the item ids of all the items found in the file and
processes the primary item at the end of the meta box. This patch
does not change any behavior. It sets up the code for parsing
alpha channel (and possibly images with 'grid') in follow up
patches.

Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Vignesh Venkatasubramanian <vigneshv@google.com>
Signed-off-by: James Zern <jzern@google.com>
5 days agoMAINTAINERS: Add ED25519 key for signing my commits in the future
Michael Niedermayer [Tue, 9 Aug 2022 19:53:32 +0000 (21:53 +0200)]
MAINTAINERS: Add ED25519 key for signing my commits in the future

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
5 days agoavcodec/mpegpicture: Move mb_var, mc_mb_var and mb_mean to MpegEncCtx
Andreas Rheinhardt [Sun, 7 Aug 2022 07:02:51 +0000 (09:02 +0200)]
avcodec/mpegpicture: Move mb_var, mc_mb_var and mb_mean to MpegEncCtx

These tables are only used by encoders and only for the current picture;
ergo they need not be put into the picture at all, but rather into
the encoder's context. They also don't need to be refcounted,
because there is only one owner.

In contrast to this, the earlier code refcounts them which
incurs unnecessary overhead. These references are not unreferenced
in ff_mpeg_unref_picture() (they are kept in order to have something
like a buffer pool), so that several buffers are kept at the same
time, although only one is needed, thereby wasting memory.

The code also propagates references to other pictures not part of
the pictures array (namely the copy of the current/next/last picture
in the MpegEncContext which get references of their own). These
references are not unreferenced in ff_mpeg_unref_picture() (the
buffers are probably kept in order to have something like a pool),
yet if the current picture is a B-frame, it gets unreferenced
at the end of ff_mpv_encode_picture() and its slot in the picture
array will therefore be reused the next time; but the copy of the
current picture also still has its references and therefore
these buffers will be made duplicated in order to make them writable
in the next call to ff_mpv_encode_picture(). This is of course
unnecessary.

Finally, ff_find_unused_picture() is supposed to just return
any unused picture and the code is supposed to work with it;
yet for the vsynth*-mpeg4-adap tests the result depends upon
the content of these buffers; given that this patchset
changes the content of these buffers (the initial content is now
the state of these buffers after encoding the last frame;
before this patch the buffers used came from the last picture
that occupied the same slot in the picture array) their ref-files
needed to be changed. This points to a bug somewhere (if one removes
the initialization, one gets uninitialized reads in
adaptive_quantization in ratecontrol.c).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
5 days agolavc/vaapi_encode: enable 8bit 4:4:4 encoding for HEVC and VP9
Philip Langdale [Fri, 5 Aug 2022 03:35:04 +0000 (20:35 -0700)]
lavc/vaapi_encode: enable 8bit 4:4:4 encoding for HEVC and VP9

Sufficiently recent Intel hardware is able to do encoding of 8bit 4:4:4
content in HEVC and VP9. The main requirement here is that the frames
must be provided in the AYUV format.

Enabling support is done by adding the appropriate encoding profiles
and noting that AYUV is officially a four channel format with alpha so
we must state that we expect all four channels.

5 days agolavc/vaapi_decode: add missing flag when picking best pixel format
Philip Langdale [Fri, 5 Aug 2022 03:24:48 +0000 (20:24 -0700)]
lavc/vaapi_decode: add missing flag when picking best pixel format

vaapi_decode_find_best_format currently does not set the
VA_SURFACE_ATTRIB_SETTABLE flag on the pixel format attribute that it
returns.

Without this flag, the attribute will be ignored by vaCreateSurfaces,
meaning that the driver's default logic for picking a pixel format will
kick in.

So far, this hasn't produced visible problems, but when trying to
decode 4:4:4 content, at least on Intel, the driver will pick the
444P planar format, even though the decoder can only return the AYUV
packed format.

The hwcontext_vaapi code that sets surface attributes when picking
formats does not have this bug.

Applications may use their own logic for finding the best format, and
so may not hit this bug. eg: mpv is unaffected.

5 days agodoc/filters: clarify behaviour of weights in amix
Gyan Doshi [Tue, 9 Aug 2022 08:28:16 +0000 (13:58 +0530)]
doc/filters: clarify behaviour of weights in amix

5 days agolavfi/overlay_vaapi: set defalut alpha value as 1.0
Fei Wang [Fri, 5 Aug 2022 06:11:19 +0000 (14:11 +0800)]
lavfi/overlay_vaapi: set defalut alpha value as 1.0

The present default value of 0 will render the overlay video invisible.
A default of 1.0 is consistent with most common use cases.

Signed-off-by: Fei Wang <fei.w.wang@intel.com>
Reviewed-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
5 days agodoc/filters: correct description of overlay_vaapi
Fei Wang [Fri, 5 Aug 2022 06:11:18 +0000 (14:11 +0800)]
doc/filters: correct description of overlay_vaapi

Signed-off-by: Fei Wang <fei.w.wang@intel.com>
Reviewed-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
5 days agodoc/filters: add examples for amix to subsection
Gyan Doshi [Tue, 9 Aug 2022 04:46:50 +0000 (10:16 +0530)]
doc/filters: add examples for amix to subsection

5 days agox86/tx_float: save a branch during coefficient deinterleaving
Lynne [Tue, 9 Aug 2022 01:31:11 +0000 (03:31 +0200)]
x86/tx_float: save a branch during coefficient deinterleaving

Directly branch into the special 64-point deinterleave
subroutine rather than going through the general deinterleave.

64-point transform timings on Zen 3:
Before:
   1974 decicycles in           av_tx (fft),16776864 runs,    352 skips
After:
   1956 decicycles in           av_tx (fft),16775378 runs,   1838 skips

6 days agocheckasm: Silence warnings about unused return value from read()
Martin Storsjö [Wed, 25 May 2022 07:27:37 +0000 (10:27 +0300)]
checkasm: Silence warnings about unused return value from read()

This codepath is enabled by default on arm, if the linux perf API
is available, unless disabled with --disable-linux-perf.

Signed-off-by: Martin Storsjö <martin@martin.st>
6 days agofftools/ffmpeg: move handling corrupt packets to the input thread
Anton Khirnov [Tue, 22 Mar 2022 17:17:27 +0000 (18:17 +0100)]
fftools/ffmpeg: move handling corrupt packets to the input thread

6 days agofftools/ffmpeg_demux: do not store demux packet in the context
Anton Khirnov [Tue, 22 Mar 2022 16:59:30 +0000 (17:59 +0100)]
fftools/ffmpeg_demux: do not store demux packet in the context

Its use is local to input_thread().

6 days agofftools/ffmpeg_demux: factorize signalling end of demuxing
Anton Khirnov [Tue, 22 Mar 2022 16:56:30 +0000 (17:56 +0100)]
fftools/ffmpeg_demux: factorize signalling end of demuxing

6 days agofftools/ffmpeg: move -stream_loop handling to the demuxer thread
Anton Khirnov [Tue, 22 Mar 2022 09:41:55 +0000 (10:41 +0100)]
fftools/ffmpeg: move -stream_loop handling to the demuxer thread

-stream_loop is currently handled by destroying the demuxer thread,
seeking, then recreating it anew. This is very messy and conflicts with
the future goal of moving each major ffmpeg component into its own
thread.

Handle -stream_loop directly in the demuxer thread. Looping requires the
demuxer to know the duration of the file, which takes into account the
duration of the last decoded audio frame (if any). Use a thread message
queue to communicate this information from the main thread to the
demuxer thread.

6 days agofftools/ffmpeg: move seek_to_start() to ffmpeg_demux.c
Anton Khirnov [Tue, 22 Mar 2022 08:58:06 +0000 (09:58 +0100)]
fftools/ffmpeg: move seek_to_start() to ffmpeg_demux.c

Reduces the diff in the following commit.

6 days agofftools/ffmpeg: move get_input_packet() to ffmpeg_demux.c
Anton Khirnov [Wed, 3 Aug 2022 12:30:48 +0000 (14:30 +0200)]
fftools/ffmpeg: move get_input_packet() to ffmpeg_demux.c

Also rename it to use the ifile_* namespace.

6 days agofftools/ffmpeg: report new streams from the input thread
Anton Khirnov [Mon, 21 Mar 2022 16:29:21 +0000 (17:29 +0100)]
fftools/ffmpeg: report new streams from the input thread

This avoids a potential race with the demuxer adding new streams. It is
also more efficient, since we no longer do inter-thread transfers of
packets that will be just discarded.

6 days agofftools/ffmpeg: handle dumping input packets in input_thread()
Anton Khirnov [Mon, 21 Mar 2022 16:12:25 +0000 (17:12 +0100)]
fftools/ffmpeg: handle dumping input packets in input_thread()

This is a more appropriate place for this.

6 days agofftools/ffmpeg: drop the 'h' key handling
Anton Khirnov [Mon, 21 Mar 2022 16:05:44 +0000 (17:05 +0100)]
fftools/ffmpeg: drop the 'h' key handling

This undocumented feature runtime-enables dumping input packets. I can
think of no reasonable real-world use case that cannot also be
accomplished in a different way. Keeping this functionality would
interfere with the following commit moving it to the input thread (then
setting the variable would require locking or atomics, which would be
unnecessarily complicated for a feature that probably nobody uses).

6 days agofftools/ffmpeg: move the input thread into its own file
Anton Khirnov [Wed, 3 Aug 2022 12:08:44 +0000 (14:08 +0200)]
fftools/ffmpeg: move the input thread into its own file

It will contain more demuxing-specific code in the future.

6 days agofftools/ffmpeg: drop a write-only variable
Anton Khirnov [Mon, 21 Mar 2022 15:51:13 +0000 (16:51 +0100)]
fftools/ffmpeg: drop a write-only variable

6 days agofftools/ffmpeg: always read input in a thread
Anton Khirnov [Mon, 21 Mar 2022 14:53:38 +0000 (15:53 +0100)]
fftools/ffmpeg: always read input in a thread

This will be required by the following architecture changes.

6 days agofftools/ffmpeg: store the input file index in InputFile
Anton Khirnov [Mon, 21 Mar 2022 16:21:46 +0000 (17:21 +0100)]
fftools/ffmpeg: store the input file index in InputFile

Use it to simplify some code and fix two off-by-one errors.

Similar to what was previously done for OutputFile.

6 days agofftools/ffmpeg: drop a superfluous stack variable
Anton Khirnov [Mon, 21 Mar 2022 15:08:31 +0000 (16:08 +0100)]
fftools/ffmpeg: drop a superfluous stack variable

6 days agodoc/ffmpeg: update -map documentation
Anton Khirnov [Wed, 3 Aug 2022 11:02:00 +0000 (13:02 +0200)]
doc/ffmpeg: update -map documentation

Make it match reality (current text was not updated for stream
specifiers), extend and clarify the text.

6 days agofftools/ffmpeg: deprecate specifying a sync stream with -map
Anton Khirnov [Wed, 3 Aug 2022 10:02:59 +0000 (12:02 +0200)]
fftools/ffmpeg: deprecate specifying a sync stream with -map

It has not had any effect whatsoever for over 10 years.

6 days agofftools/ffmpeg: remove OutputStream.sync_ist
Anton Khirnov [Wed, 3 Aug 2022 09:54:08 +0000 (11:54 +0200)]
fftools/ffmpeg: remove OutputStream.sync_ist

It is not actually used for anything.

6 days agofftools/ffmpeg: remove OutputStream.encoding_needed
Anton Khirnov [Wed, 3 Aug 2022 09:32:10 +0000 (11:32 +0200)]
fftools/ffmpeg: remove OutputStream.encoding_needed

It is unnecessary, as it is always exactly equivalent to !!ost->enc_ctx

6 days agofftools/ffmpeg: remove OutputStream.stream_copy
Anton Khirnov [Wed, 3 Aug 2022 09:32:10 +0000 (11:32 +0200)]
fftools/ffmpeg: remove OutputStream.stream_copy

There are currently three possible modes for an output stream:
1) The stream is produced by encoding output from some filtergraph. This
   is true when ost->enc_ctx != NULL, or equivalently when
   ost->encoding_needed != 0.
2) The stream is produced by copying some input stream's packets. This
   is true when ost->enc_ctx == NULL && ost->source_index >= 0.
3) The stream is produced by attaching some file directly. This is true
   when ost->enc_ctx == NULL && ost->source_index < 0.

OutputStream.stream_copy is currently used to identify case 2), and
sometimes to confusingly (or even incorrectly) identify case 1). Remove
it, replacing its usage with checking enc_ctx/source_index values.

6 days agofftools/ffmpeg_opt: drop redundant decoder selection
Anton Khirnov [Wed, 3 Aug 2022 08:30:54 +0000 (10:30 +0200)]
fftools/ffmpeg_opt: drop redundant decoder selection

A decoder is already selected above, in choose_decoder().

6 days agofftools/ffmpeg: stop accessing the decoder context unnecessarily
Anton Khirnov [Mon, 20 Jun 2022 08:16:47 +0000 (10:16 +0200)]
fftools/ffmpeg: stop accessing the decoder context unnecessarily

The same information is available from AVStream.codecpar. This will
allow to stop allocating a decoder unless decoding is actually
performed.

6 days agofftools/ffmpeg_hw: stop logging to the decoder context
Anton Khirnov [Tue, 2 Aug 2022 09:08:09 +0000 (11:08 +0200)]
fftools/ffmpeg_hw: stop logging to the decoder context

Only the decoder itself should do that. Use NULL as is done by all other
logging code in ffmpeg.

6 days agofftools/ffmpeg_opt: move adding metadata out of open_output_file()
Anton Khirnov [Wed, 3 Aug 2022 08:47:21 +0000 (10:47 +0200)]
fftools/ffmpeg_opt: move adding metadata out of open_output_file()

6 days agofftools/ffmpeg_opt: move adding programs out of open_output_file()
Anton Khirnov [Wed, 3 Aug 2022 08:47:21 +0000 (10:47 +0200)]
fftools/ffmpeg_opt: move adding programs out of open_output_file()

6 days agofftools/ffmpeg_opt: move adding attachments out of open_output_file()
Anton Khirnov [Wed, 3 Aug 2022 08:47:21 +0000 (10:47 +0200)]
fftools/ffmpeg_opt: move adding attachments out of open_output_file()

6 days agoavformat/movenc: Remove experimental status of flac-in-MP4 muxing
Martijn van Beurden [Sat, 6 Aug 2022 08:39:42 +0000 (10:39 +0200)]
avformat/movenc: Remove experimental status of flac-in-MP4 muxing

The fLaC and dfLa box IDs have been registered with the MP4 RA
(they are now listed at https://mp4ra.org/#/codecs) and support
for muxing FLAC in MP4 has been experimental in ffmpeg for
6 years now, since Nov 21, 2016

This patch removes the experimental status and removes the MP4
object type, as none has been registered for FLAC as it was not
deemed necessary.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
6 days agoavformat: allow .ec3 as extension for raw E-AC-3 stream
Ruben Gonzalez [Thu, 23 Jun 2022 12:14:36 +0000 (14:14 +0200)]
avformat: allow .ec3 as extension for raw E-AC-3 stream

In addition to .eac3, .ec3 is also commonly used by people to name raw
E-AC-3 streams. Enables automatic recognition of the eac3 format for
the .ac3 extension.

For instance Dolby Digital Plus software only support files with
.ec3. Files with .eac3 are not supported. Check issue #18 in the
public dlb_mp4base repository from DolbyLaboratories.

Signed-off-by: Ruben Gonzalez <rgonzalez@fluendo.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
6 days agoswscale/output: fix reading chroma values when generating vuya output
James Almer [Mon, 8 Aug 2022 12:24:46 +0000 (09:24 -0300)]
swscale/output: fix reading chroma values when generating vuya output

Signed-off-by: James Almer <jamrial@gmail.com>
6 days agoavcodec/nvdec: Use av_buffer_replace() where appropriate
Andreas Rheinhardt [Sat, 6 Aug 2022 07:18:29 +0000 (09:18 +0200)]
avcodec/nvdec: Use av_buffer_replace() where appropriate

Reviewed-by: Timo Rothenpieler <timo@rothenpieler.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
6 days agoavcodec/nvdec: Check av_buffer_ref()
Andreas Rheinhardt [Sat, 6 Aug 2022 07:14:11 +0000 (09:14 +0200)]
avcodec/nvdec: Check av_buffer_ref()

It (unfortunately) involves an allocation and can therefore fail.

Reviewed-by: Timo Rothenpieler <timo@rothenpieler.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
6 days agoavcodec/libspeexdec: Fix use of uninitialized value
Andreas Rheinhardt [Sat, 6 Aug 2022 18:07:02 +0000 (20:07 +0200)]
avcodec/libspeexdec: Fix use of uninitialized value

Regression since 97d9a3293854eda84f05c22e2eaefae7406ac969.
Fixes Coverity issue #1503072.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
6 days agoavcodec/cbs_h2645: Remove always-false check
Andreas Rheinhardt [Thu, 4 Aug 2022 09:39:14 +0000 (11:39 +0200)]
avcodec/cbs_h2645: Remove always-false check

The functions to replace parameter sets are only called
after the respective parameter set has just been read or
has just been written; all of these functions check
that the id field is within the appropriate range.
So the checks in the replace-functions can be removed.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
6 days agoavcodec/cbs: Remove ff_cbs_alloc_unit_content
Andreas Rheinhardt [Thu, 4 Aug 2022 09:31:18 +0000 (11:31 +0200)]
avcodec/cbs: Remove ff_cbs_alloc_unit_content

It is no longer used.
Also rename ff_cbs_alloc_unit_content2 to ff_cbs_alloc_unit_content.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
6 days agoavcodec/cbs_jpeg: Use table-based alloc/free
Andreas Rheinhardt [Thu, 4 Aug 2022 09:23:01 +0000 (11:23 +0200)]
avcodec/cbs_jpeg: Use table-based alloc/free

cbs_jpeg was the last user of CBS that didn't use
CodedBitstreamUnitTypeDescriptors.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
6 days agoavcodec/cbs_internal: Use unions to shrink size of descriptors
Andreas Rheinhardt [Thu, 4 Aug 2022 09:02:14 +0000 (11:02 +0200)]
avcodec/cbs_internal: Use unions to shrink size of descriptors

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
6 days agoavcodec/cbs_internal, cbs_h2645: Add and use new descriptor macros
Andreas Rheinhardt [Thu, 4 Aug 2022 08:49:50 +0000 (10:49 +0200)]
avcodec/cbs_internal, cbs_h2645: Add and use new descriptor macros

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
6 days agoavcodec/cbs: Use smaller scope for variables, add const
Andreas Rheinhardt [Thu, 4 Aug 2022 05:19:29 +0000 (07:19 +0200)]
avcodec/cbs: Use smaller scope for variables, add const

And also avoid an unnecessary indirection for src_buf.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
6 days agoavcodec/cbs: Remove redundant assignment
Andreas Rheinhardt [Thu, 4 Aug 2022 04:55:46 +0000 (06:55 +0200)]
avcodec/cbs: Remove redundant assignment

The code just creates new references without allocating
new buffers for the subobjects; therefore the actual data pointer
stays valid and need not be updated.

Also remove an assert that ensured that the calculation
for updating the pointer makes sense.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
6 days agoavcodec/cbs: Avoid code duplication for making unit refcounted/writable
Andreas Rheinhardt [Thu, 4 Aug 2022 04:52:55 +0000 (06:52 +0200)]
avcodec/cbs: Avoid code duplication for making unit refcounted/writable

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
6 days agoavcodec/error_resilience: Avoid overhead of AVBuffer API
Andreas Rheinhardt [Thu, 4 Aug 2022 16:26:56 +0000 (18:26 +0200)]
avcodec/error_resilience: Avoid overhead of AVBuffer API

These buffers are not shared in any way.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
6 days agoavutil/hwcontext_videotoolbox: add missing include for AVFrame
Zhao Zhili [Thu, 4 Aug 2022 10:48:48 +0000 (18:48 +0800)]
avutil/hwcontext_videotoolbox: add missing include for AVFrame

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
6 days agoavformat/avisynth: cosmetics after nb_channels change
Stephen Hutchinson [Mon, 8 Aug 2022 01:25:32 +0000 (21:25 -0400)]
avformat/avisynth: cosmetics after nb_channels change

Signed-off-by: James Almer <jamrial@gmail.com>
6 days agoavformat/avisynth: use ch_layout.nb_channels for channel count
Stephen Hutchinson [Mon, 8 Aug 2022 01:25:31 +0000 (21:25 -0400)]
avformat/avisynth: use ch_layout.nb_channels for channel count

Fixes deprecation warning

Signed-off-by: James Almer <jamrial@gmail.com>