Commit Graph

140 Commits

Author SHA1 Message Date
Niklas Haas 39ca87ed1e avcodec/libx265: implement dolby vision coding
libx265 supports these natively, we just need to attach the generated
NALs to the x265picture, as well as setting the appropriate DV profile.
2024-04-22 12:17:56 +02:00
Jan Ekström 16128f3c55 avcodec/libx265: do not arbitrarily limit color values
Newer specifications such as H.273 have, and probably will further
in the future add new values to these, so - instead of trying to update
these limits - we should simply check if the values are not set to the
value of "unspecified".

This should allow newer avutil values such as IPT-C2 or YCgCo-R
variants be passed to x265 itself, which apparently does its own
validation further down the line.
2024-04-03 21:31:35 +03:00
Andreas Rheinhardt 790f793844 avutil/common: Don't auto-include mem.h
There are lots of files that don't need it: The number of object
files that actually need it went down from 2011 to 884 here.

Keep it for external users in order to not cause breakages.

Also improve the other headers a bit while just at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-31 00:08:43 +01:00
Andreas Rheinhardt b7bec5d3c9 avutil/frame: Rename av_frame_side_data_get and add wrapper for it
av_frame_side_data_get() has a const AVFrameSideData * const *sd
parameter; so calling it with an AVFramesSideData **sd like
AVCodecContext.decoded_side_data (or with a AVFramesSideData * const
*sd) is safe, but the conversion is not performed automatically
in C. All users of this function therefore resort to a cast.

This commit changes this: av_frame_side_data_get() is renamed
to av_frame_side_data_get_c(); furthermore, a static inline
wrapper for it name av_frame_side_data_get() is added
that accepts an AVFramesSideData * const * and converts this
to const AVFramesSideData * const * in a Wcast-qual safe way.

This also allows to remove the casts from the current users.

Reviewed-by: Jan Ekström <jeebjp@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-22 23:38:16 +01:00
Andreas Rheinhardt b9fcc135c5 avcodec/libx265: Pass logctx as void*, not AVClass**
The latter need not be save, because av_log() expects
to get a pointer to an AVClass-enabled structure
and not only a fake object. If this function were actually
be called in the following way:

const AVClass *avcl = avctx->av_class;
handle_mdcv(&avcl, );

the AVClass's item_name would expect to point to an actual
AVCodecContext, potentially leading to a segfault.

Reviewed-by: Jan Ekström <jeebjp@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-22 23:32:15 +01:00
Andreas Rheinhardt 244db71037 avcodec/libx265: Don't use AVBPrint unnecessarily
This code uses the AVBPrint API for exactly one av_bprintf()
in a scenario in which a good upper bound for the needed
size of the buffer is available (with said upper bound being
much smaller than sizeof(AVBPrint)). So one can simply use
snprintf() instead. This also avoids the (always-false due to
the current size of the internal AVBPrint buffer) check for
whether the AVBPrint is complete.

Furthermore, the old code used AV_BPRINT_SIZE_AUTOMATIC
which implies that the AVBPrint buffer will never be
(re)allocated and yet it used av_bprint_finalize().
This has of course also been removed.

Reviewed-by: Jan Ekström <jeebjp@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-22 23:31:58 +01:00
Jan Ekström d7d2213a6b avcodec/libx265: add support for writing out CLL and MDCV
The newer of these two are the separate integers for content light
level, introduced in 3952bf3e98c76c31594529a3fe34e056d3e3e2ea ,
with X265_BUILD 75. As we already require X265_BUILD of at least
89, no further conditions are required.
2024-03-20 19:15:05 +02:00
James Almer 67e7f0b05e avutil: remove deprecated FF_API_REORDERED_OPAQUE
Signed-off-by: James Almer <jamrial@gmail.com>
2024-03-07 08:53:30 -03:00
Anton Khirnov 08bebeb1be Revert "all: Don't set AVClass.item_name to its default value"
Some callers assume that item_name is always set, so this may be
considered an API break.

This reverts commit 0c6203c97a.
2024-01-20 10:34:48 +01:00
Andreas Rheinhardt 0c6203c97a 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>
2023-12-22 15:12:33 +01:00
James Almer 0231df505d avcodec/utils: move ff_add_cpb_side_data() to encoder code
It's only used by encoders, so move it to prevent wrong usage.

