Commit Graph

37 Commits

Author SHA1 Message Date
Haihao Xiang a1b3e8f2d7 lavfi/vf_vpp_qsv: add vpp_preinit callback
Set the expected default value for options in this callback, hence we
have the right values even if these options are not included in the
option arrray.

This is in preparation for reusing the code for other QSV filters.

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2023-01-17 10:10:52 +08:00
Haihao Xiang eb71c67dcc lavfi/vf_vpp_qsv: allow special values for the output video dimensions
Special values are:
0 = original width/height
-1 = keep original aspect

This is in preparation for reusing the code for other QSV filters.

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2023-01-17 10:10:52 +08:00
Haihao Xiang 129530e917 lavfi/vf_vpp_qsv: handle NULL pointer when evaluating an expression
This patch provides default value if the expression is NULL.

This is in preparation for reusing the code for other QSV filters.

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2023-01-17 10:10:52 +08:00
Haihao Xiang 24a8e1e126 lavfi/vf_vpp_qsv: add "a", "dar" and "sar" variables
Also fix the naming style in enum var_name.

This is in preparation for reusing the code for other QSV filters.

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2023-01-17 10:10:52 +08:00
Haihao Xiang 3552dba0e1 lavfi/vf_vpp_qsv: accept P010 input in system memory
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2022-12-08 14:25:52 +08:00
Haihao Xiang e5faa1d50c lavfi/vf_vpp_qsv: allow user to set scale_mode with constants
$ ffmpeg -f lavfi -i testsrc -vf "format=nv12,vpp_qsv=scale_mode=hq" -f
null -

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2022-12-08 14:24:21 +08:00
Haihao Xiang d51edd225d lavfi/vf_vpp_qsv: use macros for extra mfx parameter
Make it easy to add new extra mfx parameter buffer. No functional
change.

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2022-12-08 14:22:12 +08:00
Wenbin Chen 20f2941191 libavfilter/qsvvpp: Change the alignment to meet the requirement of YUV420P format
When process yuv420 frames, FFmpeg uses same alignment on Y/U/V
planes. VPL and MSDK use Y plane's pitch / 2 as U/V planes's
pitch, which makes U/V planes 16-bytes aligned. We need to set
a separate alignment to meet runtime's behaviour.

Now alignment is changed to 16 so that the linesizes of U/V planes
meet the requirment of VPL/MSDK. Add get_buffer.video callback to
qsv filters to change the default get_buffer behaviour.

Now the commandline works fine:
ffmpeg -f rawvideo -pix_fmt yuv420p -s:v 3082x1884 \
-i ./3082x1884.yuv -vf 'vpp_qsv=w=2466:h=1508' -f rawvideo \
-pix_fmt yuv420p 2466_1508.yuv

Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
2022-12-08 14:21:07 +08:00
Haihao Xiang 0ae459176b lavfi/vf_vpp_qsv: scale_mode can be applied to color conversion
Reviewed-by: Soft Works <softworkz@hotmail.com>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2022-12-01 09:40:40 +08:00
Fei Wang 6ec127b223 avfilter/vf_vpp_qsv: set outlink to EOF correctly
1. Return error if filter frame fail before set outlink to EOF in none
pass through mode.
2. Set outlink to EOF before return success in pass through mode.

Fix endless cmd:

ffmpeg -hwaccel qsv -qsv_device /dev/dri/renderD128 -hwaccel_output_format     \
qsv -v debug -c:v hevc_qsv -i 4k.h265                                          \
-filter_complex "vpp_qsv=w=3840:h=2160:async_depth=4[o1];[o1]split=2[s1][s2];
[s2]vpp_qsv=w=1920:h=1080:async_depth=4[o2];[o2]split=2[s3][s4];
[s4]vpp_qsv=w=1920:h=1080:async_depth=4[o3]" \
-map [s1] -c:v hevc_qsv -async 3 -async_depth 3 -b:v 9000k -preset 7 -g 33 -y -f null - \
-map [s3] -c:v hevc_qsv -async 3 -async_depth 3 -b:v 4000k -preset 7 -g 33 -y -f null - \
-map [o3] -c:v hevc_qsv -async 3 -async_depth 3 -b:v 3100k -preset 7 -g 33 -y -f null -
2022-05-26 23:21:26 +08:00
Haihao Xiang 478e1a98a2 qsv: add requirement for the mininal version of libmfx
libmfx 1.28 was released 3 years ago, it is easy to get a greater
version than 1.28. We may remove lots of compile-time checks if adding
the requirement for the minimal version in the configure script.

