bmegli / hardware-video-encoder

HVE - Hardware Video Encoder C library
Mozilla Public License 2.0
16 stars 11 forks source link

bitrate control with iHD on some platforms #31

Open bmegli opened 3 years ago

bmegli commented 3 years ago

Some platforms only expose low power encoding through iHD with default driver (free build, but there is also full featured build and alternative i965 driver).

Low power encoding requires extra firmware (GuC/HuC) loaded for bitrate control.

When trying to hardware encode without GuC/HuC you will see then error like this:

# FFmpeg 4.2.4 (Ubuntu 20.04)
[h264_vaapi @ 0x7f990c03a340] Driver does not support any RC mode compatible with selected options (supported modes: CQP).
# FFmpeg 3.4.8 (Ubuntu 18.04)
[h264_vaapi @ 0x5619121478a0] Rate control mode 0x4 is not supported (mask: 0x10).
bmegli commented 3 years ago

To confirm that your platform only supports low power encoding (LP) through default driver:

vainfo
# or specify device if you have multiple (e.g. NVIDIA/Intel)
vainfo --display drm --device /dev/dri/renderD128

Example output:

vainfo --display drm --device /dev/dri/renderD128
libva info: VA-API version 1.7.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_7
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.7 (libva 2.6.0)
vainfo: Driver version: Intel iHD driver for Intel(R) Gen Graphics - 20.1.1 ()
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointEncSliceLP
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointEncSliceLP
      VAProfileJPEGBaseline           : VAEntrypointVLD
      VAProfileJPEGBaseline           : VAEntrypointEncPicture
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSliceLP
      VAProfileVP8Version0_3          : VAEntrypointVLD
      VAProfileHEVCMain               : VAEntrypointVLD
      VAProfileHEVCMain10             : VAEntrypointVLD
      VAProfileVP9Profile0            : VAEntrypointVLD
      VAProfileVP9Profile2            : VAEntrypointVLD

Notice that there is only LP profile for encoding (VAEntrypointEncSliceLP)

bmegli commented 3 years ago

The workarounds are:

bmegli commented 3 years ago

Checking profile/driver support

LIBVA_DRIVER_NAME=i965 vainfo --display drm --device /dev/dri/renderD128
LIBVA_DRIVER_NAME=iHD vainfo --display drm --device /dev/dri/renderD128

Example output with i965 (compare with output in post above)

LIBVA_DRIVER_NAME=i965 vainfo --display drm --device /dev/dri/renderD128
libva info: VA-API version 1.7.0
libva info: User environment variable requested driver 'i965'
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_1_6
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.7 (libva 2.6.0)
vainfo: Driver version: Intel i965 driver for Intel(R) Kaby Lake - 2.4.0
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Simple            : VAEntrypointEncSlice
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSliceLP
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointEncSlice
      VAProfileH264Main               : VAEntrypointEncSliceLP
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointEncSlice
      VAProfileH264High               : VAEntrypointEncSliceLP
      VAProfileH264MultiviewHigh      : VAEntrypointVLD
      VAProfileH264MultiviewHigh      : VAEntrypointEncSlice
      VAProfileH264StereoHigh         : VAEntrypointVLD
      VAProfileH264StereoHigh         : VAEntrypointEncSlice
      VAProfileVC1Simple              : VAEntrypointVLD
      VAProfileVC1Main                : VAEntrypointVLD
      VAProfileVC1Advanced            : VAEntrypointVLD
      VAProfileNone                   : VAEntrypointVideoProc
      VAProfileJPEGBaseline           : VAEntrypointVLD
      VAProfileJPEGBaseline           : VAEntrypointEncPicture
      VAProfileVP8Version0_3          : VAEntrypointVLD
      VAProfileVP8Version0_3          : VAEntrypointEncSlice
      VAProfileHEVCMain               : VAEntrypointVLD
      VAProfileHEVCMain               : VAEntrypointEncSlice
      VAProfileHEVCMain10             : VAEntrypointVLD
      VAProfileHEVCMain10             : VAEntrypointEncSlice
      VAProfileVP9Profile0            : VAEntrypointVLD
      VAProfileVP9Profile0            : VAEntrypointEncSlice
      VAProfileVP9Profile2            : VAEntrypointVLD

Notice both LPand typical EncSlice encoding paths.

To force i965 driver for your application use LIBVA_DRIVER_NAME=i965 before start command or set in in your environment.

bmegli commented 3 years ago

Example of affected platform:

Intel(R) Core(TM) m3-8100Y CPU

Example devices using this chipset: