1
mirror of https://git.videolan.org/git/ffmpeg.git synced 2024-09-05 07:48:07 +02:00
Commit Graph

172 Commits

Author SHA1 Message Date
Andreas Rheinhardt
9348d06fc6 avcodec/qsvenc: Remove dead code for user-provided buffers
Dead since commit 93016f5d1d
which ensured that the packets received by encoders are always blank.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-25 22:58:17 +02:00
Andreas Rheinhardt
dd0a7fdfc0 avcodec/qsvenc: Fix memleaks upon allocation errors
Fixes leaks in case the allocation of the H.264-specific stuff fails.
Fixes Coverity issues #1442911 and #1442914.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-25 22:58:17 +02:00
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
Xu Guangxin
3bbe0c210b avcodec/qsv_enc: do not reuse enc_ctrl from previous frames
fixes #8857

If we do not clear the enc_ctrl, we will reuse previous frames' data like FrameType.

Reviewed-by: Xiang, Haihao <haihao.xiang@intel.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-09-09 12:53:25 -03:00
Haihao Xiang
115f5e8035 lavc/qsvenc: allows the SDK runtime to choose LowPower/non-LowPower modes
The SDK supports LowPower and non-LowPower modes, but some features are
available only under one of the two modes. Currently non-LowPower mode
is always chosen in FFmpeg if the mode is not set to LowPower
explicitly. User will experience some SDK errors if a LowPower related
feature is specified but the mode is not set to LowPower. With this
patch, the mode is set to unknown by default in FFmpeg, the SDK is able
to choose a workable mode for the specified features.

Reviewed-by: Soft Works <softworkz@hotmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-08-12 22:25:11 -03:00
Haihao Xiang
65fdc0e589 lavc/qsvenc: pass the color properties to the SDK
Otherwise the color properties won't be encoded into the bitstream
header

Reviewed-by: Xiang, Haihao <haihao.xiang@intel.com>
Reviewed-by: Soft Works <softworkz@hotmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-08-04 10:06:26 -03:00
Haihao Xiang
f2feb31b78 qsvenc: Value '0' is not a valid value for parameter GopOptFlag
The accepted values for GopOptFlag are MFX_GOP_CLOSED (1) and
MFX_GOP_STRICT (2).

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
Signed-off-by: Zhong Li <zhongli_dev@126.com>
2021-07-27 23:48:53 +08:00
Gyan Doshi
1aa9dcd091 avcodec/qsvenc: clip global_quality for ICQ modes.
Allowed range is 1 to 51.

