1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00
Commit Graph

64 Commits

Author SHA1 Message Date
James Almer
362586fcad avfilter/vf_xpsnr: remove duplicated DSP infranstructure
Fully reuse the existing one from vf_psnr, instead of halfways.

Signed-off-by: James Almer <jamrial@gmail.com>
2024-10-07 09:33:52 -03:00
Marvin Scholz
29d7ed089e lavfi/vf_psnr: use av_err2str to simplify code
No need to explicitly specify the buffer here as it is only
ever passed to av_log, so av_err2str can be used.
2024-09-13 00:21:02 +02:00
Anton Khirnov
6d75d44d90 lavfi: drop internal.h
All that remains in it are things that belong in avfilter_internal.h.

Move them there and remove internal.h
2024-08-19 21:48:04 +02:00
Anton Khirnov
a23d565ea7 lavfi: move AVFilterLink.frame_rate to FilterLink
Co-developed-by: James Almer <jamrial@gmail.com>
2024-08-15 19:34:27 +02:00
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
Chema Gonzalez
7311fcc869 lavfi/vf_psnr: add warning when color ranges differ
The PSNR 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 a simple black pixel/white pixel image.
```
$ echo -n -e "\x00\x00\x00\xff\xff\xff" > /tmp/foo.rgb24
```

(2) From this image, let's distill full and limited range y4m
copies.

```
$ ffmpeg -y -f rawvideo -video_size 2x1 -pix_fmt rgb24 -i /tmp/foo.rgb24 -vf scale="out_range=full" -pix_fmt yuv420p /tmp/foo.full.y4m
$ xxd /tmp/foo.full.y4m
00000000: 5955 5634 4d50 4547 3220 5732 2048 3120  YUV4MPEG2 W2 H1
00000010: 4632 353a 3120 4970 2041 303a 3020 4334  F25:1 Ip A0:0 C4
00000020: 3230 6a70 6567 2058 5953 4353 533d 3432  20jpeg XYSCSS=42
00000030: 304a 5045 4720 5843 4f4c 4f52 5241 4e47  0JPEG XCOLORRANG
00000040: 453d 4655 4c4c 0a46 5241 4d45 0a00 ff80  E=FULL.FRAME....
00000050: 80                                       .
```

and

```
$ ffmpeg -y -f rawvideo -video_size 2x1 -pix_fmt rgb24 -i /tmp/foo.rgb24 -vf scale="out_range=limited" -pix_fmt yuv420p /tmp/foo.limited.y4m
$ xxd /tmp/foo.limited.y4m
00000000: 5955 5634 4d50 4547 3220 5732 2048 3120  YUV4MPEG2 W2 H1
00000010: 4632 353a 3120 4970 2041 303a 3020 4334  F25:1 Ip A0:0 C4
00000020: 3230 6a70 6567 2058 5953 4353 533d 3432  20jpeg XYSCSS=42
00000030: 304a 5045 4720 5843 4f4c 4f52 5241 4e47  0JPEG XCOLORRANG
00000040: 453d 4c49 4d49 5445 440a 4652 414d 450a  E=LIMITED.FRAME.
00000050: 10eb 8080                                ....
```

Note that the 2x images are the same (both have 1x pixel at the
darkest black, and one at the brightest white). Only difference
is the range.

(3) Let's calculate the PSNR score:
```
$ ./ffmpeg -filter_threads 1 -filter_complex_threads 1 -i /tmp/foo.full.y4m -i /tmp/foo.limited.y4m -lavfi "psnr" -f null -
...
[Parsed_psnr_0 @ 0x2f5dac0] PSNR y:22.972065 u:inf v:inf average:25.982365 min:25.982365 max:25.982365
```

As we are comparing an image with itself, we expect "y:inf" as the
luma PSNR. Issue here is that the PSNR filter just uses the pixel
values, ignoring the color ranges.

A possible solution would be to have the filter do the conversion.

Proposed solution is to add a warning.

```
$ ./ffmpeg -filter_threads 1 -filter_complex_threads 1 -i /tmp/foo.full.y4m -i /tmp/foo.limited.y4m -lavfi "psnr" -f null -
...
[Parsed_psnr_0 @ 0x2f5dac0] master and reference frames use different color ranges (pc != tv)
...
[Parsed_psnr_0 @ 0x2f5dac0] PSNR y:22.972065 u:inf v:inf average:25.982365 min:25.982365 max:25.982365
```

Tested:

Ran fate.
```
$ make fate -j
...
TEST    seek-lavf-ppmpipe
TEST    seek-lavf-pgmpipe
TEST    seek-lavf-mxf_opatom
```
2023-09-23 15:55:44 +01:00
Andreas Rheinhardt
72c601e0f7 avutil/internal: Move avpriv-file API to a header of its own
It is not used by the large majority of files that include
lavu/internal.h.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-09-03 15:41:44 +02:00
Andreas Rheinhardt
40e6575aa3 all: Replace if (ARCH_FOO) checks by #if ARCH_FOO
This is more spec-compliant because it does not rely
on dead-code elimination by the compiler. Especially
MSVC has problems with this, as can be seen in
https://ffmpeg.org/pipermail/ffmpeg-devel/2022-May/296373.html
or
https://ffmpeg.org/pipermail/ffmpeg-devel/2022-May/297022.html

This commit does not eliminate every instance where we rely
on dead code elimination: It only tackles branching to
the initialization of arch-specific dsp code, not e.g. all
uses of CONFIG_ and HAVE_ checks. But maybe it is already
enough to compile FFmpeg with MSVC with whole-programm-optimizations
enabled (if one does not disable too many components).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-06-15 04:56:37 +02:00
softworkz
f579a1d08b avfilter: use avpriv_fopen_utf8() instead of plain fopen()
Unify file access operations by replacing usages of direct calls
to posix fopen() to prepare for long filename support on Windows.

Signed-off-by: softworkz <softworkz@hotmail.com>
Signed-off-by: Martin Storsjö <martin@martin.st>
2022-05-24 11:50:24 +03:00
Anton Khirnov
b9c928a486 avfilter: add AVFILTER_FLAG_METADATA_ONLY
This flag allows distinguishing between filters that actually modify the
data and those that only modify metadata or gather some stream
information.
2021-12-04 14:07:19 +01:00
Paul B Mahol
8c2f142bd9 avfilter/vf_psnr/ssim: fix typos 2021-10-28 21:12:09 +02: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
860b395514 avfilter/vf_psnr: Use formats list instead of query function
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-05 18:58:26 +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
63cc7077c1 avfilter/vf_psnr: 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:57:20 +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
Limin Wang
8410000f17 avfilter/vf_psnr: remove unnecessary check
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2021-05-01 08:45:30 +08: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
680ba23bc2 avfilter/vf_psnr: add support for slice threading 2021-02-19 21:15:08 +01:00
Paul B Mahol
6c52c27d3d avfilter/vf_psnr: remove precision limits for metadata values 2021-02-12 23:22:32 +01:00
Paul B Mahol
735ec7666b avfilter/vf_psnr: add timeline support 2021-02-12 21:21:25 +01:00
Paul B Mahol
5c9a4ff8c1 avfilter/vf_psnr: fix logic failure when comparing time bases 2020-02-01 21:10:25 +01:00
Paul B Mahol
9e283aa24e avfilter/vf_psnr,vf_ssim: add warning if different timebases are encountered 2019-10-25 22:02:41 +02:00
Paul B Mahol
bd6c57d532 avfilter: add support for gray14 format 2018-09-09 19:10:44 +02:00
Paul B Mahol
cfd52094c0 avfilter/vf_psnr: add more gbrap formats
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2017-12-20 12:45:21 +01:00
Carl Eugen Hoyos
5d3e935728 lavfi: Rename local variables "main" as "master".
Silences several warnings:
main is usually a function
2017-10-07 20:49:48 +02:00
Nicolas George
5f5dcf44e3 lavfi: rename framesync2 to framesync. 2017-09-12 11:03:51 +02:00
Nicolas George
3bd11df459 lavfi/vf_psnr: convert to framesync2. 2017-08-29 10:19:04 +02:00
Paul B Mahol
bac508fec1 avfilter: add support for GRAY9 and GBRAP10 2017-08-07 13:11:09 +02:00
Muhammad Faiz
6af050d7d0 avfilter: do not use AVFrame accessor
Reviewed-by: wm4 <nfxjfg@googlemail.com>
Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>
2017-04-23 14:40:30 +07:00
Clément Bœsch
4ea8f57548 lavfi/psnr: rename pow2 to pow_2
This conflict with the DJGPP libc which includes a pow2 function¹

