Commit Graph

407 Commits

Author SHA1 Message Date
Martin Pulec
09488b085e lavc check_av_opt_set: simplified
Actually all options can be passed as a c-string with av_opt_set(),
which then converts it to a correct type. So use to_string to convert
non-cstrings to std::string.
2023-08-23 14:49:26 +02:00
Martin Pulec
8db1db9d61 lavc video AMF: set default RC to CQP 2023-08-23 14:14:40 +02:00
Martin Pulec
9e996bd37d lavc video: set header insertion for av1_amf
Set to "gop" as with HEVC, for av1_amf, it is also possible to set to
"frame" (unsure if better).
2023-08-22 16:51:46 +02:00
Martin Pulec
9b25da71a2 show_encoder_help: don't double print default opt
some codecs have alread default value in the description, eg. profile
- _Set the profile (default main)_, thus it is unneeded to print the
information second times.

\+ do not print float default vals with "F" suffix because it can be a
little bit misleading, indicate the type in braces instead
2023-08-22 16:51:28 +02:00
Martin Pulec
eb88c64d3b lavc vid: show_encoder_help simplified 2023-08-22 16:51:17 +02:00
Martin Pulec
d2f8f2df8b lavc video: avoid nullptr dereference
When `--param keep-pixfmt` is used but the encoder doesn't produce a
packet (AVPacket.size == 0), nullptr dereference can occur.

fixes CID 416601
2023-08-22 08:57:56 +02:00
Martin Pulec
c57f2fc57b lavc video: read frames consecutively
Read and send the frames consecutively, even though the encoder presents
them at once (see previous commit description).
2023-08-18 12:25:33 +02:00
Martin Pulec
690244686a Compress sync tile API: fetch additional frames
Modified the API in order to fetch additional frames from compression
with iterative passing NULL pointer (similarly as for audio).

This is particularly usefull when inter-frame compression outputs 2
frames at once, which can occur when B-frames would be enabled. It,
however sometimes happen even when B-frames are disbled, eg. with
h264/hevc_mf HW encoder on AMD (AMDh265Encoder; see commit d70e2fb3c).

Please note that semantic of passing NUL frame is different in this API
to that in async API, where it works as a poison pill.
2023-08-18 11:07:57 +02:00
Martin Pulec
f035e43ac5 lavc video: store/restore metadata reliably
In case that the encoder buffers frame for whatever reason (NVENC
with delay, hevc_mf sometimes batching 2 frames /returned frames count
0,1,2,0,1,2.../) so that output frame doesn't match the currently
enqueued onei, metadata would be incorrect (currently enqueued copied
to non-matching dequeued one).
2023-08-16 16:10:48 +02:00
Martin Pulec
4f0fa9f5ab lavc video: small updates
- moved constexpr definitions to the (anonymous) namespace (allows
eg. detection of unused vars)
- do not import the whole std namespace
2023-08-14 16:06:16 +02:00
Martin Pulec
7e2d50af66 lavc video: set the preset threshold as px/sec
Set the threshold, that is used by some to select the preset, as a
constant in MPix/sec.
2023-08-14 16:06:16 +02:00
Martin Pulec
32b0f00e8f lavc video: removed explicit preset
removed explicit preset handling

Actually with current encoder set, having the preset is rather exceptional
- some codecs to not recognize the presets with any encoder, eg. MJPEG,
Other have a different keyword like "usage" (VP9). Even with eg. H.265
different encoders use different keywords ("scenario" for QSV and MF) etc.

So give up explicit handling of presets - those (or those under different
names) can be configure in codec specific configure callbacks.

There is also a change that the default preset is always set, previously
not if _preset_ was detected in cmdline params. This doesn't seem to be
a problem, however. The user-specified options are set after the
codec-specific configure callback so that it should override the default.
2023-08-14 16:06:15 +02:00
Martin Pulec
2d0d292f1b lavc video: support for MS MFT
set default values

