1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-12 19:18:44 +02:00
Commit Graph

282 Commits

Author SHA1 Message Date
Timo Rothenpieler
9a2171318d avcodec/nvenc: fix signedness of timing fields 2024-08-03 20:04:31 +02:00
Zhao Zhili
670ff6c7ce avcodec/nvenc: rework on DTS generation
Before the patch, the method to generate DTS only works with
timebase equal to 1/fps. With timebase like 1/1000

./ffmpeg -i foo.mp4 -an -c:v h264_nvenc -enc_time_base 1/1000 bar.mp4

pts 0    dts -3
pts 160  dts 37
pts 80   dts 77
pts 40   dts 117 <-- invalid
pts 120  dts 157
pts 320  dts 197
pts 240  dts 237
pts 200  dts 277 <-- invalid
pts 280  dts 317 <-- invalid

The generated DTS can be larger than PTS, since it only reorder the
input PTS and minus the number of frame delay, which doesn't take
timebase into account. It should minus the "time" of frame delay.

9a245bd trying to fix the issue, but the implementation is incomplete,
which only use time_base.num. Then it got reverted by ac7c265b33.

After this patch:

pts 0    dts -120
pts 160  dts -80
pts 80   dts -40
pts 40   dts 0
pts 120  dts 40
pts 320  dts 80
pts 240  dts 120
pts 200  dts 160
pts 280  dts 200

Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
2024-08-02 17:57:19 +02:00
Josh Allmann
c9151ea507 avcodec/nvenc: fix segfault in intra-only mode
In intra-only mode, frameIntervalP is 0, which means the frame
data array is smaller than the number of surfaces.

Together with using the wrong size on deallocation of the
frame_data_array, this lead to a crash.

Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
2024-07-01 19:59:01 +02:00
Anton Khirnov
e4601cc339 lavc/hevc*: move to hevc/ subdir 2024-06-04 11:46:27 +02:00
Diego Felix de Souza
9d675bb60d avcodec/nvenc: add high bit depth encoding for HEVC
Adding 10-bit encoding support for HEVC if the input is 8-bit. In
case of 8-bit input content, NVENC performs an internal CUDA 8 to
10-bit conversion of the input prior to encoding. Currently, only
AV1 supports encoding 8-bit content as 10-bit.

Signed-off-by: Diego Felix de Souza <ddesouza@nvidia.com>
Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
2024-04-25 00:33:13 +02:00
Diego Felix de Souza
1f265aa91d avcodec/nvenc: Multi NVENC Split Frame Encoding in HEVC and AV1
When Split frame encoding is enabled, each input frame is partitioned into
horizontal strips which are encoded independently and simultaneously by
separate NVENCs, usually resulting in increased encoding speed compared to
single NVENC encoding.

Signed-off-by: Diego Felix de Souza <ddesouza@nvidia.com>
Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
2024-04-13 18:00:43 +02:00
Timo Rothenpieler
271a0a55bc avcodec/nvenc: provide nvenc with monotonic frame index 2024-04-01 00:46:12 +02:00
Timo Rothenpieler
c06e9e289f avcodec/nvenc: update minimum driver version list 2024-03-31 21:43:38 +02:00
Timo Rothenpieler
21b4708969 avcodec/nvenc: add support for unidirectional b-frames 2024-03-31 21:32:55 +02:00
Timo Rothenpieler
77d23bcb1b avcodec/nvenc: add support for lookahead_level 2024-03-31 20:58:27 +02:00
Timo Rothenpieler
64e3fc9069 avcodec/nvenc: add support for HEVC temporal filtering 2024-03-31 20:47:59 +02:00
Timo Rothenpieler
06c2a2c425 avcodec/nvenc: support SDK 12.2 bit depth API 2024-03-31 19:10:49 +02:00
Timo Rothenpieler
43b417d516 avcodec/nvenc: stop using long deprecated format specifiers 2024-03-31 19:10:49 +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
Timo Rothenpieler
e006680d8e avcodec/nvenc: add option to control subsampling of packed rgb input 2023-10-09 20:17:44 +02:00
Andreas Rheinhardt
f58038d498 avcodec/avcodec: Avoid codec_desc.h, codec_par.h inclusions
Instead, use forward declarations; and in order not to affect
any user include these headers for them, but not internally.
This has the advantage of removing implicit inclusions of these
headers from almost all files providing codecs.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-03 01:59:07 +02:00
Andreas Rheinhardt
423b6a7e49 avutil/imgutils: Add wrapper for av_image_copy() to avoid casts
av_image_copy() accepts const uint8_t* const * as source;
lots of user have uint8_t* const * and therefore either
cast (the majority) or copy the array of pointers.

