FFmpeg with LCEVC
Getting started
Overview
Most standard FFmpeg command-line options are included, as well as additional options for configuring V-Nova LCEVC.
This FFmpeg release supports LCEVC with an x264 and x265 base. Additional base codecs are available (e.g. NVEnc, libvpx, QSV, Xilinx NGcodec, etc.) and a patch for your build of FFmpeg can be provided by V-Nova upon request.
LCEVC codec
An additional FFmpeg video codec, LCEVC, is available in this build. It is invoked by specifying the codec to enhance and the implementation of the base codec to be enhanced. Its syntax is as follows:
-c:v lcevc_<codec> -base_encoder <codec implementation> -eil_params "<enhancement parameters string>;<base parameters string>"
Where <codec>
can be h264 or hevc, and <codec implementation>
can be a specific software implementation such as x264 or nvenc_hevc.
The behaviour of lcevc_<codec>
is described by the following help command in FFmpeg:
ffmpeg -help encoder=lcevc_h264
ffmpeg -help encoder=lcevc_hevc
eil_params
is a command line string that is used to pass parameters to both enhancement and base codec. Its behaviour is described later.
Bitrate, GOP length and framerate
There are a number of parameters that are considered generic, i.e. not specific in use to either LCEVC or the base codec it enhances. These parameters are bitrate, GOP length and framerate. Furthermore, these parameters are used to calculate initialisation values for LCEVC and base codec.
Bitrate, GOP length and framerate are NOT set through the eil_params
string. Instead, they use the FFmpeg generic command line options:
-b:v for video bitrate
-g for GOP length
-r for framerate
Since these settings are used by the LCEVC integration layer to initialise the common rate control engine, the equivalent options in the base codec are deprecated. For example, bitrate=1000k
or keyint=120
may produce unexpected behaviour or return an error. Please, use -b:v
and -g
instead.
EIL (Encoding Integration Layer) parameters and syntax
EIL parameters and syntax overview
The Encoding Integration Layer (EIL) is a V-Nova library that combines the base encoder and the LCEVC enhancement, orchestrating the combined behaviour. Moreover, the EIL is architected to support any base codec implementation through a plug-in system that makes it generic and independent. The EIL will parse the command line parameters at initialisation and configure both base and enhancement as required.
It is through the eil_params
parameter, that both the LCEVC enhancement and the base codec are configured, for everything other than bitrate, frame rate and GOP length. Its syntax is as follows, where eil_params
is a semicolon-separated string of parameters and values that are passed to the LCEVC enhancement layer:
ffmpeg.exe -i input.mp4 -c:v lcevc_h264 -base_encoder x264 -eil_params "<parameter1>=<value1>;<parameter2>=<value2>;…" output.ts
<parameter1>, <parameter2>, etc., are passed to the EIL interface, and configure both the V-Nova LCEVC encoder and the base encoder.
V-Nova LCEVC FFmpeg encoder: examples of recommended commands
1080p and higher resolution
The following examples refer to encoding a 1080p60 YUV source.
Important: If you intend to run objective metrics, then please remember to disable dithering on the decoder.
CBR (with CBR base - recommended)
Example of recommended command line for 1080p CBR with CBR base, tune VQ, with bitrate set at 3 Mbps:
ffmpeg.exe -y -framerate 59.97 -f rawvideo -pix_fmt yuv420p -s 1920x1080 -i input-p60-1920x1080.yuv -c:v lcevc_h264 -base_encoder x264 -g 120 -b:v 3000k -eil_params "preset=medium;rc_pcrf_window_type=rolling" output-p60-1920x1080_3000kbps.ts
CBR (with CRF base)
Example of a recommended command line for CBR with CRF base, with bitrate set at 3 Mbps:
ffmpeg.exe -y -framerate 59.97 -f rawvideo -pix_fmt yuv420p -s 1920x1080 -i input-p60-1920x1080.yuv -c:v lcevc_h264 -base_encoder x264 -g 120 -b:v 3000k -eil_params "rc_pcrf_base_rc_mode=crf;preset=medium;rc_pcrf_window_type=rolling" output-CRFbase-p60-1920x1080_3000kbps.ts
pCRF (uncapped)
Example of the above command line for pCRF, with pCRF set at 27: (notice: -b:v 0 can also be avoided, since it is the default value of -b:v for Ffmpeg)
ffmpeg.exe -y -framerate 59.97 -f rawvideo -pix_fmt yuv420p -s 1920x1080 -i input-p60-1920x1080.yuv -c:v lcevc_h264 -base_encoder x264 -g 120 -b:v 0 -eil_params "rc_pcrf=27;" output-p60-1920x1080_pcrf27.ts
pCRF (Capped)
Example of the above command line for pCRF, with pCRF set at 27 and cap of 5mbps.
ffmpeg.exe -y -framerate 59.97 -f rawvideo -pix_fmt yuv420p -s 1920x1080 -i input-p60-1920x1080.yuv -c:v lcevc_h264 -base_encoder x264 -g 120 -b:v 5M -eil_params "rc_pcrf=27;rc_pcrf_min_bitrate=0;rc_pcrf_base_rc_mode=crf" output-p60-1920x1080_pcrf27.ts
720p and lower resolutions
The following examples refer to encoding a 360p30 YUV source.
CBR (with CBR base - recommended) – 360p25
Example of recommended command line for 360p CBR, bitrate set at 170 Kbps:
ffmpeg.exe -y -framerate 25 -f rawvideo -pix_fmt yuv420p -s 640x360 -i input-p25-640x360.yuv -c:v lcevc_h264 -base_encoder x264 -g 50 -b:v 170k -eil_params "preset=medium;rc_pcrf_window_type=rolling" output-p25-640x360_170kbps.ts
CBR (with CBR base) – 540p30
Example of a recommended command line for CBR, bitrate set at 450 kbps:
ffmpeg.exe -y -framerate 29.97 -f rawvideo -pix_fmt yuv420p -s 960x540 -i input-p30-960x540.yuv -c:v lcevc_h264 -base_encoder x264 -g 60 -b:v 450k -eil_params "preset=medium;rc_pcrf_window_type=rolling" output-p30-960x540_450kbps.ts
More advanced settings can allow to set specific CBR rates for the base, overriding the default values.
pCRF (uncapped) – 720p
Example of command line for pCRF set at 30:
ffmpeg.exe -y -framerate 29.97 -f rawvideo -pix_fmt yuv420p -s 1280x720 -i input-p30-1280x720.yuv -c:v lcevc_h264 -base_encoder x264 -g 60 -b:v 0 -eil_params "rc_pcrf=30;preset=medium;rc_pcrf_window_type=rolling" output-p30-1280x720_pcrf30.ts
V-Nova LCEVC with other base encoders
The LCEVC enhancement layer behaves differently depending on the performance of the base codec and plugin it is working with. Please, consult V-Nova on how to best tune supported base encoder plugins.
x265
The LCEVC-enhanced x265 encoder can be setup as follows:
-c:v lcevc_hevc -base_encoder x265 -eil_params "<enhancement parameter string>;”
The following command line is an example using configurations for both the enhancement and the base codec.
ffmpeg.exe -y -i source.y4m -c:v lcevc_hevc -base_encoder x265 -g 60 -b:v 1000k -eil_params "preset=medium;lcevc_tune=vq;" output.ts
Note that GOP Length is no longer passed directly to x.265 using keyint as a parameter in the eil_params string. Rather, it is set using the global -g option in FFmpeg. Other options for GOP length, such as min-keyint remain available and applicable with the use of scene-cut.
AV1 (LibAOM)
The LibAOM encoder is configured using the formatting below:
-c:v lcevc_av1 -base_encoder aom -eil_params "<enhancement parameter string>;”
Here is a full example command, encoding AV1 with LCEVC in FFmpeg:
ffmpeg -y -i input.yuv -c:v lcevc_av1 -base_encoder aom -g 60 -b:v 1000k -eil_params "threads=8;cpu-used=4;row-mt=1;lcevc_tune=vq;" output.webm
To define the balance of encoding speed and quality libaom uses 'cpu-used' with a range 0-8 (0 Quality, 8 performance) . This should be used in partnership with lcevc_preset
guidance.
Note that B-Frames are not applicable in AV1, the picture type structure is different and uses S-frame and Intra frames. There is no parameter control for frame types but the -g (GOP) setting is critical to define the interval of the 'Intra' frame type.
Note that the output container needs to be webm.
AV1 (SVT-AV1)
Intel's SVT-AV1 is configured using the formatting below:
-c:v lcevc_av1 -base_encoder svt_av1 -eil_params "<enhancement parameter string>;”
'Preset' is the control to define the balance of encoding speed over quality for the base codec. The values available are 0-13 (P1 quality, P12 performance). This should be used in partnership with lcevc_preset
guidance.
Note that B-Frames are not applicable in AV1, the picture type structure is different and uses S-frame and Intra frames. There is no parameter control for frame types but the -g (GOP) setting is critical to define the interval of the 'Intra' frame type.
Note that the output container needs to be webm
VP9
VP9 is configured in a similar way to x265 where most extra parameters are required within the eil param string otherwise they won't be passed corretly:
-c:v lcevc_vp9 -base_encoder vpx_vp9 -eil_params "<enhancement parameter string>;”
The following command line is an example using configurations for both the enhancement and the base codec.:
ffmpeg -y -i source.yuv -c:v lcevc_vp9 -base_encoder vpx_vp9 -s 1920x1080 -r 30 -b:v 3000k -g 120 -eil_params "quality=good;cpu-used=0;row-mt=1" output.webm
To define the balance of encoding speed and quality VP9 uses; 'cpu-used' (0-8) & 'quality' (Best, good, realtime).
When the quality parameter is good
or best
, values for -cpu-used
can be set between 0 and 5, when quality is set to realtime
, the available values for -cpu-used
are 0 to 8 (0 Quality, 8 performance). This should be used in partnership with lcevc_preset
guidance.
As guided in the VP9 documentation -row-mt=1;
is advised to enable multi threading operation.
Note B-Frames are not applicable in VP9, the picture type structure uses Intra or Key frames. There is no parameter control for frame types but the -g (GOP) setting is critical to define the interval of the 'Intra' frame type.
Note that the output container needs to be webm.
QSV
Quick Sync Video is Intel's hardware dedicated encoding and decoding tools, the codec has certain hardware requirements which can be found on Intel's website. QSV supports encoding of H264, HEVC, VP8 and VP9. Encoding with LCEVC is similar to previous examples:
-c:v lcevc_h264 -base_encoder qsv_h264 -eil_params "<enhancement parameter string>;”
-c:v lcevc_hevc -base_encoder qsv_hevc -eil_params "<enhancement parameter string>;”
The following command line is an example using configurations for both the enhancement and the base codec:
ffmpeg -y -vcodec rawvideo -pix_fmt yuv420p -s 1920x1080 -r 30 -i source.yuv -c:v lcevc_hevc -s 1920x1080 -r 30 -b:v 5000k -g 60 -base_encoder qsv_hevc output.ts
There is different level of support for MFX (aka Intel Media SDK) between Windows and Linux on Windows - supported on a broader range of chipsets on Linux - supported on gen8+ chipsets only, which use iHD driver for older chipsets on Linux a direct integration of VAAPI is required, basically an extra EIL plugin, how difficult - unknown. This will enable older Intel chipsets to be used on Linux for LCEVC encodes (with hardware base encoding, which base codecs are supported by which generations of chipsets - another question
NVENC Plugin
NVENC is NVidia's built-in video encoding available on a broad range of its GPU cards, details on the specific support from different NVidia hardware is available here. NVENC can support both AVC/H.264 and HEVC/H.265 encoding depending upon the GPU in question. Running LCEVC-enhanced encoding of these two base encoders can be initiated with the following commands:
CPU - The LCEVC encoding is performed solely on the CPU with the NVIDIA GPU's NVENC hardware encoder providing the base layer encodin
-c:v lcevc_h264 -base_encoder nvenc_h264 -eil_params "<enhancement parameter string>;”
-c:v lcevc_hevc -base_encoder nvenc_hevc -eil_params "<enhancement parameter string>;”
Vulkan - This process primarily uses the GPU to encode the LCEVC enhancement.
-c:v lcevc_h264_vulkan -base_encoder nvenc_h264 -eil_params "gpu_device=NVIDIA”
-c:v lcevc_hevc_vulkan -base_encoder nvenc_hevc -eil_params "gpu_device=NVIDIA”
Within FFmpeg, NVidia is not able to access frame data in normal system memory. All frame data needs to be uploaded to hardware surfaces connected to the appropriate device before being used. As per Nvidia documentation here. Within FFmpeg the following example creates a filter where rawvideo is uploaded in hardware, then passed to the stream named.
-filter_complex '[0]hwupload[input_in_gpu_memory]' -map '[input_in_gpu_memory]'
Following the same logic as other base encoders, bitrate, frame rate, resolution and GOP are specified as normal in FFmpeg, however other commands need to be within the eil_params. Post NVENC SDK 10.0 the API structure changed. For a guide to translate your preset please see here. Old preset options; [default, hp, hq, lossless, lossless_hp] are now updated to be an integer with 'preset=X' where the value range is 1-7 (P7 highest quality, P1 performance).
V-Nova LCEVC FFmpeg decoder commands
The V-Nova LCEVC decoder can be used similarly to other codecs in FFmpeg or FFplay, with one important difference. The enhancement layer is embedded as metadata in a fully compliant and backward compatible H.264/AVC or H.265/HEVC elementary stream. Therefore, the decoder must be instructed to extract and decode LCEVC data.
The command line to enable V-Nova LCEVC decoding of an LCEVC-enhanced transport stream or MP4 file, is as follows:
ffmpeg.exe -vcodec lcevc_h264 -i stream.ts -vcodec rawvideo output.yuv
ffmpeg.exe -vcodec lcevc_h264 -i stream.mp4 -vcodec rawvideo output.yuv
The equivalent command line for HEVC is:
ffmpeg.exe -vcodec lcevc_hevc -i stream.ts -vcodec rawvideo output.yuv
ffmpeg.exe -vcodec lcevc_hevc -i stream.mp4 -vcodec rawvideo output.yuv
And for FFplay, h.264 and HEVC respectively:
ffplay.exe -vcodec lcevc_h264 -i stream.mp4
ffplay.exe -vcodec lcevc_hevc -i stream.mp4
Decoding to perform Objective evaluation
To perform objective metric calculations when dithering is enabled in LCEVC encoding, dithering must be disabled as follows:
ffmpeg.exe -vcodec lcevc_h264 -disable_dithering 1 -i stream.mp4 -vcodec rawvideo output.yuv
To calculate metrics, the command line is similar to that of other codecs in FFmpeg, in line with guidelines included at the following link, and as shown in the following command line:
https://github.com/Netflix/vmaf/blob/master/resource/doc/libvmaf.md
ffmpeg.exe -vcodec lcevc_h264 –i input_stream.ts -vcodec rawvideo -s 1920x1080 -i reference_yuv.yuv -filter_complex " [0:v]scale=1920x1080:flags=bicubic[main];[main][1:v]libvmaf" -f null
Last updated
Was this helpful?