Commit Graph

32 Commits

Author SHA1 Message Date
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
nilfm 5f4b7bf2b5 avfilter/vf_libvmaf: fix string comparison bug
The libvmaf filter was doing substring checks in place of string equality
comparisons. This led to a bug when the user specified the pooling method
"harmonic_mean", since "mean" was checked first and the substring comparison
returned true. This patch changes all substring comparisons for string equality
comparisons. This is both correct and more efficient than the existing method.

Signed-off-by: nilfm <nilf@netflix.com>
2023-12-08 10:32:46 -08:00
Kyle Swanson 9f1dbca820 avfilter/libvmaf: small cleanup for style, whitespace, unused LIBVMAFContext struct members
Signed-off-by: Kyle Swanson <kswanson@netflix.com>
2023-12-04 10:00:01 -08:00
Kyle Swanson e5f774268a avfilter/libvmaf: fix broken cuda build
Signed-off-by: Kyle Swanson <kswanson@netflix.com>
2023-10-27 15:00:58 -07:00
Kyle Swanson 2e33f5ced0 avfilter/libvmaf: update pix_fmts
Signed-off-by: Kyle Swanson <kswanson@netflix.com>
2023-10-12 10:37:36 -07:00
Kyle Swanson 6028728bb8 avfilter/libvmaf: remove deprecated options 2023-10-10 11:00:20 -07:00
Kyle Swanson 7f685d0f49 avfilter: add libvmaf_cuda
Signed-off-by: Kyle Swanson <kswanson@netflix.com>
2023-09-27 10:22:33 -07:00
Chema Gonzalez c0f89dccc8 lavfi/vf_libvmaf: add warning when color ranges differ
The VMAF filter uses the pixel values without considering
the color ranges. This is incorrect. Patch adds a warning
so at least the user knows it.

Let's see an example.

(1) Let's get FR and LR versions of the same image.

```
$ ffmpeg -y -i /tmp/lena.490x490.ppm -vf scale="out_range=full" -pix_fmt yuv420p /tmp/lena.full.y4m
$ xxd /tmp/lena.full.y4m |head
00000000: 5955 5634 4d50 4547 3220 5734 3930 2048  YUV4MPEG2 W490 H
00000010: 3439 3020 4632 353a 3120 4970 2041 303a  490 F25:1 Ip A0:
00000020: 3020 4334 3230 6a70 6567 2058 5953 4353  0 C420jpeg XYSCS
00000030: 533d 3432 304a 5045 4720 5843 4f4c 4f52  S=420JPEG XCOLOR
00000040: 5241 4e47 453d 4655 4c4c 0a46 5241 4d45  RANGE=FULL.FRAME
00000050: 0a72 7271 7070 706f 6f6e 6d6d 6c6d 6d6d  .rrqpppoonmmlmmm
00000060: 6c6e 6e6d 6d6e 6e6e 6d6c 6d6d 6d6d 6d6d  lnnmmnnnmlmmmmmm
00000070: 6d6e 6d6b 6c6d 6e6e 6d6c 6d6d 6e6e 6f6f  mnmklmnnmlmmnnoo
00000080: 6f6f 6e6e 6e6e 6f70 7172 7375 7676 7370  oonnnnopqrsuvvsp
00000090: 6d69 6662 5e59 534d 4845 3d35 302e 2d2c  mifb^YSMHE=50.-,
```

