Commit Graph

5818 Commits

Author SHA1 Message Date
Martin Pulec
e2f0bb34d7 lavd video: removed parser
This effectively reverts recent commit d70e2fb3 (from 15th Aug).

The use of parser seems to be a problem for UG workflow, in the end -
the point is that it may cache a packet until arival of next packet
(commit 6e9a4142), so in that commit, as a solution flushing with EOF
was added.

However, it seems to produce problems with simple (but not with H.264 parser):
```
uv -d gl -t  testcard -c libavcodec:encoder=libx265
```
because the parser seems to be confused when parsing frames after EOF
so for the subsequent frames it consumes 1 byte producing 1 byte output. This
is mostly harmless (it is actually '\0', part of the start code), but
it produces errors:
```
[lavc hevc @ 0x68216c0055c0] missing picture in access unit with size 1
```

Possible solution would be to re-create the parser for every frame
(sic!) but it is unclear the overhead (which applies also to parsing the
frames, anyways). Anyways, as piggy-backed frames should not occur since
the commit c57f2fc5, it is perhaps best to remove this stuff altogether.
2023-08-23 16:51:04 +02:00
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
945e2e9841 vidcap testcard: fixed opt shortcut for pattern
`-t testcard:p=noise` didn't work
2023-08-23 14:14:40 +02:00
Martin Pulec
ecf1ed6fef lavd video: set dav1d default for AV1
The dav1d decoder is performing better than the reference AOM
implementation that would be selected otherwise.
2023-08-22 16:51:46 +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
6104131316 lavd video: debug print parsed pict_type
Only if could not decompress frame, otherwise picture type is printed
in decompress duration summary (also in debug mode).
2023-08-22 15:29:13 +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
4e16bab401 DELTACAST: VideoMaster 6.21 compat
VHD_BOARDTYPE_HDMI is neither deprecated in 6.21, nor
VHD_BOARDTYPE_HDMI_DEPRECATED is defined anymore.
2023-08-21 12:08:12 +02:00
Martin Pulec
989d732d80 lavd video: fixed parsing workflow
(see also previous 2 commits)

Fixed according to [FFmpeg decode video example] - the parser needs
final call with zero long buffer to flush the frame.

\+ prefix eventual parser error with identifying prefix

[FFmpeg decode video example]:
https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/decode_video.c
2023-08-21 11:34:48 +02:00
Martin Pulec
6e9a4142fd Revert "lavd video: don't print false positive errs"
This reverts commit d4be2d97b5.

The fix was not correct, because it just hided the root of the problem -
the av_parser_parse2 needs final call with buf_size == 0 to flush last
frame. Otherwise it will remain in the queue, effectivelly adding a
delay by one frame, because the particular frame will get flushed when
processing next frame.

See also:
<https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/decode_video.c>
2023-08-21 11:34:45 +02:00
Martin Piatka
94740e221c screen_pw: Fix out_ptr segv
g_variant_get is a varargs function, which doesn't seem to play well
with out_ptr. Call the type conversion operator explicitly
2023-08-18 15:33:14 +02:00
Martin Piatka
1e6bbbee9f screen_pw: Replace frame_wrapper by unique_ptr 2023-08-18 15:29:27 +02:00
Martin Pulec
d4be2d97b5 lavd video: don't print false positive errs
do not print errors like:

    uv -d dummy -t testcard -c libavcodec
    [lavd] Error while decoding frame (rc == 42836): Error number 42836 occurred.

when decoder returns empty packet ("error" code acutally indicated number
of consumed bytes).
2023-08-18 12:57:00 +02:00
Martin Pulec
732441f07a cineform dec.: removed needless frame_seq storing 2023-08-18 12:25:41 +02:00
Martin Pulec
12364a9025 lavd video: removed handling of dropped VP8 frms
removed skipping P frames after missing P frame in VP8

This doesn't seem to be needed anymore and removing it simplifies the
code a bit. Moreover, if frame drops was the case, now frames, that
have been skipped until now will be presented, potentially reducing
twitching.
2023-08-18 12:25:41 +02:00
Martin Pulec
2179179b77 video compress sync frame API: follow tile API
Updated sync frame API to match updated tile API as defined by the
commit  e9a407ad.

Note: none of 2 compression using this API currently need reading
additional frames.
2023-08-18 12:25:40 +02:00
Martin Pulec
3943cc739d video compress async tile: removed frame erasing
There was a comment that the frame is no longer valid, which was a bit
misleading, because the the tiles hold reference to that frame but do
not modify it in any way.

Also removed assigning NUL altogether - it was not much functional,
since it will be released soon thereafter, anyways, so it is possibly
not much needed.
2023-08-18 12:25:40 +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
ffa749eb4f lavd video: do not fail if parser init fails
some codecs (FFV1, HFYU) do not have parsers
2023-08-16 15:38:14 +02:00
Martin Pulec
e5b3f5ffa6 lavd video: do not crash if FFV1/HFYU init fails 2023-08-16 15:38:13 +02:00
Martin Pulec
d70e2fb3c1 lavd video: parse the received video buffer
use AVParser for the received compressed data