Signed-off-by: James Almer <jamrial@gmail.com>
2023-09-06 10:27:45 -03:00
Anton Khirnov 7d1d61cc5f lavc: deprecate AVCodecContext.ticks_per_frame
For encoding, this field is entirely redundant with
AVCodecContext.framerate.

For decoding, this field is entirely redundant with
AV_CODEC_PROP_FIELDS.
2023-05-15 10:56:18 +02:00
Marton Balint eee6492df7 avcodec/libx265: fix else clause when zeroing reordered_opaque
CC	libavcodec/libx265.o
libavcodec/libx265.c: In function ‘libx265_encode_frame’:
libavcodec/libx265.c:781:5: warning: this ‘else’ clause does not guard... [-Wmisleading-indentation]
     else
     ^~~~
libavcodec/libx265.c:782:1: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘else’
 FF_DISABLE_DEPRECATION_WARNINGS
 ^~~

Signed-off-by: Marton Balint <cus@passwd.hu>
2023-02-16 00:52:30 +01:00
Anton Khirnov bdc76f467f lavu/frame: deprecate reordered_opaque
It is only used in libavcodec, where it's been superseded by
AV_CODEC_CAP_COPY_OPAQUE.
2023-02-04 13:40:20 +01:00
Anton Khirnov d87055107d lavc/libx265: pass through frame durations to encoded packets 2023-01-29 09:23:17 +01:00
Anton Khirnov 5c0348f3d6 lavc: add a codec flag for propagating opaque from frames to packets
This is intended to be a more convenient replacement for
reordered_opaque.

Add support for it in the two encoders that offer
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE: libx264 and libx265. Other
encoders will be supported in future commits.
2023-01-29 09:18:14 +01:00
Anton Khirnov a0b5aaceca lavc/libx265: restructure handling reordered_opaque
Current code stores a pointer to allocated data in libx265 and frees it
when the encoded packet is retrieved. This will leak if the packet is
never retrieved, e.g. if the encoder is closed without being flushed.

Restructure the code such that only indices to an array stored in our
private data are given to libx265. This ensures no allocated memory can
be lost.
2023-01-04 11:48:17 +01:00
Zhao Zhili 36a8d1e729 avcodec/libx265: fix build error
x265_sei is available since X265_BUILD 88. Bump required version
to 89 to fix the regression from commit 1f58503013, and remove a
conditional compilation.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2022-11-18 23:18:21 +08:00
erankor 6043352bd9 libx265: support ATSC A/53 captions
added a new option 'a53cc' (on by default, as in libx264) for rendering
AV_FRAME_DATA_A53_CC as hevc sei payloads.
the code is a blend of the libx265.c code for writing
AV_FRAME_DATA_SEI_UNREGISTERED with the libx264.c code for writing atsc
a/53 payloads.
2022-11-10 16:28:07 +01:00
Andreas Rheinhardt 48286d4d98 avcodec/codec_internal: Add macro to set AVCodec.long_name
It reduces typing: Before this patch, there were 105 codecs
whose long_name-definition exceeded the 80 char line length
limit. Now there are only nine of them.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-09-03 15:42:57 +02:00
Andreas Rheinhardt 6aad1204cc avcodec: Add FF_CODEC_CAP_NOT_INIT_THREADSAFE
This is in preparation of switching the default init-thread-safety
to a codec being init-thread-safe.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-18 19:58:56 +02:00
Jan Ekström 49027e7612 avcodec/libx265: make X265 CSP selection pixel format independent
Currently the format listing misses the J formats completely, yet
they are marked as supported in the encoder. Thus to make the logic
support them while not explicitly listing them, make the logic
utilize chroma subsampling information in both width and height
available through the pixel format descriptor.
2022-06-27 09:25:22 +03:00
Andreas Rheinhardt 4243da4ff4 avcodec/codec_internal: Use union for FFCodec decode/encode callbacks
This is possible, because every given FFCodec has to implement
exactly one of these. Doing so decreases sizeof(FFCodec) and
therefore decreases the size of the binary.
Notice that in case of position-independent code the decrease
is in .data.rel.ro, so that this translates to decreased
memory consumption.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-04-05 20:02:37 +02:00
Andreas Rheinhardt 5aabb2596f avcodec/codec_internal: Rename AVCodecDefault->FFCodecDefault
This structure is no longer declared in a public header,
so using an FF-prefix is more appropriate.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-03-21 01:33:10 +01:00
Andreas Rheinhardt 20f9727018 avcodec/codec_internal: Add FFCodec, hide internal part of AVCodec
Up until now, codec.h contains both public and private parts
of AVCodec. This exposes the internals of AVCodec to users
and leads them into the temptation of actually using them
and forces us to forward-declare structures and types that
users can't use at all.