We cannot make DJGPP POSIX only (using -D_POSIX_SOURCE) to avoid this
kind of symbols conflicts due to the lack of both posix_memalign and
memalign (DJGPP non standard function) in that POSIX mode. We currently
rely on memalign for aligned heap allocation.

[1]: http://www.delorie.com/djgpp/doc/libc-2.02/libc_536.html
2017-03-29 14:49:29 +02:00
Paul B Mahol
9933579a9b avfilter/vf_psnr: add gray10 and gray12 support
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2016-12-21 21:37:22 +01:00
Lucas Cooper
aabe12eba3 avfilter/vf_psnr: Add max value output option to psnr stats log.
This allows retroactive calculation/aggregation of PSNR from the stats
log.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-09-01 11:54:31 +02:00
Lucas Cooper
bc9ce5f6be avfilter: Add new format for PSNR stats log
Add an AVOption stats_version with a new header for V2 stats, which
specifies the stats log version and lists the fields that will be
present in the log (to ease parsing).

The primary motivation is to facilitate the addition of optional fields
to the log without breaking backwards compatibility, while making the
logs easier to parse.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-07-29 20:49:53 +02:00
Michael Niedermayer
9264bb7e79 avfilter/vf_psnr: Fix rounding error in average_max
The intermediate was rounded to an integer

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-07-21 11:26:28 +02:00
Derek Buitenhuis
21f9468402 avutil: Rename FF_CEIL_COMPAT to AV_CEIL_COMPAT
Libav, for some reason, merged this as a public API function. This will
aid in future merges.

A define is left for backwards compat, just in case some person
used it, since it is in a public header.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2016-01-27 16:36:46 +00:00
Ganesh Ajjanagadde
59d37f5a4e avfilter/vf_psnr: use log10 instead of log()/log(10)
This is likely more precise and conveys the intent better.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-10-29 18:53:11 -04:00
Ronald S. Bultje
0c7b44a01c vf_psnr/ssim: don't crash if stats_file is NULL. 2015-10-23 06:38:30 -04:00
Ronald S. Bultje
81d7f118e2 vf_psnr: remove %0.2f format specifiers for stream summary line.
This makes output equally precise as vf_ssim.
2015-10-22 17:18:15 -04:00
Tobias Rapp
1ec8c1554e avfilter/vf_psnr: Add support for writing stats to stdout
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-10-21 00:39:50 +02:00
Hendrik Leppkes
5d8e836d0e Replace all remaining occurances of step/depth_minus1 and offset_plus1 2015-09-08 17:10:48 +02:00
Ronald S. Bultje
22b30f925d vf_psnr: add psnr_avg to stats file. 2015-08-05 09:19:09 -04:00
James Almer
222d7619ce avfilter/vf_pnsr: fix author name
Signed-off-by: James Almer <jamrial@gmail.com>
2015-07-29 22:28:09 -03:00
Ronald S. Bultje
ae4c9ddebc vf_psnr: sse2 optimizations for sum-squared-error.
The internal line accumulator for 16bit can overflow, so I changed that
from int to uint64_t in the C code. The matching assembly looks a little
weird but output looks correct.

(avx2 should be trivial to add later.)

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-14 17:57:14 +02:00
Ronald S. Bultje
3bb58c377b vf_psnr: fix rgb channel order mixup in final log message.
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-11 19:13:57 +02:00
Ronald S. Bultje
9879421f1a vf_psnr: always calculate MSE over full pixel range.
This makes the output compatible with that of pretty much any other
tool that calculates PSNR.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-11 18:47:05 +02:00
Ronald S. Bultje
c381af77c5 vF_psnr: move set_meta() calls out of loop.
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-11 12:48:58 +02:00
Ronald S. Bultje
0303d43964 vf_psnr: add channel weighting based on chroma subsampling.
Also add per-channel psnr stream averages to final log message.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-11 04:14:09 +02:00