Seting hw_encoding=1 (force) - otherwise, the API seems to be using SW
encode. Moreover, using _hevc_mf_ fails to init (at least in some setups)
while the GPU supports that so that enforcing that makes it work.
2023-08-14 16:06:15 +02:00
Martin Pulec
7c44a85996 lavc video: do not try already tried AV pixfmts
When trying to init _any_ codec (for the further use with swscale), do not
try already tried pixfmts. Plus do not print that we will try with swscale
when there is no AV pixfmt left (it is a bit misleading in the UG output).
2023-08-14 16:06:15 +02:00
Martin Pulec
aed1af1c9c lavc video: refactor SWS fallback pixfmt select
Moved trying remaining pix_fmts to a sepaarate function.
2023-08-14 16:06:15 +02:00
Martin Pulec
bde2735dbb lavc: NVENC: default rc_buf_size_factor = 1.5
Since 2022-06-18 (commit cbc548d3), dynamic rate limiter allows
overshooting one frame by the factor of 50% so we can safely set the
default factor to 1.5 now.

see also GH-114
2023-08-07 11:47:32 +02:00
Martin Pulec
10c280959b Revert "CI Linux FFmpeg: remove NVENC IDR patch"
This reverts commit e457ab87f7 but the
patch is updated to match current FFmpeg.

The FFmpeg commit that seemed to do the same (7eeef72c6) is not working
correctly because it assigns idrPeriod cc->gopLength, which was set to
NVENC_INFINITE_GOPLENGTH above in case of intra-refresh.

refer to GH-330
2023-07-24 16:23:44 +02:00
Martin Pulec
c2c7a2ddb8 lavc video: NVENC: update ver comparison
Current libavcodec version is still 60.22.100 so intra-refresh has been
disabled since e457ab8 because the version is still not strictly greater
(is equal). Using non-strict equality breaks the compilation with version
60.22.100 prior to FFmpeg commit e457ab8 (perhaps not a big deal).

refer to GH-330
2023-07-24 15:17:09 +02:00
Martin Pulec
e457ab87f7 CI Linux FFmpeg: remove NVENC IDR patch
Since the FFmpeg commit 7eeef72c6, the IDR period is set to gopLength
unconditinally even for intra-refresh mode, which is what the removed
patch did.

+ do not check if FFmpeg is patched (the macro is )
2023-07-17 11:36:01 +02:00
Martin Pulec
83842e5f4e lavc video: if user opt fails, log as err
Compared to codec options set by UltraGrid impliclty, if user-set option
fails, it is taken as an error. But the log message didn't indicate that
the option setting was actually fatal, so use error verbosity which
makes it more visual apparent.
2023-07-04 10:14:06 +02:00
Martin Pulec
769c2d04ed lavc video: qsv rc help hint
print how the available RCs can be shown
2023-07-04 10:14:06 +02:00
Martin Pulec
01a4f0e6aa lavc video: set MJPEG Q=7 by default
FFmpeg MJPEG provides quite poor quality with Q=21 which was used
before (also when not setting anything and leaving implicit MJPEG
quality setting).
2023-06-27 10:40:56 +02:00
Martin Pulec
2d29ea28c7 video lavc: print reconfigured format in debug 2023-06-13 12:19:34 +02:00
Martin Pulec
8b5673ec5c lavc video: set defaults for rav1e
This speeds up rav1e encoding from fractions of FPS to few FPS in
FullHD, but clearly the speed is lagging behind its AOM and SVT
counterparts.
2023-05-18 14:34:18 +02:00
Martin Pulec
5b750c2ff3 lavc video: prefer libaom-av1 for ARM macs
While on x86_64 is libsvtav1 still slightly ahead, on the M1 mac, the
AOM AV1 performs significantly better (2x faster).

The above holds for native builds, it actually looks like the x86_64
build running SVT AV1 on M1 mac doesn't run correctly at all - it
produces just blank picture (green as is zeroed YCbCr buffer).
2023-05-17 14:56:11 +02:00
Martin Pulec
2961fe2f44 lavc video: print used thread count and mode 2023-05-17 11:48:08 +02:00
Martin Pulec
dc89a560a9 lavc video AOM AV1: updated defaults (performance)
updated defaults so that it may be achievable to compress 1080p on M1 mac
2023-05-17 11:42:57 +02:00
Martin Pulec
7d52917a85 lavc video: print also successfully set options
+ set also custom options with check_av_opt_set (to show setting info)
2023-05-17 11:42:05 +02:00
Martin Pulec
6b291e1183 lavc video: set default realtime usage for AOM 2023-05-17 11:42:05 +02:00
Martin Pulec
50c7f33227 lavc video: missing spaces in help 2023-05-17 11:42:05 +02:00
Martin Pulec
f7e29f1d81 remove more FFmpeg compat
according to FFmpeg commit 80154b1b, the current cut-off in UG was lavc
version 57.107.100 (incl), which corresponds to lavu 55.78.100 (incl).
2023-05-05 10:25:46 +02:00
Martin Pulec
00b7ebd40e lavc H.264: use option for interlaced DCT not param
make the "[disable_]interlaced_dct" regular option
2023-04-27 15:21:18 +02:00
Martin Pulec
8dcb6808eb lavc: do not unref packet in deconfigure
+ do not allocate it ahead in _init