Reviewed-by: softworkz <softworkz@hotmail.com>
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2022-05-25 15:17:35 +08:00
Andreas Rheinhardt ef92c352e7 avfilter/vf_vpp_qsv: Remove unnecessary lavc and lavf headers
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-03-23 23:45:38 +01:00
softworkz 479f3c6598 avfilter/vpp_qsv: fix regression on older api versions (e.g. 1.11)
Commit 8b83dad825 introduced a
regression in a way that scaling via vpp_qsv doesn't work any longer
for devices with an MSDK runtime version lower than 1.19. This is true
for older CPUs which are stuck at 1.11.
The commit added checks for the compile-sdk version but it didn't test
for the runtime version.

Signed-off-by: softworkz <softworkz@hotmail.com>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2022-01-10 14:54:36 +08: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
Wenbin Chen a822e70bec libavfilter/vf_vpp_qsv: fix uninitialized variable problem
This two variables may be used below with uninitialized value.
Now fix them.

Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
Reviewed-by: Xiang, Haihao <haihao.xiang@intel.com>
Reviewed-by: Soft Works <softworkz@hotmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-09-15 09:24:08 -03: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 ef54590f83 avfilter/internal: Don't include libavcodec/(avcodec|internal).h
The reasons for including them don't exist any longer: ff_tlog() has
been moved to libavutil/internal.h and FF_QSCALE_TYPE_* has been moved
to qp_table.h.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-05 21:15:25 +02:00
Andreas Rheinhardt cc6f6a1eef avfilter/vf_vpp_qsv: Don't overrun stack array
8b83dad825 added another potentially used
video enhancement filter without increasing a define for the number of
such options which is used as the size of stack array. This can lead to
a buffer overrun if all filters are used simultaneously. So increase
said number.

Fixes Coverity ticket #1489775.

Reviewed-by: Linjie Fu <linjie.justin.fu@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-04 12:50:37 +02:00
Fei Wang 8b83dad825 avfilter/vf_vpp_qsv: add scale mode option
The option allow user to set diffenent scaling mode from
auto/low-power/high-quality.

More details:
https://github.com/Intel-Media-SDK/MediaSDK/blob/master/doc/mediasdk-man.md#mfxExtVPPScaling

Signed-off-by: Fei Wang <fei.w.wang@intel.com>
Signed-off-by: Linjie Fu <linjie.justin.fu@gmail.com>
2021-08-03 22:20:00 +08:00
Andreas Rheinhardt 2934a4b9a5 Remove unnecessary avassert.h inclusions
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-07-22 15:02:30 +02:00
Haihao Xiang efc22e63e5 lavfi/vf_vpp_qsv: fix the time_base for outlink
Since commit 89ffcd1, the status pts of the output link is set to a
value in the input link time base, not in the output link time base when
EOF is reached. Usually this pst value is larger than the required one
because the output link time base is more greater than the input link
time base. When "-vf vpp_qsv,fps" is used, user has to wait a long time
for the ending of the pipeline because fps filter output a huge number
of frames until the wrong status pts is hit.

The issue can be triggered with the command below (use a clip with 1000
frames in this case):

$> time ffmpeg -hwaccel qsv -c:v hevc_qsv -i input.h265 -vf
"vpp_qsv=w=1920:h=1080,fps=fps=30" -f null -
...
[out_0_0 @ 0x564ccd27e020] 10000000 buffers queued in out_0_0, something
may be wrong.
frame=40119596 fps=88080 q=-0.0 Lsize=N/A time=371:28:39.96 bitrate=N/A
speed=2.94e+03x
video:17238889kB audio:0kB subtitle:0kB other streams:0kB global
headers:0kB muxing overhead: unknown

real    9m7.451s
user    2m34.102s
sys     0m39.734s

In order to avoid the above issue, the same time base for input and
ouput links is used in this patch.

Fixes ticket #9286

Signed-off-by: Zhong Li <zhongli_dev@126.com>
2021-06-20 23:05:03 +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
Fei Wang 89ffcd1bbe lavfi/qsvvpp: support async depth
Async depth will allow qsv filter cache few frames, and avoid force
switch and end filter task frame by frame. This change will improve
performance for some multi-task case, for example 1:N transcode(
decode + vpp + encode) with all QSV plugins.

Performance data test on my Coffee Lake Desktop(i7-8700K) by using
the following 1:8 transcode test case improvement:
1. Fps improved from 55 to 130.
2. Render/Video usage improved from ~61%/~38% to ~100%/~70%.(Data get
from intel_gpu_top)

test CMD:
ffmpeg -v verbose -init_hw_device qsv=hw:/dev/dri/renderD128 -filter_hw_device                 \
 hw -hwaccel qsv -hwaccel_output_format qsv -c:v h264_qsv -i 1920x1080.264                     \
-vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30 -preset 7 -g 33 -refs 2 -bf 3 -q 24 -f null - \
-vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30 -preset 7 -g 33 -refs 2 -bf 3 -q 24 -f null - \
-vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30 -preset 7 -g 33 -refs 2 -bf 3 -q 24 -f null - \
-vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30 -preset 7 -g 33 -refs 2 -bf 3 -q 24 -f null - \
-vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30 -preset 7 -g 33 -refs 2 -bf 3 -q 24 -f null - \
-vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30 -preset 7 -g 33 -refs 2 -bf 3 -q 24 -f null - \
-vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30 -preset 7 -g 33 -refs 2 -bf 3 -q 24 -f null -

Signed-off-by: Fei Wang <fei.w.wang@intel.com>
Reviewed-by: Linjie Fu <linjie.justin.fu@gmail.com>
Signed-off-by: Zhong Li <zhongli_dev@126.com>
2021-04-11 23:18:20 +08:00
Nicolas George 2f76476549 lavfi: regroup formats lists in a single structure.
It will allow to refernce it as a whole without clunky macros.

Most of the changes have been automatically made with sed:

sed -i '
  s/-> *in_formats/->incfg.formats/g;
  s/-> *out_formats/->outcfg.formats/g;
  s/-> *in_channel_layouts/->incfg.channel_layouts/g;
  s/-> *out_channel_layouts/->outcfg.channel_layouts/g;
  s/-> *in_samplerates/->incfg.samplerates/g;
  s/-> *out_samplerates/->outcfg.samplerates/g;
  ' src/libavfilter/*(.)
2020-09-08 14:02:40 +02:00
Andreas Rheinhardt c4beb0783b avfilter/vf_vpp_qsv: Fix leak of AVFilterFormats on error
The vpp_qsv's query_formats function allocated two AVFilterFormats,
before storing them permanently. If storing the first of them fails,
the function simply returns and the second leaks. This has been fixed by
only allocating the second AVFilterFormats structure after the first one
has been successfully stored.

Fixes Coverity issue #1422231.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-23 23:09:32 +02:00
Paul B Mahol d64cbd4fda remove CHAR_MIN/CHAR_MAX usage
It is not needed at all.
2020-03-17 22:46:36 +01:00
Zhong Li 74e6800381 lavfi/qsvvpp: disable pass through mode if format changed
Partly fix tiket#8065

Signed-off-by: Zhong Li <zhong.li@intel.com>
2019-08-20 14:11:26 +08:00
Linjie Fu af3ddd581f lavf/vf_vpp_qsv: add support for QSV transpose filter
Add transpose support for qsv_vpp with rotate and hflip:
    - rotate: [0, 3] support clockwise rotation of 0, 90, 180, 270;
    - hflip:  [0, 1] support horizontal flip;

Configure with:
{"cclock_hflip","clock","cclock","clock_hflip","reversal","hflip","vflip"}

CMD:
ffmpeg -hwaccel qsv -c:v h264_qsv -i input.h264
    -vf 'format=qsv,vpp_qsv=transpose=clock' -c:v h264_qsv output.h264

ffmpeg -init_hw_device qsv=hw -filter_hw_device hw -c:v h264_qsv -i input.h264
    -vf 'hwupload=extra_hw_frames=64,format=qsv,vpp_qsv=transpose=cclock_hflip'
                            -f rawvideo -pix_fmt nv12 ./transpose.yuv

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
Signed-off-by: Zhong Li <zhong.li@intel.com>
2019-08-07 20:58:49 +08:00
Zhong Li 4208b428c4 lavf/qsv_vpp: add frame format option
1. Currently output format is hard-coded as NV12, thus means
   CSC is always done for not NV12 input such as P010.
   Follow original input format as default output.