```
$ ffmpeg -y -i /tmp/lena.490x490.ppm -vf scale="out_range=limited" -pix_fmt yuv420p /tmp/lena.limited.y4m
$ xxd /tmp/lena.limited.y4m | head
00000000: 5955 5634 4d50 4547 3220 5734 3930 2048  YUV4MPEG2 W490 H
00000010: 3439 3020 4632 353a 3120 4970 2041 303a  490 F25:1 Ip A0:
00000020: 3020 4334 3230 6a70 6567 2058 5953 4353  0 C420jpeg XYSCS
00000030: 533d 3432 304a 5045 4720 5843 4f4c 4f52  S=420JPEG XCOLOR
00000040: 5241 4e47 453d 4c49 4d49 5445 440a 4652  RANGE=LIMITED.FR
00000050: 414d 450a 7272 7170 7070 6f6f 6e6e 6e6d  AME.rrqpppoonnnm
00000060: 6e6e 6e6d 6f6e 6e6e 6e6e 6e6e 6d6e 6e6e  nnnmonnnnnnnmnnn
00000070: 6e6e 6e6e 6f6e 6c6d 6e6f 6e6e 6d6e 6e6f  nnnnonlmnonnmnno
00000080: 6f6f 6f6f 6f6f 6f6f 6f6f 7071 7273 7576  oooooooooopqrsuv
00000090: 7673 706e 6a68 6461 5c57 524e 4b44 3d39  vspnjhda\WRNKD=9
```

Note that the 2x images are the same. Only difference is the range,
and the precision issues related to range conversion.

(2) Let's calculate the VMAF score:
```
$ ./ffmpeg -filter_threads 1 -filter_complex_threads 1 -i /tmp/lena.full.y4m -i /tmp/lena.limited.y4m -lavfi libvmaf="model=path=/usr/share/model/vmaf_v0.6.1neg.json" -report -f null -
...
[Parsed_libvmaf_0 @ 0x3cc9b40] VMAF score: 85.530109
```

As we are comparing an image with itself, we expect the score to
be close to 100. Issue here is that the VMAF filter just uses the
pixel values, ignoring the color ranges.

Proposed solution is to add a warning.
```
$ ./ffmpeg -filter_threads 1 -filter_complex_threads 1 -i /tmp/lena.full.y4m -i /tmp/lena.limited.y4m -lavfi libvmaf="model=path=/us
r/share/model/vmaf_v0.6.1neg.json" -report -f null -
...
[Parsed_libvmaf_0 @ 0x3cc9b40] distorted and reference frames use different color ranges (pc != tv)
...
[Parsed_libvmaf_0 @ 0x3cc9b40] VMAF score: 85.530109
```

Tested:

Ran fate.
```
$ make fate -j
...
TEST    seek-lavf-ppmpipe
TEST    seek-lavf-pgmpipe
TEST    seek-lavf-mxf_opatom
```
2023-09-23 15:55:50 +01:00
Marvin Scholz 492b45cb19 avfilter/vf_libvmaf: use av_dict_iterate
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-12-01 11:21:14 +01:00
Yondon Fu b11813708d avfilter/vf_libvmaf: Update ssim, ms_ssim options description
Update description for ssim and ms_ssim libvmaf options to specify
feature=float_ssim and feature=float_ms_ssim which are used to request
ssim and ms_ssim values in the latest versions of libvmaf.

Signed-off-by: Yondon Fu <yondon.fu@gmail.com>
2022-09-16 13:07:43 -07:00
Christian Feldmann 8357d4790f avfilter/vf_libvmaf: copy all values also for 10 bit input 2022-09-14 19:42:59 +02:00
Kyle Swanson 3d29724c00 avfilter/vf_libvmaf: update filter for libvmaf v2.0.0 2022-01-23 11:41:30 -08:00
Andreas Rheinhardt 31a373ce71 avfilter: Reindentation after query_formats changes
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-05 18:58:29 +02:00
Andreas Rheinhardt 55e8c3598b avfilter/vf_libvmaf: Use formats list instead of query function
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-05 18:58:27 +02:00
Andreas Rheinhardt b4f5201967 avfilter: Replace query_formats callback with union of list and callback
If one looks at the many query_formats callbacks in existence,
one will immediately recognize that there is one type of default
callback for video and a slightly different default callback for
audio: It is "return ff_set_common_formats_from_list(ctx, pix_fmts);"
for video with a filter-specific pix_fmts list. For audio, it is
the same with a filter-specific sample_fmts list together with
ff_set_common_all_samplerates() and ff_set_common_all_channel_counts().

