Commit Graph

22 Commits

Author SHA1 Message Date
Andreas Rheinhardt 1ea3650823 Replace all occurences of av_mallocz_array() by av_calloc()
They do the same.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-20 01:03:52 +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 1b20853fb3 avfilter/internal: Factor out executing a filter's execute_func
The current way of doing it involves writing the ctx parameter twice.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-15 21:33:25 +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
Paul B Mahol a174e5f8da avfilter/vf_nlmeans: round values toward nearest integer
Instead of rounding toward zero and thus producing
darker output.
2019-10-21 09:26:41 +02:00
Clément Bœsch 1a9c6cc411 lavfi/nlmeans: use a dynamic size for the weight LUT 2019-02-01 20:58:47 +01:00
Clément Bœsch 65e61febc8 lavfi/nlmeans: simplify log() call 2019-02-01 20:58:47 +01:00
Jun Zhao 6c586303a1 lavfi/nlmeans: improve the performance
Remove the pdiff_lut_scale in nlmeans and increase weight_lut table size
from 2^9 to 500000, this change will avoid using pdiff_lut_scale in
nlmeans_slice() for weight_lut table search, improving the performance
by about 12%. (in 1080P size picture case).

Use the profiling command like:

perf stat -a -d -r 5 ./ffmpeg -i input -an -vf nlmeans=s=30 -vframes 10 \
-f null /dev/null

without this change:
when s=1.0(default value) 63s
     s=30.0               72s

after this change:
     s=1.0(default value) 56s
     s=30.0               63s

Reviewed-by: Carl Eugen Hoyos <ceffmpeg@gmail.com>
Signed-off-by: Jun Zhao <mypopydev@gmail.com>
Signed-off-by: Clément Bœsch <u@pkh.me>
2019-02-01 20:58:43 +01:00
Clément Bœsch 8d6354aa82 lavfi/nlmeans: use AV_CEIL_RSHIFT instead of deprecated FF_CEIL_RSHIFT 2018-05-08 12:47:38 +02:00
Clément Bœsch e6114d21ac lavfi/nlmeans: inline integral patch value function
This prevents redundant position computation and make the code faster
(1.1x faster overall).
2018-05-08 10:28:06 +02:00
Clément Bœsch 4278f79ef6 lavfi/nlmeans: use unsigned for the integral patch value
This value can not be negative.
2018-05-08 10:28:06 +02:00
Clément Bœsch de956198a9 lavfi/nlmeans: reorder memory accesses in get_integral_patch_value
This doesn't seem to make much of a difference but it can't hurt.
2018-05-08 10:28:06 +02:00
Clément Bœsch 34e1e53e28 lavfi/nlmeans: move final weighted averaging out of nlmeans_plane
This helps figuring out where the filter is slow:

  70.53%  ffmpeg_g  ffmpeg_g          [.] nlmeans_slice
  25.73%  ffmpeg_g  ffmpeg_g          [.] compute_safe_ssd_integral_image_c
   1.74%  ffmpeg_g  ffmpeg_g          [.] compute_unsafe_ssd_integral_image
   0.82%  ffmpeg_g  ffmpeg_g          [.] ff_mjpeg_decode_sos
   0.51%  ffmpeg_g  [unknown]         [k] 0xffffffff91800a80
   0.24%  ffmpeg_g  ffmpeg_g          [.] weight_averages

(Tested with a large image that takes several seconds to process)

Since this function is irrelevant speed wise, the file's TODO is
updated.
2018-05-08 10:28:06 +02:00
Clément Bœsch 667503ef68 lavfi/nlmeans: switch from double to float
Overall speed appears to be 1.1x faster with no noticeable quality
impact.
2018-05-08 10:28:06 +02:00
Clément Bœsch 43d16aef63 lavfi/nlmeans: make compute_safe_ssd_integral_image_c faster
before:  ssd_integral_image_c: 49204.6
after:   ssd_integral_image_c: 44272.8

Unrolling by 4 made the biggest difference on odroid-c2 (aarch64);
unrolling by 2 or 8 both raised 46k cycles vs 44k for 4.

Additionally, this is a much better reference when writing SIMD (SIMD
vectorization will just target 16 instead of 4).
2018-05-08 10:28:06 +02:00
Clément Bœsch 5a71bce371 lavfi/nlmeans: add AArch64 SIMD for compute_safe_ssd_integral_image
ssd_integral_image_c: 49204.6
ssd_integral_image_neon: 28346.8
2018-05-08 10:28:06 +02:00
Clément Bœsch 5ba14f4f1a lavfi/nlmeans: use ptrdiff_t for linesizes
Similarly to previous commit, this will help writing SIMD code by not
having manual zero-extension in SIMD code
2018-05-08 10:28:06 +02:00
Clément Bœsch 26f02c51ce lavfi/nlmeans: add SIMD-friendly assumptions for compute_safe_ssd_integral_image
SIMD code will not have to deal with padding itself. Overwriting in that
function may have been possible but involve large overreading of the
sources. Instead, we simply make sure the width to process is always a
multiple of 16. Additionally, there must be some actual area to process
so the SIMD code can have its boundary checks after processing the first
pixels.
2018-05-08 10:28:06 +02:00
Clément Bœsch f1248b7795 lavfi/nlmeans: random code shuffling to help compiler
This makes nlmeans_slice() slightly faster at least on GCC 7.3.
2018-05-08 10:28:06 +02:00
Paul B Mahol ed93ed5ee3 avfilter: don't anonymously typedef structs
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2017-05-13 11:39:28 +02:00
Clément Bœsch c29b532a94 lavfi: add nlmeans filter
Fixes Ticket #4910
2016-09-24 09:52:10 +02:00