# SVT-HEVC

x265 has support for open source HEVC encoder SVT-HEVC and can generate SVT-HEVC compliant bitstreams. SVT-HEVC encoder can be enabled at run time using `--svt`. Since SVT-HEVC params/CLI are not exposed outside, it has to be configured only via x265 CLI options. The API’s of SVT-HEVC are accessed through x265’s API so even library users of x265 can avail this feature, under the condition that x265_param_parse() API should be used for all param assignment. Params assigned outside of x265_param_parse() API wont’t be mapped to SVT-HEVC. This document describes the steps needed to compile x265 with SVT-HEVC and CLI options mapping between x265 and SVT-HEVC.

## Supported Version

Version - 1.4.1

## Build Steps

This section describes the build steps to be followed to link SVT-HEVC with x265.

SVT-HEVC

1. Clone SVT-HEVC-repo (say at path “/home/app/”) and build it (follow the build steps in its README file)

2. Once build is successful, binaries can be found inside the Bin folder at its root directory (“/home/app/SVT-HEVC/Bin/Release/”)

x265

1. Set environmental variables SVT_HEVC_INCLUDE_DIR and SVT_HEVC_LIBRARY_DIR to help x265 locate SVT-HEVC. For example:

     - export SVT_HEVC_INCLUDE_DIR = /home/app/SVT-HEVC/Source/API/

     - export SVT_HEVC_LIBRARY_DIR = /home/app/SVT-HEVC/Bin/Release/

2. Enable the cmake option ENABLE_SVT_HEVC and continue the normal build process

## CLI options Mapping

Once x265 is compiled with SVT-HEVC, SVT-HEVC encoder can be invoked at run time using `--svt`. `--svt` can be added anywhere in the command line, x265 application will automatically parse it first and maps all other x265 CLI’s present in the command line to SVT-HEVC encoder options internally and configures the same. Below table shows the actual mapping of x265 CLI options to SVT-HEVC encoder options (Name as shown in SVT-HEVC’s sample configuration file)

x265 CLI option | SVT-HEVC Encoder Option | Range
--- | --- | ---
`--input` | InputFile | Any String
`--output` | StreamFile | Any String
`--input-depth` | EncoderBitDepth | [8, 10]
`--input-res` | SourceWidth | [64 - 8192]
SourceHeight | [64 - 8192]
`--frames` | FrameToBeEncoded | Any Positive Integer
`--fps` | FrameRateNumerator | Any Positive Integer
FrameRateDenominator | Any Positive Integer
`--profile` | Profile | [main, main10]

`--level-idc`

Level

[1, 2, 2.1, 3, 3.1, 4, 4.1,

  5, 5.1, 5.2, 6, 6.1, 6.2]

`--high-tier` | Tier |
`--qpmin` | MinQpAllowed | [0 - 50]
`--qpmax` | MaxQpAllowed | [0 - 51]
`--rc-lookahead` | LookAheadDistance | [0 - 250]
`--scenecut` | SceneChangeDetection | Any Positive Integer
`--open-gop` | IntraRefreshType |
`--deblock` | LoopFilterDisable | Any Integer
`--sao` | SAO |
`--keyint` | IntraPeriod | [(-2) - 255]
`--constrained-intra` | ConstrainedIntra |
`--vui-timing-info` | VideoUsabilityInfo |
`--hdr` | HighDynamicRangeInput |
`--aud` | AccessUnitDelimeter |
`--qp` | RateControlMode | RateControlMode = 0
QP | [0 - 51]
`--bitrate` | RateControlMode | RateControlMode = 1
TargetBitrate | Any Positive Integer
`--interlace` | InterlacedVideo | [0 - 2]
`--pools` | TargetSocket, LogicalProcessors | Maximum NUMA Nodes = 2
`--master-display` | MasteringDisplayColorVolume | Any String
`--max-cll` | maxCLL, maxFALL | Any Positve Integer
`--dolby-vision-profile` | DolbyVisionProfile | [8.1]
`--dolby-vision-rpu` | DolbyVisionRpuFile | Any String
`--nalu-file` | NaluFile | Any String
`--hrd` | hrdFlag | [0, 1]
`--vbv-maxrate` | vbvMaxrate | Any Positive Integer
`--vbv-bufsize` | vbvBufsize | Any Positive Integer
`--vbv-init` | VbvBufInit | [0 - 100]
`--frame-threads` | ThreadCount | Any Number
`--svt-search-width` | SearchAreaWidth | [1 - 256]
`--svt-search-height` | SearchAreaHeight | [1 - 256]
`--svt-hierarchical-level` | HierarchicalLevels | [0 - 3]
`--svt-base-layer-switch-mode` | BaseLayerSwitchMode | [0, 1]
`--svt-pred-struct` | PredStructure | [0 - 2]
`--svt-hme` | HME, UseDefaultMeHme |
`--svt-compressed-ten-bit-format` | CompressedTenBitFormat |
`--svt-speed-control` | SpeedControlFlag |
`--svt-fps-in-vps` | FpsInVps |

x265 CLI options which are not present in the above table will have no effect if SVT-HEVC is enabled and would be ignored silently with a warning. If SVT-HEVC is enabled, accepted input range of x265 CLI options will change, because it follows SVT-HEVC encoder’s specs, which are mentioned in the Range section in the above table. Options starting with prefix “–svt-” are newly added to fecilitate access to the features of SVT-HEVC which couldn’t be mapped to the existing x265 CLI’s. So these options will have effect only if SVT-HEVC is enabled and would be ignored with default x265 encode.

## Preset Option Mapping

x265 has 10 presets from ultrafast to placebo whereas SVT-HEVC has 12 presets. Use `--svt-preset-tuner` with Placebo preset to access the additional 2 presets of SVT-HEVC. Note that `--svt-preset-tuner` should be used only if SVT-HEVC is enabled and only with Placebo preset, would be ignored otherwise. Below table shows the actual mapping of presets,

x265 Preset | SVT-HEVC Preset
--- | ---
Ultrafast | 11
Superfast | 10
Veryfast | 9
Faster | 8
Fast | 7
Medium | 6
Slow | 5
Slower | 4
Veryslow | 3
Placebo | 2
Placebo `--svt-preset-tuner` 0 | 0
Placebo `--svt-preset-tuner` 1 | 1