This commit allows to remove the boilerplate query_formats callbacks
by replacing said callback with a union consisting the old callback
and pointers for pixel and sample format arrays. For the not uncommon
case in which these lists only contain a single entry (besides the
sentinel) enum AVPixelFormat and enum AVSampleFormat fields are also
added to the union to store them directly in the AVFilter,
thereby avoiding a relocation.

The state of said union will be contained in a new, dedicated AVFilter
field (the nb_inputs and nb_outputs fields have been shrunk to uint8_t
in order to create a hole for this new field; this is no problem, as
the maximum of all the nb_inputs is four; for nb_outputs it is only
two).

The state's default value coincides with the earlier default of
query_formats being unset, namely that the filter accepts all formats
(and also sample rates and channel counts/layouts for audio)
provided that these properties agree coincide for all inputs and
outputs.

By using different union members for audio and video filters
the type-unsafety of using the same functions for audio and video
lists will furthermore be more confined to formats.c than before.

When the new fields are used, they will also avoid allocations:
Currently something nearly equivalent to ff_default_query_formats()
is called after every successful call to a query_formats callback;
yet in the common case that the newly allocated AVFilterFormats
are not used at all (namely if there are no free links) these newly
allocated AVFilterFormats are freed again without ever being used.
Filters no longer using the callback will not exhibit this any more.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-05 17:48:25 +02:00
Andreas Rheinhardt 095d88d7ca avfilter/vf_libvmaf: Remove always-false format check
This filter uses ff_set_common_formats_from_list().

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-21 17:56:55 +02:00
Andreas Rheinhardt 8be701d9f7 avfilter/avfilter: Add numbers of (in|out)pads directly to AVFilter
Up until now, an AVFilter's lists of input and output AVFilterPads
were terminated by a sentinel and the only way to get the length
of these lists was by using avfilter_pad_count(). This has two
drawbacks: first, sizeof(AVFilterPad) is not negligible
(i.e. 64B on 64bit systems); second, getting the size involves
a function call instead of just reading the data.

This commit therefore changes this. The sentinels are removed and new
private fields nb_inputs and nb_outputs are added to AVFilter that
contain the number of elements of the respective AVFilterPad array.

Given that AVFilter.(in|out)puts are the only arrays of zero-terminated
AVFilterPads an API user has access to (AVFilterContext.(in|out)put_pads
are not zero-terminated and they already have a size field) the argument
to avfilter_pad_count() is always one of these lists, so it just has to
find the filter the list belongs to and read said number. This is slower
than before, but a replacement function that just reads the internal numbers
that users are expected to switch to will be added soon; and furthermore,
avfilter_pad_count() is probably never called in hot loops anyway.

This saves about 49KiB from the binary; notice that these sentinels are
not in .bss despite being zeroed: they are in .data.rel.ro due to the
non-sentinels.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-20 12:53:58 +02:00
Andreas Rheinhardt 18ec426a86 avfilter/formats: Factor common function combinations out
Several combinations of functions happen quite often in query_format
functions; e.g. ff_set_common_formats(ctx, ff_make_format_list(sample_fmts))
is very common. This commit therefore adds functions that are equivalent
to commonly used function combinations in order to reduce code
duplication.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-13 17:36:22 +02:00
Andreas Rheinhardt a04ad248a0 avfilter: Constify all AVFilters
This is possible now that the next-API is gone.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 11:48:05 -03:00
Harry Mallon 412d63fe72 avfilter/libvmaf: mention csv as available log format
Signed-off-by: Harry Mallon <harry.mallon@codex.online>
Signed-off-by: Gyan Doshi <ffmpeg@gyani.pro>
2020-08-21 10:48:27 +05:30
Limin Wang 8aa143eaa8 avfilter/vf_libvmaf: Check for av_frame_alloc failure
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-11-28 18:44:01 +01:00
Paul B Mahol e835a9d302 avfilter/vf_libvmaf: fix filtering of >8 bit data
This is what reference does.
2019-10-13 23:43:42 +02:00
Kyle Swanson 87cc7e8d4e lavfi/vf_libvmaf: update to use libvmaf v1.3.9
Signed-off-by: Kyle Swanson <kswanson@netflix.com>
2018-08-10 12:00:12 -07:00
Kevin Wheatley 51775bc1cd avfilter/vf_libvmaf: the libvmaf filter tried to join on an invalid thread id
The thread id was invalid because it was not initialised
during the calls to init_complex_filtergraph.