This commit changes this by adding a static inline wrapper
for av_image_copy() that casts between the two types
so that we do not need to add casts everywhere else.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-09-12 09:42:27 +02:00
Andreas Rheinhardt
8238bc0b5e avcodec/defs: Add AV_PROFILE_* defines, deprecate FF_PROFILE_* defines
These defines are also used in other contexts than just AVCodecContext
ones, e.g. in libavformat. Furthermore, given that these defines are
public, the AV-prefix is the right one, so deprecate (and not just move)
the FF-macros.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-09-07 00:39:02 +02: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
Aleksoid
7eb0d9e905 avcodec/nvenc: add option to limit slice size 2023-08-22 23:46:11 +02:00
Andreas Rheinhardt
2d7c1479c2 avcodec/nvenc: Remove always-true check
nvenc_store_frame_data() is always called with frame != NULL
(checked at the beginning of nvenc_send_frame());
in fact, frame is dereferenced unconditionally after the block
guarded by the check for frame. Therefore Coverity complains
about this in issue #1538295.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-08-02 18:31:59 +02:00
Zhao Zhili
7eeef72c67 avcodec/nvenc: set idrPeriod to gopLength unconditionally
When intra_refresh is enabled, gopLength is equal to
NVENC_INFINITE_GOPLENGTH. gopLength should be 1 at least.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-07-07 13:39:26 +02:00
Zhao Zhili
0d0c39832f avcodec/nvenc: fix intraRefreshPeriod setting
Regression since 99dfdb45. intraRefreshPeriod access cc->gopLength,
which has been overwritten to NVENC_INFINITE_GOPLENGTH before.

Fixes #10445.
2023-07-07 13:39:26 +02:00
Ricardo Monteiro
99dfdb45a8 avcodec/nvenc: let preset decide default gop size
Default GOP size is now set by preset and tuning info. This GOP size is only overwriten if -g value is provided.

Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
2023-06-22 19:33:09 +02:00
Timo Rothenpieler
16fdb48e0d avcodec/nvenc: handle frame durations and AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE 2023-06-16 22:10:42 +02:00
Timo Rothenpieler
6c418ae25e Revert "lavc/nvenc: handle frame durations and AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE"
The implementation is flawed in that the frame opaque data is not in
fact correctly reordered along with the packets, but is being output in
packet input order, just like the dts are.

This reverts commit 3553809703.
2023-06-16 22:10:42 +02:00
Timo Rothenpieler
ac7c265b33 Revert "avcodec/nvenc: fix b-frame DTS behavior with fractional framerates"
This reverts commit 9a245bdf5d.

This commit basically broke all samples with fractional framerates,
rather than fixing them.
I at this point do not understand the original issue anymore, and I'm
not sure how this slipped my initial testing.
All my test samples must have happened to have a simple timebase.

The actual dts values pretty much always are just a simple chain of
1,2,3,4,5,... Or maybe slightly bigger steps. Each increase by one means
an advance in time by one unit of the timebase.
So a fractional framerate/timebase is already not an issue.

So with this patch applied, the calculation might end up substracting
huge values (1001 is a common one) from the dts, which would be an
offset of that many frames, not of that many fractions of a second.
This broke at least muxing into mp4, if the sample happened to have a
fractional framerate.

I do not thing the original issue this patch tried to fix existed in the
first place, so it can be reverted without further consequences.
2023-06-15 00:59:02 +02:00
Timo Rothenpieler
d2b46c1ef7 avcodec/nvenc: stop using deprecated rc modes with SDK 12.1 2023-06-01 23:47:14 +02: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
James Almer
2f561ba953 avcodec: use the new AVFrame interlace flags in all decoders and encoders
Signed-off-by: James Almer <jamrial@gmail.com>
2023-05-04 18:14:02 -03:00
Kyle Manning
9a245bdf5d avcodec/nvenc: fix b-frame DTS behavior with fractional framerates
When using fractional framerates (or any fraction with a numerator != 1),
DTS values for packets would be calculated incorrectly.

