Commit Graph

470 Commits

Author SHA1 Message Date
Martin Pulec
002bb4dc7f tv.h (+others): get rid of NS_IN_MS[_DBL]
Use rather the more comprehensible NS_TO_MS and NS_TO_MS function-like
macros (obvious from what to what the conversion is performed).
2024-09-10 16:40:29 +02:00
Martin Pulec
c41e7f8a47 vcomp/lavc: check MJPEG params validity
MJPEG does produce wrong JPEGs[^1] if either slices or threads == 1 and
the other not (until now also the implicit case, because the values
are auto-adjusted).

So if either is 1, auto-set the other value to 1 as well. If both are
set and either is 1 and the other not, issue at least a warning.

[^1]: for the s=1 && t>1, FFmpeg own decoder is capable to decode,
but the bitstream is definitely wrong - instead of RST markers there
are EOI markers.
2024-08-14 11:28:11 +02:00
Martin Pulec
6549973a70 vcomp/lavc: show_coder_help - split to 2 functions
separate UG codec specific usage to a separate function
2024-07-11 14:56:14 +02:00
Martin Pulec
c0a2d0a7e2 vcomp/lavc: per-codec help improvement
If both encoder and decoder of the same name is present, eg. jpeg2000,
print help for both encoder and decoder. Since for the decoder, options
are also printed with enc=<enc>:help, print both enc and dec at the
same time.
2024-07-11 14:56:05 +02:00
Martin Pulec
60befe0b3a vcomp/lavc: add cmdline doc for libsvtav1
examples + remarks for svtav1-param option
2024-07-11 14:29:13 +02:00
Martin Pulec
52b9b38d4a configure_svt: split to av1 version et al.
Actually the setting is entirelly divergent - different if branches are
taken for libsvtav1 and HEVC/VP9. So split it to 2 functions to simplify.
2024-07-11 08:54:03 +02:00
Martin Pulec
5aa8657d3f vcomp/lavc: accept bitrate also for CQP 2024-07-10 16:17:15 +02:00
Martin Pulec
c9930dcc85 vcomp/lavc: do not assert on wrong bitrate
rather return (the error message is already printed by unit_evaluate)
2024-07-10 16:12:26 +02:00
Martin Pulec
208c2f2243 vcomp/lavc libsvtavi: allow bitrate with CRF
This sets Max Bitrate for CRF RC.
2024-07-10 16:12:24 +02:00
Martin Pulec
8737896579 vcomp/lavc: copy setparam_param
In case that set_param callback modifies some field use a copy to be
reentrant for next attempted pixfmt (or reconfiguration).

The other alternative would be to set the pointer to setparam struct
const, but some setters currenty really modify the params.
2024-07-10 15:39:20 +02:00
Martin Pulec
fbeff23698 vcomp/lavc: do not log CRF/CQP setting twice
info already printed with chec_av_opt_set

\+ prints eventual error with error verboseity (template second parameter)
2024-07-09 16:33:35 +02:00
Martin Pulec
e20ce512fb vcomp/lavc: unset svtav1 pred-struct=1 with bitrate
User may be tempted to set the bitrate although CRF is now default,
so unset pred-struct (because it won't work with current
ffmpeg/libxsvtav1).

But issue a (serious) warning in this case.
2024-07-09 16:33:32 +02:00
Martin Pulec
febff7d093 Revert "vcomp/lavc libsvtav1: do not set pred_struct=1"
This reverts commit fa8bb8ca8e.