This commit changes this by adding a new structure FFCodec to
codec_internal.h that extends AVCodec, i.e. contains the public
AVCodec as first member; the private fields of AVCodec are moved
to this structure, leaving codec.h clean.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-03-21 01:33:09 +01:00
Andreas Rheinhardt a688f3c13c avcodec/internal: Move FF_CODEC_CAP_* to a new header codec_internal.h
Also move FF_CODEC_TAGS_END as well as struct AVCodecDefault.
This reduces the amount of files that have to include internal.h
(which comes with quite a lot of indirect inclusions), as e.g.
most encoders don't need it. It is furthemore in preparation
for moving the private part of AVCodec out of the public codec.h.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-03-21 01:33:09 +01:00
Limin Wang 63d5b6f935 avcodec/libx26[45]: reindent after last commit
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2021-12-28 14:19:38 +08:00
Limin Wang 7dfc3cc713 avcodec/libx26[45]: add udu_sei option to import user data unregistered SEIs
Most of user data unregistered SEIs are privated data which defined by user/
encoder. currently, the user data unregistered SEIs found in input are forwarded
as side-data to encoders directly, it'll cause the reencoded output including some
useless UDU SEIs.

I prefer to add one option to enable/disable it and default is off after I saw
the patch by Andreas Rheinhardt:

https://patchwork.ffmpeg.org/project/ffmpeg/patch/AM7PR03MB66607C2DB65E1AD49D975CF18F7B9@AM7PR03MB6660.eurprd03.prod.outlook.com/

How to test by cli:
ffmpeg -y -f lavfi -i testsrc -c:v libx264 -frames:v 1 a.ts
ffmpeg -y -i a.ts -c:v libx264 -udu_sei 1 b.ts
ffmpeg -y -i a.ts -c:v libx264 -udu_sei 0 c.ts

# check the user data unregistered SEIs, you'll see two UDU SEIs for b.ts.
# and mediainfo will show with wrong encoding setting info
ffmpeg -i b.ts -vf showinfo -f null -
ffmpeg -i c.ts -vf showinfo -f null -

This fixes tickets #9500 and #9557.

Reviewed-by: "zhilizhao(赵志立)" <quinkblack@foxmail.com>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2021-12-28 14:19:38 +08:00
Andreas Rheinhardt 1ea3650823 Replace all occurences of av_mallocz_array() by av_calloc()
They do the same.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-20 01:03:52 +02:00
Jan Ekström 9b2281a4a3 avcodec/libx265: add support for setting chroma sample location
Unlike libx264, libx265 does not handle the chroma format check
on its own side, so in order to not write out values which are
supposed to be ignored according to the specification, we limit
the writing out of chroma sample location to 4:2:0 only.
2021-09-01 23:27:19 +03:00
Jan Ekström 06ce821bc7 avcodec/libx265: only call av_pix_fmt_desc_get once in init
Now both current usages utilize an already found descriptor.
2021-08-29 21:09:21 +03:00
Jan Ekström dbe40478e2 avcodec/libx265: improve full range flag setting logic
Unlike libx264, libx265 does not have a separate "unspecified"/"auto"
default for color range, so we do always have to specify it.
Thus, we are required to handle the RGB case on the libavcodec
side to enable the correct value to be written out in in case
of RGB content with unspecified color range being received.

In other words:
1. If the user has set color range specifically, follow that.
2. If the user has not set color range specifically, set full
   range by default in case of RGB and YUVJ pixel formats.
2021-08-18 12:09:37 +03:00
Brad Hards 1f58503013 libavcodec/libx265: add user data unregistered SEI encoding
MISB ST 0604 and ST 2101 require user data unregistered SEI messages
(precision timestamps and sensor identifiers) to be included. That
currently isn't supported for libx265. This patch adds support
for user data unregistered SEI messages in accordance with
ISO/IEC 23008-2:2020 Section D.2.7