Signed-off-by: Kyle Manning <tt2468@irltoolkit.com>
Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
2023-04-03 11:59:36 +02:00
Timo Rothenpieler
7a8560cb22 avcodec/nvenc: avoid failing b_ref_mode check when unset 2023-03-10 13:17:21 +01:00
Zhao Zhili
21101d9eb1 avcodec/nvenc: fix potential NULL pointer dereference
Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
2023-02-28 19:16:52 +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
3553809703 lavc/nvenc: handle frame durations and AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE 2023-01-29 09:23:17 +01:00
Timo Rothenpieler
9ca139b2aa avcodec/nvenc: fix vbv buffer size in cq mode
The CQ calculation gets thrown off and behaves very nonsensical
if it isn't set to 0.
2022-12-08 12:31:02 +01:00
Timo Rothenpieler
45216e33e2 avcodec/nvenc: notify users about rc_lookahead clipping 2022-12-05 21:21:41 +01:00
Timo Rothenpieler
ac0f42d893 avcodec/nvenc: explicitly disable lookahead if lacking sufficient surfaces
It could already be enabled by the preset, so it needs explicitly
disabled in this case.
2022-12-05 21:21:41 +01:00
Timo Rothenpieler
eb1e359a14 avcodec/nvenc: use provided constant for max extradata size 2022-11-15 01:32:56 +01:00
Timo Rothenpieler
c7a60124e3 avcodec/nvenc: add forgotten X2RGB10 formats to 10-bit-list 2022-11-14 23:10:20 +01:00
Timo Rothenpieler
939273d3b4 avcodec/nvenc: remove unsupported AV1 High Profile 2022-11-10 15:26:43 +01:00
Timo Rothenpieler
e7fbdda64e avcodec/nvenc: fix AV1 darWidth/Height calculation
nvenc uses the darWidth/Height fields for the AV1 render_width/height
instead, so a different calculation is needed.
2022-11-10 14:51:31 +01:00
Timo Rothenpieler
aa3d98227e avcodec/nvenc: don't queue and offset dts for AV1
dts != pts is actually a spec violation for AV1, given it has no
reordering in the classical sense.

We don't really need the whole timestamp queue in this case and can just
pass through the timestamp as is for both dts and pts.
2022-11-06 00:53:02 +01:00
Timo Rothenpieler
6362b8cd19 avcodec/nvenc: set correct "sei" payload type for AV1 2022-11-05 21:18:36 +01:00
Timo Rothenpieler
5c288a44ad avcodec/nvenc: add AV1 encoding support
The encoder seems to be trading blows with hevc_nvenc.
In terms of quality at low bitrate cbr settings, it seems to
outperform it even. It produces fewer artifacts and the ones it
does produce are less jarring to my perception.

At higher bitrates I had a hard time finding differences between
the two encoders in terms of subjective visual quality.

Using the 'slow' preset, av1_nvenc outperformed hevc_nvenc in terms
of encoding speed by 75% to 100% while performing above tests.

Needless to say, it always massively outperformed h264_nvenc in terms
of quality for a given bitrate, while also being slightly faster.
2022-11-05 21:17:37 +01:00
Timo Rothenpieler
28680e2f41 avcodec/nvenc: only set b_ref_mode when explicitly requested 2022-11-05 18:35:33 +01:00
Timo Rothenpieler
12733c0cbd avcodec/nvenc: remove unused slice offset querying 2022-11-01 17:42:54 +01:00
Timo Rothenpieler
b710698790 avcodec/nvenc: hardcode color characteristics for internal RGB2YUV conversion
nvenc does not appear to use these values as inputs for its built in RGB
to YUV conversion, but instead sets them on the output as-is.

Testing indicates the input is expected to be sRGB, with the output
ending up as limited range bt.470.
2022-08-06 22:23:33 +02:00
Timo Rothenpieler
85bc6b5abf avcodec/nvenc: add support for additional (10 bit) RGB pixel formats 2022-07-05 18:27:37 +02:00
Martin Storsjö
a78f136f3f configure: Use a separate config_components.h header for $ALL_COMPONENTS
This avoids unnecessary rebuilds of most source files if only the
list of enabled components has changed, but not the other properties
of the build, set in config.h.

Signed-off-by: Martin Storsjö <martin@martin.st>
2022-03-16 14:12:49 +02:00