Ref: https://software.intel.com/content/www/us/en/develop/articles/advanced-bitrate-control-methods-in-intel-media-sdk.html
2021-07-12 09:33:22 +05:30
Haihao Xiang
9583e66ea0 qsvenc_hevc: allow user set more coding options
The SDK supports NalHrdConformance, RecoveryPointSEI and AUDelimiter for
hevc encoder, so we may allow user to set these coding options like as
what we did for h264_qsv encoder.

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
Signed-off-by: Zhong Li <zhongli_dev@126.com>
2021-07-02 23:38:36 +08:00
Andreas Rheinhardt
11bc790893 avcodec: Remove deprecated AVCodecContext.coded_frame
Deprecated in 40cf1bbacc.
(The currently disabled filter vf_mcdeint and vf_uspp were users of
this field; they have not been changed, so that whoever wants to fix
them can see the state of these filters when they were disabled.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:12 -03:00
Andreas Rheinhardt
d85c41b572 avcodec: Remove private options from AVCodecContext
Several options that were too codec-specific were deprecated between
0e6c853221 and
0e9c4fe254.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:02 -03:00
Andreas Rheinhardt
78ce00428f avcodec: Remove deprecated coder type options
Deprecated in be00ec832c.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:01 -03:00
Haihao Xiang
b8cd37a59f qsv: dump more info in error, debug and verbose mode
Dump iopattern mode and the SDK error/warning desciptions for qsv based
filters and iopattern mode for qsvenc

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
Signed-off-by: Linjie Fu <linjie.justin.fu@gmail.com
2021-01-23 16:10:16 +00:00
Mark Thompson
cd322794ee lavc: Mark hw_config pointer arrays as const
They are read-only just like the HWConfig structures they point to.
2020-11-08 18:54:42 +00:00
Linjie Fu
c2d000ec27 lavc/qsvenc_hevc: add qmax/qmin support for HEVC encoding
Add qmax/qmin support for HEVC software bitrate control(SWBRC).

Limitations:
    - RateControlMethod != MFX_RATECONTROL_CQP
    - with EXTBRC ON

Signed-off-by: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
Signed-off-by: Linjie Fu <linjie.fu@intel.com>
Signed-off-by: Zhong Li <zhongli_dev@126.com>
2020-07-05 23:43:45 +08:00
James Almer
6e1903938b avcodec/internal: move packet related functions to their own header
Signed-off-by: James Almer <jamrial@gmail.com>
2020-06-02 19:02:12 -03:00
Linjie Fu
8999a2f21d lavc/qsvenc: add encode support for HEVC 4:2:2 8-bit and 10-bit
Enables HEVC Range Extension encoding support (Linux) for 4:2:2 8/10 bit
on ICL+ (gen11 +) platform.

Restricted to linux only for now.

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
2020-05-18 13:33:29 +08:00
Mark Thompson
5a1ff44907 lavc/qsvenc: Add hardware config metadata
All of these encoders can accept libmfx surfaces directly in a hardware
frames context, or they can accept software frames if a suitable device
is supplied to use.
2020-04-26 18:38:25 +01:00
Carl Eugen Hoyos
d46a91b7f3 lavc/qsvenc: Fix format specifiers for two variables of type int. 2020-04-04 23:18:08 +02:00
Linjie Fu
ebee808595 lavc/qsvenc: add support for external bitrate control for HEVC
Enables option for hevc_qsv encoder:
    -extbrc

Improvements in BD-Rate could be observed with extbrc on.

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
Signed-off-by: Zhong Li <zhongli_dev@126.com>
2020-02-18 10:27:54 +08:00
JonCookCubic
566de25599 libavcodec/qsvenc.c: Set mjpeg height and width alignment
Currently width_align and height_align are zero when encoding with mjpeg_qsv,
which causes "Error submitting the frame for encoding". This patch sets the alignments.

There is a little bit more about the problem here http://ffmpeg.org/pipermail/ffmpeg-user/2019-November/046143.html

Signed-off-by: JonCookCubic <jon.cook@cubicmotion.com>
Signed-off-by: Zhong Li <zhongli_dev@126.com>
2020-02-18 10:21:02 +08:00
Linjie Fu
8446318502 lavc/qsvenc: add Tiles encode support for HEVC
Add -tile_rows and -tile_cols option to specify the number of tile rows
and columns for ICL+ (gen 11) platform.

A tile must wholly contain all the slices within it. Slices cannot cross
tile boundaries. So the slice number would be implicitly resized to the
max(nSlice, nTile).

Example:
    ffmpeg -v verbose -hwaccel qsv -init_hw_device qsv=hw
    -filter_hw_device hw -f rawvideo -s:v 1920x1080 -i ./input.nv12 -vf
    format=nv12,hwupload=extra_hw_frames=64 -c:v hevc_qsv -tile_rows 2
    -tile_cols 2 -slices 4 -y output.h265

Also dump the actual quantity of encoded tiled rows and columns in run
time.

Fix the enhancement #8400.

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
2019-12-12 23:43:06 +08:00
Linjie Fu
df625057af lavc/qsvenc: Fix some code indentations
Signed-off-by: Linjie Fu <linjie.fu@intel.com>
2019-11-28 23:34:40 +08:00
Carl Eugen Hoyos
a2fbdc6898 lavc/qsvenc: Fix compilation for some build environments.
Reported and tested by Sean Darcy.
2019-11-27 00:03:33 +01:00
Zhong Li
33583803e1 lavc/qsvenc: enable vp9 encoder
1. must enable low_power mode since just VDENC can be supported by iHD
driver right now
2. Coding option1 and extra_data are not supported by MSDK
3. IVF header will be inserted in MSDK by default, but it is not needed
for FFmpeg, so disable it.

Signed-off-by: Zhong Li <zhongli_dev@126.com>
2019-11-03 16:45:35 +08:00
Linjie Fu
e786e37326 lavc/qsvenc: Fix bitrate_limit to allow AVC encode in limited bitrate
MFXVideoENCODE_Query calls CheckVideoParamQueryLike in MSDK and
will determine whether to set param.mfx.TargetKbps to the allowed
minTargetKbps according to the bitrate_limit in extco2 buffer.

Thus q->param.ExtParam must be set before MFXVideoENCODE_Query in case
minTargetKbps is written to TargetKbps by default.

1080P AVC encoding with option "-bitrate_limit 0 -b:v 100k":
Before patch:
            902 kbps
After patch:
            156 kbps
Signed-off-by: Linjie Fu <linjie.fu@intel.com>
2019-11-03 16:22:47 +08:00
Linjie Fu
5345965b3f lavc/qsvdec: Add GPU-accelerated memory copy support
GPU copy enables or disables GPU accelerated copying between video
and system memory. This may lead to a notable performance improvement.
Memory must be sequent and aligned with 128x64.

CMD:
ffmpeg -init_hw_device qsv=hw -filter_hw_device hw -c:v h264_qsv
                    -gpu_copy on -i input.h264 -f null -
or:
ffmpeg -c:v h264_qsv -gpu_copy on -i input.h264 -f null -

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
Signed-off-by: ChaoX A Liu <chaox.a.liu@intel.com>
Signed-off-by: Zhong Li <zhong.li@intel.com>
2019-10-09 11:27:34 +08:00
Zhong Li
74007dd86a lavc/qsv: Fix MSDK initialization failure in system memory mode
MSDK does not create internal acceleration device on Linux,
So MFXVideoCORE_SetHandle() is necessary.
It has been added for ff_qsv_init_session_device().
But missed for ff_qsv_init_internal_session() due to commit
1f26a23 overwrited commit db89f45

Fix #7030

Signed-off-by: Zhong Li <zhong.li@intel.com>
2019-09-26 13:44:02 +08:00
Zhong Li
4dc3d93880 lavc/qsvenc: fix the incorrent map from bits to bytes
Reported-by:Maggie Sun <maggie.sun@intel.com>
Signed-off-by: Zhong Li <zhong.li@intel.com>
2019-07-01 13:24:01 +08:00
Linjie Fu
8f6e651833 lavc/qsvenc: Fix the memory leak for enc_ctrl.Payload
frame->enc_ctrl.Payload is malloced in get_free_frame, directly memset
the whole structure of enc_ctrl to zero will cause the memory leak for
enc_ctrl.Payload.

frame->enc_ctrl as a structure will be malloc and init to zero by calling
frame = av_mallocz(sizeof(*frame)), so the memset is redundant and can
be removed.

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
Signed-off-by: Zhong Li <zhong.li@intel.com>
2019-05-22 22:16:21 +08:00
Zhong Li
1125277bc6 lavc/qsvenc: enable hevc gpb option
GPB is the default type, just contains forward references but the
slice_type is B slice with higher encoding efficiency than regular P
slice, but lower performance.

Add an option to allow user to set regular P slice.

Fix ticket#6870

Test data on Intel Kabylake (i7-7567U CPU @ 3.50GHz):
1. ffmpeg -hwaccel qsv -c:v h264_qsv -i bbb_sunflower_1080p_30fps_normal.mp4 -vsync passthrough
-vframes 1000  -c:v hevc_qsv -gpb 0 -bf 0 -q 25 test_gpb_off_bf0_kbl.mp4

transcoding fps: 85
encoded file size of test_gpb_off_bf0_kbl.mp4: 21960100 (bytes)

2. ffmpeg -hwaccel qsv -c:v h264_qsv -i bbb_sunflower_1080p_30fps_normal.mp4 -vsync passthrough
-vframes 1000  -c:v hevc_qsv -gpb 1 -bf 0 -q 25 test_gpb_on_bf0_kbl.mp4

transcoding fps: 79
encoded file size oftest_gpb_on_bf0_kbl.mp4:  21211449 (bytes)

In this case, enable gpb can bring about 7% performance drop but 3.4% encoding efficiency improvment.

Signed-off-by: Zhong Li <zhong.li@intel.com>
2019-04-03 23:00:15 +08:00
Zhong Li
c745bedd18 lavc/qsvenc: enable hevc coding options configuration
Signed-off-by: Zhong Li <zhong.li@intel.com>
2019-04-03 22:57:55 +08:00
Zhong Li
d071a1117d lavc/qsvenc: get vps extradata from MSDK
Signed-off-by: Zhong Li <zhong.li@intel.com>
Reviewed-by: Mark Thompson <sw@jkqxz.net>
2019-04-01 19:21:48 +08:00
Linjie Fu
a8355eed36 lavc/qsvenc: expose low_power as a common option for QSV encoder
Always exposes low_power option for all qsv encoder, and reports a warning
if VDENC is not supported in current version of MSDK.

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
Signed-off-by: Zhong Li <zhong.li@intel.com>
2019-04-01 19:21:42 +08:00
Zhong Li
b9a066ae23 lavc/qsvenc: use the common option "trellis" of AVCodecContext
Signed-off-by: Zhong Li <zhong.li@intel.com>
2019-03-28 21:50:01 +08:00
Zhong Li
b47446cc39 lavc/qsvenc: make the queried libmfx version easily reused
Signed-off-by: Zhong Li <zhong.li@intel.com>
2019-03-28 21:48:09 +08:00
Zhong Li
74cf2dc3ac lavc/qsvenc: enable QVBR mode
QVBR mode is to use the variable bitrate control algorithm
with constant quality.
mfxExtCodingOption3 should be supported to enable QVBR mode.

It is neccesary to specify a max_rate for QVBR, else it may be ICQ mode.
Example usage: ffmpeg -hwaccel qsv -c:v h264_qsv -i input.mp4 -c:v
h264_qsv -global_quality 25 -maxrate 2M test_qvbr.mp4 -v verbose

Clip QVBR quality range to be [0, 51] as Mark's commments.
It is similar to qp range of CQP but possibly should be updated when VP8/VP9
encoding can be supported.

Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: Zhong Li <zhong.li@intel.com>
2019-01-25 16:53:27 +08:00
Zhong Li
87c165c237 lavc/qsvenc: set BRCParamMultiplier to aviod BRC overflow
Fix ticket #7663

Reviewed-by: Carl Eugen Hoyos <ceffmpeg@gmail.com>
Reviewed-by: Hendrik Leppkes <h.leppkes@gmail.com>
Signed-off-by: Zhong Li <zhong.li@intel.com>
2019-01-22 10:44:39 +08:00
Zhong Li
0aaaca25e0 lavc/qsvenc: set pict_type to be I for IDR frames.
Signed-off-by: Zhong Li <zhong.li@intel.com>
2019-01-10 21:48:27 +08:00
Linjie Fu
e92ce340e6 lavc/qsvenc: add VDENC support for H264
Add VDENC(lowpower mode) support for QSV H264

It's an experimental function(like lowpower in vaapi) with
some limitations:
- CBR/VBR require HuC which should be explicitly loaded via i915
module parameter(i915.enable_guc=2 for linux kernel version >= 4.16)

Use option "-low_power 1" to enable VDENC.
Add in dump_video_param() to show the status of VDENC in runtime log.

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
Signed-off-by: Zhong Li <zhong.li@intel.com>
2019-01-10 21:48:07 +08:00
Michael Niedermayer
3e461f9d4c avcodec/qsvenc: Fix Unkown typo
Reviewed-by: Lou Logan <lou@lrcd.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-12-31 02:37:08 +01:00
Linjie Fu
1c96d2e399 lavc/qsvenc: replace assert with error return
Fix the (m)jpeg encoding regression issue as decription in tikect #7593,
due to bs->FrameType is not set in such case in
MSDK (https://github.com/Intel-Media-SDK/MediaSDK/issues/970).
(And assert on a value coming from an external library is not proper.)

Add default type check for bs->FrameType, and return invalid data error in function
ff_qsv_encode to avoid using uninitialized value.

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
Signed-off-by: Zhong Li <zhong.li@intel.com>
2018-12-10 11:19:24 +08:00
Zhong Li
c9f0cff5ef lavc/qsvenc: add an option to set h264 pps for every frame
RepeatPPS is enabled by default in mfx. It is not necessary mostly and
wasting encoding bits.
Add an option to control it and disable it by default.

Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: Zhong Li <zhong.li@intel.com>
2018-12-07 17:13:36 +08:00
Zhong Li
c4a4cfa762 lavc/qsvenc: dump log for frame rate
Signed-off-by: Zhong Li <zhong.li@intel.com>
2018-12-07 17:12:07 +08:00
Zhong Li
33df1afe39 lavc/qsvenc: make hevc alignment same as h264 for 1.19+ version
It is to clean up to the code and To-Do list.

Signed-off-by: Zhong Li <zhong.li@intel.com>
2018-12-07 17:09:23 +08:00
Zhong Li
34cba65557 lavc/qsvenc: remove redundant code
Signed-off-by: Zhong Li <zhong.li@intel.com>
2018-12-07 17:05:56 +08:00
Linjie Fu
67cdfcf694 lavc/qsvenc: assert uninitialized pict_type
Assert in function ff_qsv_encode to avoid using uninitialized value:

FF_DISABLE_DEPRECATION_WARNINGS
        avctx->coded_frame->pict_type = pict_type;
FF_ENABLE_DEPRECATION_WARNINGS

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
Signed-off-by: Zhong Li <zhong.li@intel.com>
2018-11-30 17:53:26 +08:00
Zhong Li
ac0bcd6b61 lavc/qsvenc: add forced_idr option
This option can be used to repect original input I/IDR frame type.

Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: Zhong Li <zhong.li@intel.com>
2018-11-30 17:53:00 +08:00
James Almer
f4cf6ba8c9 Merge commit 'a2041a6522642859ce64af1c618d6fb90a50d4af'
* commit 'a2041a6522642859ce64af1c618d6fb90a50d4af':
  qsvenc: AV_PIX_FMT_QSV path should release frame

Merged-by: James Almer <jamrial@gmail.com>
2018-09-18 13:28:05 -03:00
Maxym Dmytrychenko
a2041a6522 qsvenc: AV_PIX_FMT_QSV path should release frame
Fixes high memory usage and prevents over allocation of the frames via
proper unref.

Can be checked as:
-hwaccel qsv -c:v h264_qsv -i ../h264-conformance/CANL2_Sony_E.jsv -c:v
h264_qsv -b:v 2000k -y qsv.mp4
2018-09-18 17:53:37 +02:00