This is particularly useful when encoder produces frames glued together -
it shouldn't be the case most of the times, since UG programmatically
disables B-frames but there can be some not handled encoders, notably
currently problematic _hevc_mf_ on AMD (AMDh265Encoder).

The FFmpeg native H.264 and HEVC decoders are particuraly sensitive to
passing 2 encoded frames at once, breaking the picture with errors like:

    [lavc hevc @ 0x61c590004d80] Two slices reporting being the first in the same frame.
    [lavc hevc @ 0x61c590004d80] Could not find ref with POC 7

or

     [lavc h264 @ 0x6ee80c004d80] Frame num change from 3 to 4
     [lavc h264 @ 0x6ee80c004d80] decode_slice_header error

After this fix, decoding is correct. Excess frames are dismissed but
decoding works and more importantly, user is informed what is the
problem.
2023-08-15 16:27:06 +02:00
Martin Pulec
4fbe76085e lavd_flush: print error msgs, not only numbers 2023-08-15 16:26:59 +02:00
Martin Pulec
aaf8ff9771 lavd decode: H.264/HEVC - read forced props early
Moved reading eventual forced props at the beginning. Previously, it
must have been waited until first IDR, which is unecessary, because the
custom NAL unit is appended to every frame.

Also it is not needed to read it in all compressions since it is
codec-specific and thus as implemented now, it is only applicable to
H.264/HEVC.
2023-08-15 15:39:35 +02:00
Martin Pulec
f36384247a lavd video: moved usable decoder select to func
Mostly refactor only (just changed bound-checking if-s to assert because
the condition should not happen - it is not depending on user input).
2023-08-15 15:39:31 +02:00
Martin Piatka
e58c6a98f0 conference: fps is optional 2023-08-15 13:08:13 +02:00
Martin Piatka
9e92834ea1 rpi4_out: Use out_ptr 2023-08-15 13:08:12 +02:00
Martin Piatka
6679bc7de1 conference: Use out_ptr 2023-08-15 13:08:12 +02:00
Martin Piatka
ddf64f32cf hd-rum-recompress: Use out_ptr 2023-08-15 13:08:12 +02:00
Martin Piatka
f6951ab4b3 audio/filter/playback: Use out_ptr 2023-08-15 13:08:11 +02:00
Martin Piatka
6be121097d screen_pw: Use unique GVariant insted of ScopeExit 2023-08-15 13:08:11 +02:00
Martin Piatka
f1f1b683d0 misc: Add out_ptr implementation
Useful for setting unique_ptr via plain ptr setters (setter(void **))
2023-08-15 13:08:11 +02:00
Martin Piatka
f1a6325b0d screen_pw: Replace custom instrumentation timer 2023-08-15 13:08:11 +02:00
Martin Pulec
199a67e98d export: small improvements
- simplified a bit
- create_anonymous_dir->create_implicit_dir (obviously, the name
_export.<date>_ is not much anonymous)
2023-08-15 09:05:56 +02:00
Martin Pulec
f0f7140e60 fixed Coverity ID 4165{59,60} 2023-08-15 08:25:49 +02:00
Martin Pulec
d035fcefdf platform_mkdir->mkdir: use POSIX syntax
Use rather defined function as mkdir(3p) is, even though there is needed
a compat for MSW.

+ removed some strtok_r undef, which should no longer be needed (see
also commit 6c6253c9)
2023-08-14 16:06:16 +02:00
Martin Pulec
1656f705e4 dump disp.: use date/time instead of timestamp
Use ISO 8601 date/time for dump directory name instead of seconds since
epoch. Basic format is used because in the extended, the colons delimiting
the time interfere with _export_ options delimiter.
2023-08-14 16:06:16 +02:00
Martin Pulec
08f083a107 NAL_(?!HEVC) -> NAL_H264
Since H.264 and HEVC uses different constants even for the same (named)
NAL type (eg. AUD has 9 in H.264 but 35 in HEVC), replace NAL_ prefix,
that were implilcitly meant or H.264 with NAL_H264.
2023-08-14 16:06:16 +02:00
Martin Pulec
5a9bfd1e53 video lavd: skip leading AUD NALU for HEVC
see the commit d2fedd72 for details
2023-08-14 16:06:16 +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
0017e57134 compat/qsort_s.h: do not require include 1st
Do not enforce the file to be either included before stdlib.h or stdlib.h
to be using __STDC_WANT_LIB_EXT1__ = 1. The bound checking API is
currently nowhere implemented, anyways, and we may use system native secure
qsort implementation (qsort_r in *NIX, MS variant of qsort_s).
2023-08-14 16:06:15 +02:00