2. Add an option to specify output format.

Signed-off-by: Zhong Li <zhong.li@intel.com>
2019-06-14 10:27:33 +08:00
Zhong Li e62f625163 lavf/qsvvpp: add P010 output format support
Signed-off-by: Zhong Li <zhong.li@intel.com>
2019-06-10 13:48:41 +08:00
Ruiling Song d865783b6c lavf/qsv: clone the frame which may be managed by framework
For filters based on framesync, the input frame was managed
by framesync, so we should not directly keep and destroy it,
instead we make a clone of it here, or else double-free will occur.
But for other filters not based on framesync, we still need to
free the input frame inside filter_frame.

Signed-off-by: Ruiling Song <ruiling.song@intel.com>
2018-04-21 19:00:43 +01:00
James Almer ae7e66fb4b Merge commit '29a8ed766354c45c9be4b8512c5b2eb25a450cdc'
* commit '29a8ed766354c45c9be4b8512c5b2eb25a450cdc':
  lavf/qsvvpp: bypass vpp if not needed.

Merged-by: James Almer <jamrial@gmail.com>
2018-04-13 19:58:47 -03:00
Zhong Li 29a8ed7663 lavf/qsvvpp: bypass vpp if not needed.
Currently vpp pipeline is always created, even for the unnecessary
cases such as setting the option "vpp_qsv=w=1280:h=720" for an input
with native resolution 1280x720. Thus introduces unnecessary performance
dropping, so bypass vpp if not needed.

Signed-off-by: Zhong Li <zhong.li@intel.com>
Signed-off-by: Maxym Dmytrychenko <maxim.d33@gmail.com>
2018-04-08 20:47:59 +02:00
Zhong Li f7d77b4112 lavf/qsv_vpp: check the return value of ff_formats_ref()
Fixes the build warning of "ignoring return value of ‘ff_formats_ref’,
declared with attribute warn_unused_result"

Signed-off-by: Zhong Li <zhong.li@intel.com>
Reviewed-by: Carl Eugen Hoyos <ceffmpeg@gmail.com>
Signed-off-by: Mark Thompson <sw@jkqxz.net>
2017-11-20 15:47:05 +00:00
Michael Niedermayer 1828c549c3 avfilter/vf_*_qsv: Fix flags
Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-13 03:58:34 +01:00
James Almer 4391d6cb81 Merge commit 'a5a6ac1a123a927e5bed984ed757a29b7ff87dab'
* commit 'a5a6ac1a123a927e5bed984ed757a29b7ff87dab':
  libavfilter/overlay_qsv: Add QSV overlay vpp filter
  libavfilter/vf_vpp: Add common filters of the qsv vpp

Merged-by: James Almer <jamrial@gmail.com>
2017-11-11 15:07:06 -03:00
Huang, Zhengxu 8d3666c425 libavfilter/vf_vpp: Add common filters of the qsv vpp
Add common filters of the qsv vpp features including scale,denosie,
deinterlace,frc,crop and procAmp.

Performance will be significantly reduced in the test if using cascade
mode just like qsv framerate + qsv scale + qsv deinterlace + qsv denoise in
separated way no matter in system or video memmory cases.
And the code is so redundant because so much the same just as session and
surface's creation and management.
So we add a common qsv filter.

Usage:
-hwaccel qsv -c:v h264_qsv -r 25 -i in -vf
vpp_qsv=w=iw/2:h=400:deinterlace=1:framerate=60:detail=50:denoise=50
-b 2M -maxrate 3M -c:v h264_qsv -y out.h264

Signed-off-by: ChaoX A Liu <chaox.a.liu@gmail.com>
Signed-off-by: Zhengxu Huang <zhengxu.maxwell@gmail.com>
Signed-off-by: Andrew Zhang <huazh407@gmail.com>
Change-Id: I130392ce722138c209ab658c5f03f0009b6e8024
Signed-off-by: Maxym Dmytrychenko <maxim.d33@gmail.com>
2017-09-17 19:57:13 +02:00