This adds a flag to check for initialisation before trying to
peform the join.

Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com>
Signed-off-by: Kevin Wheatley <kevin.j.wheatley@gmail.com>
2018-05-04 18:29:53 -03:00
enctac be502ec6cd vf_libvmaf: Fix memory leak
Fixes ticket #6967
2018-03-31 20:58:09 -07:00
Ronald S. Bultje df3222d4bb libvmaf: exit gracefully if the library fails.
Fixes trac issue #6884 and Netflix/vmaf issue #124.
2017-12-18 07:59:53 -05:00
Carl Eugen Hoyos d13b8f68d7 lavfi/libvmaf: Rename local variable "main" as "master".
Fixes the following warning:
libavfilter/vf_libvmaf.c:179:14: warning: 'main' is usually a function

Missed in 5d3e9357
2017-11-30 14:13:15 +01:00
Ashish Pratap Singh 4c38aa79ec avfilter/vf_libvmaf: fix errors while running with psnr=1.
This patch fixes the seg fault which ocuured while running libvmaf filter
with option psnr=1.

Signed-off-by: ashk43712 <ashk43712@gmail.com>
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
2017-11-06 07:50:11 -05:00
Nicolas George 5f5dcf44e3 lavfi: rename framesync2 to framesync. 2017-09-12 11:03:51 +02:00
Ashish Singh 2a4a26fa4f avfilter/vf_libvmaf: fix pre convert to framesync2 bugs
Hi, it fixes the errors while converting to framesync2.
libvmaf was changed recently, double *score variable is removed in the new
version since it's not used anywhere. This patch fixes all the warnings and
segmentation faults.

Signed-off-by: Ashish Singh <ashk43712@gmail.com>
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
2017-08-30 09:19:15 -04:00
Nicolas George a8ab52fae7 lavfi/vf_libvmaf: convert to framesync2.
After this commit, the code compiles, but on my setup it
segfaults before and after. It also prints the very worrying
warning:

src/libavfilter/vf_libvmaf.c:161:66: warning: passing argument 4 of ‘compute_vmaf’ from incompatible pointer type [-Wincompatible-pointer-types]
/tmp/i/include/libvmaf.h:26:8: note: expected ‘int (*)(float *, float *, float *, int,  void *)’ but argument is of type ‘int (*)(float *, float *, float *, int,  double *, void *)’