Actually this worsened the behavior significantly by increasing the
latency in the order of 100 frames (depending on properties). This
(currently) disallows setting the bitrate, using CRF/CQP is only possible
because the FFmpeg plugin isn't able to set CBR for now.
2024-07-09 14:56:26 +02:00
Martin Pulec
c445c6fd5e vcomp/lavc: set CRF=35 for libsvtav1 by default
This will allow running libsvtav1 with pred_struct=1.
2024-07-09 14:53:53 +02:00
Martin Pulec
5281fbc4a8 vcomp/lavc: set forced-idr directly
set_forced_idr function was unnecessary - the error handling can now
do chec_av_opt_set(). Moreover it prints out the setting to std output
even when succeeded.
2024-07-09 12:30:43 +02:00
Martin Pulec
7b0c7f3224 vcomp/lavc: use check_av_opt_set for svtav1-params
it also prints value set in UG output (and handles errors as well)
2024-07-09 10:14:38 +02:00
Martin Pulec
4e63c0ce8b vcomp/lavc: use fast-decode=1 for libsvtav1
set fast-decode as suggested by SVT AV1:
```
Svt[warn]: If you are using tiles with the intent of increasing the
decoder speed, please also consider using --fast-decode 1, especially if
the intended decoder is running with limited multi-threading capabilities.
````
2024-07-02 16:36:12 +02:00
Martin Pulec
fa8bb8ca8e vcomp/lavc libsvtav1: do not set pred_struct=1
currently it causes following error:
```
Svt[error]: VBR Rate control is currently not supported for SVT_AV1_PRED_LOW_DELAY_B, use CBR mode
```

Setting the CBR mode is currently not possible with current FFmpeg patch
- only possibility is to set rc_max_rate=bit_rate ([1] but this triggers
another error:
```
Svt[error]: Instance 1: Max Bitrate only supported with CRF mode
Svt[error]: CBR Rate control is currently not supported for SVT_AV1_PRED_RANDOM_ACCESS, use VBR mode
```

It is also not clear if the pred-struct set to SVT_AV1_PRED_LOW_DELAY_B
has some impact in situation when UG does not use B frames.

[1]: 5d54a25eea/libavcodec/libsvtav1.c (L224)
2024-07-02 16:36:10 +02:00
Martin Pulec
3aec782d03 vcomp/lavc: added defaults for OpenH264
Acually there is quite a few that can be set:
1. default compression (witout RC) works quite good
2. bitrate as well (if the bitrate isn't too low)
3. quality controlled RC doesn't seem to work good

Slice considerations:
- 32 (default) triggers a warning for FullHD and OpenH264 will use
16 -> this is OK
- slices=0 would disable multithreading
- setting max_nal_size (with slices=0) would help as well, but it is
not clear what is the "good" value

Not yet added to CI (libopenh264 is included in Ubuntu 22.04, now using
20.04 for the build).
2024-06-04 15:29:35 +02:00
Martin Pulec
f5d6cc0741 vcomp/lavc: check requested CQP/CRF vals
CQP just for number validity (not sure about the reange now), CRF also
the ranged (0-63 - 63 for 10-bit H.264, otherwise 51 /also for higher
bit depth HEVC).
2024-06-04 15:29:35 +02:00
Martin Pulec
755023088f vcomp/lavc: move req quality to setparam_params
In the configure callback, requested mode or even its value may (will)
be evaluated.
2024-06-04 15:29:31 +02:00
Martin Pulec
63b524c781 vcomp/lavc: thr_cnt=0 for other threads implicitly
Set automatic number (== 0) of threads if codec advertises
AV_CODEC_CAP_OTHER_THREAD implicitily, with exceptions:
1. AOM AV1, rav1e - seems not to set the number automatically
2. libx26* - allow setting but enables frame threading internally
(which is undesirable)

the current setting applies not just to libvpx* but also to
eg. libopenh264.
2024-06-03 12:13:15 +02:00
Martin Pulec
3801f6ecc9 vcomp/lavc: warn if requesting codecs w/o enc
Warn if requesting input encoder pixel formats but the encoder is
not specified explicitly, eg. for
`uv -c lavc:codec=H.264 --param lavc-use-codec=help`
we cannot know, whinch encoder will be used in the
end (usually libx264 for YCbCr and libx264rgb for RGB pixel formats).
2024-06-03 11:44:38 +02:00
Martin Pulec
59407efe38 vcomp/lavc: moved help handling to a separate function 2024-06-03 11:44:37 +02:00
Martin Pulec
64a7579387 vcomp/lavc: renamed backend->req_encoder
req_encoder seems to be more clear

\+ print "Encoder %s doesn't encode requested codec" as an error (no
encoding is actually done)
2024-06-03 11:43:33 +02:00
Martin Pulec
c8def23c98 vcomp/lac: usage parsing simplified
It was a bit unintelligible, but improve the stuff a bit.
2024-06-03 10:33:23 +02:00
Martin Pulec
49c9d2482d vcomp/lavc: codec opts printout fix
When help was not present but default value yes, it was printed without
a delimiter (" - ") after the option.
2024-05-23 15:32:03 +02:00
Martin Pulec
3aa75eca52 vcomp/lavc: unsupp feature warn also for encoders
Use a word 'coders' instead of 'decoders' to point out to potentially
unsupported features, because not only decoders may be affected, so make
it clear.
2024-05-23 12:40:30 +02:00
Martin Pulec
481332757f vcompress/lavc: do metadata housekeeping in store
Moved metadata housekeeping to store_metadata() and removed the
assert. The idea is to prevent crashes on assert when some encode fails.

In some malicous case (eg. when the latency is higg), the metadata can be
now released prior to restoring, so print at least a warning about that.
2024-04-26 13:00:43 +02:00
Martin Pulec
4fe23e9728 vcompress/lavc SVT: preset for HEVC > UHD@60
The SVT HEVC compression has (for UG) an ugly feature that it caches
internally in some cases a huge amount of frames, leading to increased
latency and also memory consumption. The first problem is dealt with
at least with the warning (commit e3f64d56, 2024-04-12).

if running
`uv -t testcard:c=RG48:s=3840x2160:fps=240 -c lavc:enc=libsvt_hevc`
with default preset (7) the latency grew up to some 430 frames, triggering
the assertion in store_metadata().

Setting the preset (for the above command - it is size/FPS depending)
to 11 shrinks the amount of frames cached to some 40 frames, that seem
more acceptable.
2024-04-16 12:32:56 +02:00
Martin Pulec
0725294e8c vcompress/lavc: suggest preset opt for libsvt_hevc
in case of insufficient performance
2024-04-15 16:39:49 +02:00
Martin Pulec
4facf0e5e0 vcompress/lavc: receive_packet handle to fn
There are actually 2 places where avcodec_receive_packet() is called
and the error handling is the same so move it to a separate function.

\+ report (in debug) EAGAIN
\+ move HOUSEKEEP_INTERVAL at the beginning of the file (there already
is an eligible enum)
2024-04-15 15:23:10 +02:00
Martin Pulec
4590f04dcf vcapture/lavc: assert pts != AV_NOPTS_VALUE
I assume that the pts should be always set on output if set on input so
assert it. If this proves wrong, it would need to be handled specially
(but also it will break the mechanism of metadata storing/restoring).
2024-04-12 14:24:29 +02:00
Martin Pulec
e3f64d5656 vcompress/lavc: report delayed frames
Can indicate a problem, eg. currently SVT HEVC when doesn't manage to
compress real-time.

It can also indicate eg. B-frames presence which may be desired (requested
by user parameters) but we can at least point it out.
2024-04-12 14:24:25 +02:00
Martin Pulec
d992c68227 lavc video: repeat the compressoion duration warn
Repeat the message every 30 secods - it is potentially important
information and when printed only once, the user may miss the point when
there is plenty of messages (especially at the beginning).

\+ do the same also for decompress
2024-02-28 12:15:36 +01:00
Martin Pulec
0e97fba40e lavc video: fixed crash when reinit fails
Fixed a crash in situation where compressing stream with properties A,
then B but init fails and then again A.

This can occur when using switcher for 1->2->1 when compress reconf
fails for 2. But because `saved_desc` is set if reconf succeeds and
was already set on first configure, the state is inconsistent because
partially de/configured for 2 but it looks like it is still correctly
configured to input 1 because `saved_desc` was not cleared.

refers to GH-365
2024-01-03 14:49:21 +01:00
Martin Pulec
9575c24b79 lavc: include config.h unconditionally
needed for PACKAGE_BUGREPORT
2023-12-04 13:06:16 +01:00
Martin Pulec
574a33da0a lavc: enable header_inserter for h264_amf
AMD RX 7600 needs this even though header_spacing is set to 1. RX 580
didn't need this.
2023-12-04 12:43:25 +01:00
Martin Pulec
acf3320143 lavc header_inserter: fixed inverted condition 2023-12-04 12:34:01 +01:00
Martin Pulec
40a7d04ec1 unit_evaluate[_dbl]: added endptr param 2023-11-29 15:27:32 +01:00
Martin Pulec
cb269cf992 lavc video: do not set interlaced DCT for libx265
Interlacing is not honored by libx265, anyways, and this saves the
eventual HWacc warning.

It is still passed to QSV even for HEVC, anyways. Not sure how the API
handles that but FFmpeg seems to pass it.
2023-10-06 16:44:18 +02:00
Martin Pulec
31af5137e7 lavc video: warn also when >8 bit depth used
\+ remove "and not 4:2:0" from subs complaint - it is perhaps needlessly
verbose (other feature doesn't name the correct value. user should be
aware, anyways, and there is also a hint below.
2023-10-06 16:44:18 +02:00
Martin Pulec
f2ac2cbdf8 lavc,lavd vid: print used subs in warn
Print used subsampling (or sw fmt in lavd) in warning if not using 4:2:0.

This may be helpful sometimes as an additional information.
2023-10-06 11:26:49 +02:00
Martin Pulec
ac110f1b49 vaapi dec.: deduce SW format to reported valid
Set AVHWFramesContext::sw_format to first of av_hwframe_transfer_get_formats().

This is consistent how MPV does that. Fixes NV12 being transmitted
despite AVHWFramesContext::sw_format was set to yuv420p causing chroma
channels corruption (because the nv12 data was misinterpreted as the
latter one) occuring on AMD cards, steps to reproduce:
```
uv -t testcard -c lavc:enc=libx264:safe -d gl --param use-hw-accel=vaapi
```

See also:
<66e30e7f2f>
2023-10-06 11:19:11 +02:00
Martin Pulec
e5d628cd79 lavc: added "safe" option
enables option for HW(-accelerated) decode compatibility:
* subsampling 420
* no intra refresh
* no interlaced DCT
2023-10-06 11:19:11 +02:00
Martin Pulec
000c8c0bdb lavc video help: cmdline print updates
* shorten lines
* print usage where can be seen that there is also fullhelp
2023-10-06 11:19:11 +02:00
Martin Pulec
e990318499 lavc video: handle incompatible subs as other features 2023-10-06 11:19:10 +02:00
Martin Pulec
4c250bd274 lavc video: do not report "lavc" shortcut in caps
would be displayed twice in GUI otherwise
2023-10-05 15:05:36 +02:00
Martin Pulec
8e1f8905d5 lavc video enc: warn on interlaced DCT as well
see also previous commit
2023-10-05 15:05:36 +02:00
Martin Pulec
17fcd1bf44 lavc video: warn when auto-enabled intra-refresh
Warn in the same way as when non-4:2:0 video is encoded - intra refresh
might be problematic as well.

Do not warn if enabled explicitly (`:intra_refresh`).
2023-10-05 15:05:36 +02:00