For HuffYUV and FFV1 this caused crash (perhaps deconfigure was run twice
for those codecs with extradata /it uses a different path than usual
codecs without that data/, leaving the AVpacket pointer nullptr after
first run).

Unreferencing should not be necessary - we are not refcounting it and
FFmpeg example (decode_video.c), which works similarly, doesn't do that,
anyways. Also av_packet_free() should unreference it according to doc.
2023-04-06 14:39:10 +02:00
Martin Pulec
df211bf948 lavc: always use default slice count
Use default slice count also for JPEG with threads==1 because it is no
longer broken with current FFmpeg code.
2023-04-06 14:20:55 +02:00
Martin Pulec
9ffeba2d38 lavc: allocate at least 4 KiB buf for compressed
When compressing very small video (16x16) with libx265, first frame is
2690 B, which is more than W*H*4 (1024) leading to a crash on assert.

steps to reproduce the fixed problem:

    uv -t testcard:size=16x16 -c libavcodec:encoder=libx265
2023-03-29 12:08:40 +02:00
Martin Pulec
d2c00ff3f8 split utils/text to string.c and text.c 2023-03-14 13:21:12 +01:00
Martin Pulec
0c731e93b8 lavcd: remove unused param warnings when no sws 2023-03-13 16:26:14 +01:00
Martin Pulec
15e0448e0d lavc: set QSV default RC VBR
seems to be performing better than CBR

refer to GH-298
2023-03-09 10:40:12 +01:00
Martin Pulec
3d7ac66c12 lavc QSV QVBR: set rc_max_rate to 115% of bit rate
The key is to set (anyhow) rc_max_rate != bit_rate, otherwise FFmpeg
triggers CBR mode. But 200% as it was set was perhaps too much.
2023-03-09 10:36:50 +01:00
Martin Pulec
6d696a782f lavc QSV QVBR: set default quality to 21
Set to DEFAULT_CQP (21) instead of DEFAULT_CQP_QSV (5000). The usable
range here seem to be in tens, not thousands as for the other constant
so set it accordingly the detail to work satisfactorily when the quality
(cqp) parameter is not given explicitly.
2023-03-08 12:30:30 +01:00
Martin Pulec
e0df14ca35 lavc qsv: added QVBR RC 2023-03-08 12:00:01 +01:00
Martin Pulec
7993f04e8c lavc qsv: added ICQ RC 2023-03-08 11:39:57 +01:00
Martin Pulec
2ce0cab237 lavc qsv hevc: added cqp RC 2023-03-08 11:23:06 +01:00
Martin Pulec
aeaef446e7 lavc qsv: add rc to codec-specific usage 2023-03-08 11:09:05 +01:00
Martin Pulec
c5c35c9607 lavc: removed unneeded compat (already in common) 2023-03-08 11:09:05 +01:00
Martin Pulec
58ee16e995 lavc: do not erase opts from lavc_opts
Erasing the opt isn't reentrant, so either when reconfigure occurs or
init of first pixfmt fails (eg. with hevc_qsv), it is no longer applicable.
2023-03-08 11:09:05 +01:00
Martin Pulec
62142510c6 lavc: add support for RC for QSV
refer to GH-298
2023-03-08 11:08:30 +01:00
Martin Pulec
a43168ee06 lavc: added option to keep original pixel format
refer to GH-295
2023-03-03 16:30:33 +01:00
Martin Pulec
2f1fc85a8f lavc: set async_depth=1 for mjpeg_qsv
This option improves latency (similarly as done for QSV H.264 and HEVC).
2023-02-28 16:17:36 +01:00
Martin Pulec
2519e3593b lavc: print options set in verbose mode 2023-02-28 16:17:36 +01:00