==12116== Thread 6:
==12116== Conditional jump or move depends on uninitialised value(s)
==12116==    at 0x526D432: cons_ (ocval.h:1188)
==12116==    by 0x526D432: GenericIT (ocval.h:1119)
==12116==    by 0x526D432: OC::TranslateForNumPyClassesToArray(OC::Val&) (pickleloader.h:92)
==12116==    by 0x5211F5D: loads (pickleloader.h:566)
==12116==    by 0x5211F5D: LoadValFromArray (chooseser.h:290)
==12116==    by 0x5211F5D: LoadValFromFile (chooseser.h:405)
==12116==    by 0x5211F5D: _read_and_assert_model(char const*, OC::Val&, OC::Val&, OC::Val&, OC::Val&, OC::Val&, OC::Val&) (vmaf.cpp:77)
==12116==    by 0x5212B0F: VmafRunner::run(Asset, int (*)(float*, float*, float*, int, void*), void*, bool, bool, bool, bool, bool) (vmaf.cpp:149)
==12116==    by 0x52165B6: RunVmaf(char const*, int, int, int (*)(float*, float*, float*, int, void*), void*, char const*, char const*, char const*, bool, bool, bool, bool, bool, char const*) (vmaf.cpp:645)
==12116==    by 0x518AFFF: compute_vmaf_score (vf_libvmaf.c:161)
==12116==    by 0x518AFFF: call_vmaf (vf_libvmaf.c:170)
==12116==    by 0x7967493: start_thread (pthread_create.c:333)
==12116==    by 0x7F69A8E: clone (clone.S:97)
==12116==
==12116== Conditional jump or move depends on uninitialised value(s)
==12116==    at 0x526D432: cons_ (ocval.h:1188)
==12116==    by 0x526D432: GenericIT (ocval.h:1119)
==12116==    by 0x526D432: OC::TranslateForNumPyClassesToArray(OC::Val&) (pickleloader.h:92)
==12116==    by 0x526D50D: OC::TranslateForNumPyClassesToArray(OC::Val&) (pickleloader.h:94)
==12116==    by 0x5211F5D: loads (pickleloader.h:566)
==12116==    by 0x5211F5D: LoadValFromArray (chooseser.h:290)
==12116==    by 0x5211F5D: LoadValFromFile (chooseser.h:405)
==12116==    by 0x5211F5D: _read_and_assert_model(char const*, OC::Val&, OC::Val&, OC::Val&, OC::Val&, OC::Val&, OC::Val&) (vmaf.cpp:77)
==12116==    by 0x5212B0F: VmafRunner::run(Asset, int (*)(float*, float*, float*, int, void*), void*, bool, bool, bool, bool, bool) (vmaf.cpp:149)
==12116==    by 0x52165B6: RunVmaf(char const*, int, int, int (*)(float*, float*, float*, int, void*), void*, char const*, char const*, char const*, bool, bool, bool, bool, bool, char const*) (vmaf.cpp:645)
==12116==    by 0x518AFFF: compute_vmaf_score (vf_libvmaf.c:161)
==12116==    by 0x518AFFF: call_vmaf (vf_libvmaf.c:170)
==12116==    by 0x7967493: start_thread (pthread_create.c:333)
==12116==    by 0x7F69A8E: clone (clone.S:97)
==12116==
==12116== Conditional jump or move depends on uninitialised value(s)
==12116==    at 0x526D432: cons_ (ocval.h:1188)
==12116==    by 0x526D432: GenericIT (ocval.h:1119)
==12116==    by 0x526D432: OC::TranslateForNumPyClassesToArray(OC::Val&) (pickleloader.h:92)
==12116==    by 0x526D50D: OC::TranslateForNumPyClassesToArray(OC::Val&) (pickleloader.h:94)
==12116==    by 0x526D50D: OC::TranslateForNumPyClassesToArray(OC::Val&) (pickleloader.h:94)
==12116==    by 0x5211F5D: loads (pickleloader.h:566)
==12116==    by 0x5211F5D: LoadValFromArray (chooseser.h:290)
==12116==    by 0x5211F5D: LoadValFromFile (chooseser.h:405)
==12116==    by 0x5211F5D: _read_and_assert_model(char const*, OC::Val&, OC::Val&, OC::Val&, OC::Val&, OC::Val&, OC::Val&) (vmaf.cpp:77)
==12116==    by 0x5212B0F: VmafRunner::run(Asset, int (*)(float*, float*, float*, int, void*), void*, bool, bool, bool, bool, bool) (vmaf.cpp:149)
==12116==    by 0x52165B6: RunVmaf(char const*, int, int, int (*)(float*, float*, float*, int, void*), void*, char const*, char const*, char const*, bool, bool, bool, bool, bool, char const*) (vmaf.cpp:645)
==12116==    by 0x518AFFF: compute_vmaf_score (vf_libvmaf.c:161)
==12116==    by 0x518AFFF: call_vmaf (vf_libvmaf.c:170)
==12116==    by 0x7967493: start_thread (pthread_create.c:333)
==12116==    by 0x7F69A8E: clone (clone.S:97)
==12116==
==12116== Use of uninitialised value of size 8
==12116==    at 0x518AC79: read_frame_8bit (vf_libvmaf.c:147)
==12116==    by 0x52AB5E8: combo (combo.c:149)
==12116==    by 0x5212E95: VmafRunner::run(Asset, int (*)(float*, float*, float*, int, void*), void*, bool, bool, bool, bool, bool) (vmaf.cpp:278)
==12116==    by 0x52165B6: RunVmaf(char const*, int, int, int (*)(float*, float*, float*, int, void*), void*, char const*, char const*, char const*, bool, bool, bool, bool, bool, char const*) (vmaf.cpp:645)
==12116==    by 0x518AFFF: compute_vmaf_score (vf_libvmaf.c:161)
==12116==    by 0x518AFFF: call_vmaf (vf_libvmaf.c:170)
==12116==    by 0x7967493: start_thread (pthread_create.c:333)
==12116==    by 0x7F69A8E: clone (clone.S:97)
==12116==
==12116== Invalid read of size 4
==12116==    at 0x518AC79: read_frame_8bit (vf_libvmaf.c:147)
==12116==    by 0x52AB5E8: combo (combo.c:149)
==12116==    by 0x5212E95: VmafRunner::run(Asset, int (*)(float*, float*, float*, int, void*), void*, bool, bool, bool, bool, bool) (vmaf.cpp:278)
==12116==    by 0x52165B6: RunVmaf(char const*, int, int, int (*)(float*, float*, float*, int, void*), void*, char const*, char const*, char const*, bool, bool, bool, bool, bool, char const*) (vmaf.cpp:645)
==12116==    by 0x518AFFF: compute_vmaf_score (vf_libvmaf.c:161)
==12116==    by 0x518AFFF: call_vmaf (vf_libvmaf.c:170)
==12116==    by 0x7967493: start_thread (pthread_create.c:333)
==12116==    by 0x7F69A8E: clone (clone.S:97)
==12116==  Address 0x40 is not stack'd, malloc'd or (recently) free'd
==12116==
==12116==
==12116== Process terminating with default action of signal 11 (SIGSEGV)
==12116==  Access not within mapped region at address 0x40
==12116==    at 0x518AC79: read_frame_8bit (vf_libvmaf.c:147)
==12116==    by 0x52AB5E8: combo (combo.c:149)
==12116==    by 0x5212E95: VmafRunner::run(Asset, int (*)(float*, float*, float*, int, void*), void*, bool, bool, bool, bool, bool) (vmaf.cpp:278)
==12116==    by 0x52165B6: RunVmaf(char const*, int, int, int (*)(float*, float*, float*, int, void*), void*, char const*, char const*, char const*, bool, bool, bool, bool, bool, char const*) (vmaf.cpp:645)
==12116==    by 0x518AFFF: compute_vmaf_score (vf_libvmaf.c:161)
==12116==    by 0x518AFFF: call_vmaf (vf_libvmaf.c:170)
==12116==    by 0x7967493: start_thread (pthread_create.c:333)
==12116==    by 0x7F69A8E: clone (clone.S:97)
2017-08-29 10:19:04 +02:00
Ashish Singh 615479d51c avfilter: add LIBVMAF filter
This one changes the previous vmaf patch to libvmaf to keep it separate from the
native implementation of vmaf inside ffmpeg later.

Signed-off-by: Ashish Singh <ashk43712@gmail.com>
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
2017-07-16 08:21:32 -04:00