The design is based on nvenc, with support finished up at
57de80673c

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2021-08-01 12:07:54 +01:00
Andreas Rheinhardt a4b3343278 avcodec/libx265: Allow user-supplied buffers
Here the packet size is known before allocating the packet,
so that supporting user-supplied buffers is trivial.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-05-23 14:59:15 +02:00
Andreas Rheinhardt 11bc790893 avcodec: Remove deprecated AVCodecContext.coded_frame
Deprecated in 40cf1bbacc.
(The currently disabled filter vf_mcdeint and vf_uspp were users of
this field; they have not been changed, so that whoever wants to fix
them can see the state of these filters when they were disabled.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:12 -03:00
Anton Khirnov 7d09579190 lavc: rename AV_CODEC_CAP_AUTO_THREADS->AV_CODEC_CAP_OTHER_THREADS
This cap is currently used to mark multithreading-capable codecs that
wrap external libraries with their own multithreading code. The name is
highly confusing for our API users, since libavcodec ALWAYS handles
thread_count=0 (see commit message in previous commit). Therefore rename
the cap and update its documentation to make its meaning clear.

The old name is kept deprecated until next+1 major bump.
2021-03-16 10:38:41 +01:00
Anton Khirnov 8a129077cc lavc: replace internal use of AV_CODEC_CAP_AUTO_THREADS with an internal cap
AV_CODEC_CAP_AUTO_THREADS was originally added in b4d44a45f9 to mark
codecs that spawn threads internally and are able to select an optimal
threads count by themselves (all such codecs are wrappers around
external libraries). It is used by lavc generic code to check whether it
should handle thread_count=0 itself or pass the zero directly to the
codec implementation. Within this meaning, it is clearly supposed to be
an internal cap rather than a public one, since from the viewpoint of a
libavcodec user, lavc ALWAYS handles thread_count=0. Whether it happens
in the generic code or within the codec internals is not a meaningful
difference for the caller.

External aspects of this flag will be dealt with in the following
commit.
2021-03-16 10:34:29 +01:00
Limin Wang e3b5897fe3 avcodec/libx265: Fix integer overflow in computation of max and avg bitrate
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-06-19 07:14:46 +08:00
James Almer 6e1903938b avcodec/internal: move packet related functions to their own header
Signed-off-by: James Almer <jamrial@gmail.com>
2020-06-02 19:02:12 -03:00
James Almer 74dfc88b63 avcodec/libx265: add support for reordered_opaque
Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2020-05-19 19:12:17 -03:00
Limin Wang d8e98d9348 avcodec/libx265: Fix Uninitialized scalar variable
return error if unknown picture type encountered

Fixes CID 1457234
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-05-08 06:42:25 +08:00
James Almer 6ae84e7b03 avcodec/libx265: zero the padding bytes in extradata
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-18 12:45:59 -03:00
Marton Balint 91f64ea4c5 avcodec/libx265: use AV_OPT_TYPE_DICT for x265-params
Signed-off-by: Marton Balint <cus@passwd.hu>
2020-01-01 21:22:09 +01:00
James Almer 3670a10c2d avcodec/libx265: export encoded frame stats
Signed-off-by: James Almer <jamrial@gmail.com>
(cherry picked from commit 66b6005301894823052b437a950003ffbe3ba6de)
2020-01-01 13:50:39 -03:00
James Almer 278a91f8fe avcodec/libx265: add a qp option and apply the relevant global AVCodecContext settings to the encoder context
Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-01 13:48:02 -03:00
James Almer 3c22436ddf avcodec/libx265: apply some global AVCodecContext settings to the encoder context
There's no reason to ignore them if set.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-01 13:25:18 -03:00
Zhong Li a87b5d5e8c lavc/x265: set preferred_transfer_characteristics for HLG
"HEVC HDR UHDTV Bitstreams using HLG10 shall also contain the
alternative_transfer_characteristics SEI message. The
alternative_transfer_characteristics SEI message shall be inserted on
the HEVC DVB_RAP, and preferred_transfer_characteristics shall be set
equal to "18", indicating Recommendation ITU-R BT. 2100 [45] HLG
system."

Signed-off-by: Zhong Li <zhongli_dev@126.com>
2019-12-12 23:44:02 +08:00
Guo, Yejun 85e338ab0d libavcodec/libx265: add a flag to output ROI warnings only once.
Signed-off-by: Guo, Yejun <yejun.guo@intel.com>
2019-09-24 17:22:15 +01:00
Mark Thompson f6c572bd89 libx265: Update ROI behaviour to match documentation
Equivalent to the previous patch for libx264.
2019-07-07 19:19:26 +01:00
Derek Buitenhuis 80757bed89 avcodec/libx265: Support full range videos
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2019-05-26 12:04:46 +01:00