Av1an
Av1an is a video encoding framework. It can increase your encoding speed and improve cpu utilization by running multiple encoder processes in parallel. Target quality, VMAF plotting, and more, available to take advantage for video encoding.
For help with av1an, please reach out to us on Discord or file a GitHub issue
Parameters
For more details, see documentation for each parameter or run av1an --help
.
General
Name | Flag | Type | Default |
---|---|---|---|
Input | -i | Path | |
Output | -o | Path | |
Temporary | --temp | Path | Input file name hash |
Quiet | -q | ||
Verbose | --verbose | ||
Log File | -l , --log-file | Path | ./logs/av1an.log |
Log Level | --log-level | LOG_LEVEL | debug |
Resume | --resume | ||
Keep | -k , --keep | ||
Force | --force | ||
No Defaults | --no-defaults | ||
Overwrite | -y | ||
Never Overwrite | -n | ||
Max Tries | --max-tries | Integer | 3 |
Workers | --workers | Integer | 0 (Automatic) |
Thread Affinity | --set-thread-affinity | Integer | |
Scaler | --scaler | SCALER | bicubic |
VSPipe Arguments | --vspipe-args | String List | |
Help | -h , --help | ||
Version | -V , --version |
Scene Detection
Name | Flag | Type | Default |
---|---|---|---|
Scenes | -s , --scenes | Path | |
Scene Detection Only | --sc-only | ||
Split Method | --split-method | SPLIT_METHOD | av-scenechange |
Scene Detection Method | --sc-method | SC_METHOD | standard |
Scene Downscale Height | --sc-downscale-height | Integer | |
Scene Pixel Format | --sc-pix-format | PIXEL_FORMAT | |
Extra Split Frames | -x , --extra-split | Integer | |
Extra Split Seconds | --extra-split-sec | Integer | 10 |
Minimum Scene Length | --min-scene-len | Integer | 24 |
Force Keyframes | --force-keyframes | Integer List |
Encoding
Name | Flag | Type | Default |
---|---|---|---|
Encoder | -e , --encoder | ENCODER | aom |
Video Parameters | -v , --video-params | String List | Based on Encoder |
Passes | -p , --passes | Integer | 1 |
Tile Auto | --tile-auto | ||
FFmpeg Parameters | -f , --ffmpeg | String | |
Audio Parameters | -a , --audio-params | String | |
Ignore Frame Mismatch | --ignore-frame-mismatch | ||
Chunk Method | -m , --chunk-method | CHUNK_METHOD | lsmash |
Chunk Order | --chunk-order | CHUNK_ORDER | long-to-short |
Photon Noise | --photon-noise | Integer | |
Chroma Noise | --chroma-noise | ||
Photon Noise Width | --photon-noise-width | Integer | |
Photon Noise Height | --photon-noise-height | Integer | |
Concatenation Method | -c , --concat | CONCAT | ffmpeg |
Pixel Format | --pix-format | PIX_FORMAT | yuv420p10le |
Zones | -z , --zones | Path |
VMAF
Name | Flag | Type | Default |
---|---|---|---|
VMAF | --vmaf | ||
VMAF Path | --vmaf-path | String | |
VMAF Resolution | --vmaf-res | String | 1920x1080 |
VMAF Threads | --vmaf-threads | Integer | |
VMAF Filter | --vmaf-filter | String |
Target Quality
Name | Flag | Type | Default |
---|---|---|---|
Target Quality | --target-quality | Float | |
Probes | --probes | Integer | 4 |
Probing Rate | --probing-rate | Integer | 1 |
Probe Slow | --probe-slow | ||
Minimum Quantizer | --min-q | Integer | Based on Encoder |
Maximum Quantizer | --max-q | Integer | Based on Encoder |
General
Name | Flag | Type | Default |
---|---|---|---|
Input | -i | Path | |
Output | -o | Path | |
Temporary | --temp | Path | Input file name hash |
Quiet | -q | ||
Verbose | --verbose | ||
Log File | -l , --log-file | Path | ./logs/av1an.log |
Log Level | --log-level | LOG_LEVEL | debug |
Resume | --resume | ||
Keep | -k , --keep | ||
Force | --force | ||
No Defaults | --no-defaults | ||
Overwrite | -y | ||
Never Overwrite | -n | ||
Max Tries | --max-tries | Integer | 3 |
Workers | --workers | Integer | 0 (Automatic) |
Thread Affinity | --set-thread-affinity | Integer | |
Scaler | --scaler | SCALER | bicubic |
VSPipe Arguments | --vspipe-args | String List | |
Help | -h , --help | ||
Version | -V , --version |
Input -i
Input file to encode.
Can be a video or a VapourSynth (.py
, .vpy
) script.
Examples
> av1an -i ./input.mkv -o output.mkv
> av1an -i C:\Videos\input.mp4 -o output.mkv
> av1an -i /home/videos/vapoursynth/script.vpy -o output.mkv
> av1an -i ./script.py -o output.mkv
Output -o
Video output file.
Examples
> av1an -i input.mkv -o C:\Encodes\output.mkv
> av1an -i input.mkv -o output.mkv
> av1an -i input.mkv -o /home/videos/av1an/done.mkv
Temporary --temp
Temporary directory to use.
Default
If not specified, the temporary directory name is a hash of the input file name.
Examples
> av1an -i input.mkv -o output.mkv
- Creates temporary directory./.bf937a7/
> av1an -i input.mkv -o output.mkv --temp temporary
- Creates temporary directory./temporary/
> av1an -i input.mkv -o output.mkv --temp C:\tmp\av1an
- Creates temporary directoryC:\tmp\av1an\
Quiet -q
, --quiet
Disable printing progress to the terminal.
Verbose --verbose
Print extra progress info and stats to the terminal.
Log File -l
, --log-file
Log file location under ./logs
.
Must be a relative path. Prepending with ./logs
is optional.
Default
If not specified, logs to ./logs/av1an.log.{DATE}
where {DATE}
is the current date in ISO-8601 format.
Examples
> av1an -i input.mkv -o output.mkv
- Logs to./logs/av1an.log.2020-1-10
> av1an -i input.mkv -o output.mkv -l log.txt
- Logs to./logs/log.txt
> av1an -i input.mkv -o output.mkv --log-file ./today/1.log
- Logs to./logs/today/1.log
Log Level --log-level
Set log level for log file (does not affect command-line log level)
Possible Values
error
: Designates very serious errors.warn
: Designates hazardous situations.info
: Designates useful information.debug
: Designates lower priority information.trace
: Designates very low priority, often extremely verbose, information. Includes rav1e scenechange decision info.
Default
If not specified, log level is set to debug
.
Resume --resume
Resume previous session from temporary directory.
Keep -k
, --keep
Do not delete the temporary folder after encoding has finished
Necessary for resuming a session.
Force --force
Do not check if the encoder arguments specified by -v
/--video-params
are valid.
No Defaults --no-defaults
Do not include Av1an's default set of encoder parameters.
Overwrite -y
Overwrite output file, without confirmation
Never Overwrite -n
Never overwrite output file, without confirmation
Max Tries --max-tries
Maximum number of chunk restarts for an encode.
Possible Values
Can be an integer greater than or equal to 1
.
Default
If not specified, max tries is set to 3
.
Workers -w
, --workers
Number of workers to spawn.
Default
If not specified or set to 0
, the number of workers is automatically determined.
Examples
> av1an -i input.mkv -o output.mkv
- Spawns workers automatically> av1an -i input.mkv -o output.mkv -w 4
- Spawns 4 workers> av1an -i input.mkv -o output.mkv --workers 2
- Spawns 2 workers
Thread Affinity --set-thread-affinity
Pin each worker to a specific set number of threads.
This is currently only supported on Linux and Windows, and does nothing on unsupported platforms. Leaving this option unspecified allows the OS to schedule all processes spawned.
Possible Values
Can be an integer greater than or equal to 1
.
Default
If not specified, thread affinity is disabled and the OS will schedule all processes spawned.
Scaler --scaler
Scaler used for scene detection when downscaling (--sc-downscale-height
) or for VMAF calculation
Possible Values
Valid scalers are based on the scalers available in FFmpeg, including lanczos[1-9]
with [1-9]
defining the width of the lanczos scaler.
Default
If not specified, the scaler is set to bicubic
.
Examples
> av1an -i input.mkv -o output.mkv --sc-downscale-height 720 --scaler bilinear
- Downscale to 720p using bilinear scaling> av1an -i input.mkv -o output.mkv --sc-downscale-height 540 --scaler lanczos3
- Downscale to 540p using lanczos3
VSPipe Arguments --vspipe-args
Additional arguments to pass to vspipe.
Only applicable when using VapourSynth chunking methods (--chunk-method
) such as lsmash or ffms2 or when the input is a VapourSynth script.
Possible Values
Can be a string or a list of strings separated by spaces in the format of "key1=value1" "key2=value2"
. See the VSPipe documentation for more information.
Examples
> av1an -i input.mkv -o output.mkv --vspipe-args "message=fluffy kittens" "head=empty"
- Passesmessage=fluffy kittens
andhead=empty
to vspipe with generated loadscript.vpy> av1an -i input.vpy -o output.mkv --vspipe-args "blur=10"
- Passesblur=10
to vspipe with input.vpy
Help -h
, --help
Print help information.
Version -V
, --version
Print version information.
Scene Detection
Name | Flag | Type | Default |
---|---|---|---|
Scenes | -s , --scenes | Path | |
Scene Detection Only | --sc-only | ||
Split Method | --split-method | SPLIT_METHOD | av-scenechange |
Scene Detection Method | --sc-method | SC_METHOD | standard |
Scene Downscale Height | --sc-downscale-height | Integer | |
Scene Pixel Format | --sc-pix-format | PIXEL_FORMAT | |
Extra Split Frames | -x , --extra-split | Integer | |
Extra Split Seconds | --extra-split-sec | Integer | 10 |
Minimum Scene Length | --min-scene-len | Integer | 24 |
Force Keyframes | --force-keyframes | Integer List |
Scenes -s
, --scenes
File location for scenes.
Scenes are stored as JSON.
Examples
> av1an -i input.mkv -o output.mkv -s scenes.json
- Creates scenes file./scenes.json
> av1an -i input.mkv -o output.mkv --scenes C:\Av1an\scenes\1.json
- Creates scenes fileC:\Av1an\scenes\1.json
Scene Detection Only --sc-only
Run the scene detection only before exiting.
Requires a scene file with --scenes
.
Split Method --split-method
Method used to determine chunk boundaries.
"av-scenechange" uses an algorithm to analyze which frames of the video are the start of new scenes, while "none" disables scene detection entirely (and only relies on -x/--extra-split to add extra scenecuts).
Possible Values
av-scenechange
none
Default
If not specified, av-scenechange
is used.
Scene Detection Method --sc-method
Scene detection algorithm to use for av-scenechange.
Possible Values
standard
- Most accurate, still reasonably fast. Uses a cost-based algorithm to determine keyframes.fast
- Very fast, but less accurate. Determines keyframes based on the raw difference between pixels.
Default
If not specified, standard
is used.
Scene Downscale Height --sc-downscale-height
Optional downscaling for scene detection.
Specify as the desired maximum height to scale to (e.g. 720
to downscale to 720p — this will leave lower resolution content untouched). Downscaling improves scene detection speed but lowers accuracy, especially when scaling to very low resolutions.
By default, no downscaling is performed.
Scene Pixel Format --sc-pix-format
Perform scene detection with this pixel format.
Possible Values
Any valid pixel format name. See FFmpeg for a full list.
Examples
> av1an -i input.mkv -o output.mkv --sc-pix-format yuv420p
- Use YUV420P for scene detection> av1an -i input.mkv -o output.mkv --sc-pix-format yuv444p
- Use YUV444P for scene detection
Extra Split Frames -x
, --extra-split
Maximum scene length, in frames.
When a scenecut is found whose distance to the previous scenecut is greater than the value specified by this option, one or more extra splits (scenecuts) are added. Set this option to 0
to disable adding extra splits.
Examples
> av1an -i input.mkv -o output.mkv -x 100
- Adds an extra split every 100 frames> av1an -i input.mkv -o output.mkv --extra-split 240
- Adds an extra split every 240 frames> av1an -i input.mkv -o output.mkv --extra-split 0
- Disables adding extra splits
Extra Split Seconds --extra-split-sec
Maximum scene length, in seconds.
If both frames and seconds are specified, then the number of frames will take priority.
Default
If not specified, 10
is used.
Examples
> av1an -i input.mkv -o output.mkv --extra-split-sec 10
- Adds an extra split every 10 seconds> av1an -i input.mkv -o output.mkv --extra-split-sec 5
- Adds an extra split every 5 seconds> av1an -i input.mkv -o output.mkv --extra-split-sec 15 --extra-split 50
- Adds an extra split every 50 frames, ignoring--extra-split-sec 15
Minimum Scene Length --min-scene-len
Minimum number of frames for a scenecut.
If a scene contains fewer frames than this value, it will not be cut.
Default
If not specified, 24
is used.
Examples
> av1an -i input.mkv -o output.mkv --min-scene-len 60
- Adds an extra split every 60 frames
Force Keyframes --force-keyframes
List of frames to force as keyframes.
Possible Values
A comma-separated list of frame numbers as positive integers.
Examples
> av1an -i input.mkv -o output.mkv --force-keyframes 82,346,622
- Force frames 82, 346, and 622 as keyframes
Encoding
Name | Flag | Type | Default |
---|---|---|---|
Encoder | -e , --encoder | ENCODER | aom |
Video Parameters | -v , --video-params | String List | Based on Encoder |
Passes | -p , --passes | Integer | 1 |
Tile Auto | --tile-auto | ||
FFmpeg Parameters | -f , --ffmpeg | String | |
Audio Parameters | -a , --audio-params | String | |
Ignore Frame Mismatch | --ignore-frame-mismatch | ||
Chunk Method | -m , --chunk-method | CHUNK_METHOD | lsmash |
Chunk Order | --chunk-order | CHUNK_ORDER | long-to-short |
Photon Noise | --photon-noise | Integer | |
Chroma Noise | --chroma-noise | ||
Photon Noise Width | --photon-noise-width | Integer | |
Photon Noise Height | --photon-noise-height | Integer | |
Concatenation Method | -c , --concat | CONCAT | ffmpeg |
Pixel Format | --pix-format | PIX_FORMAT | yuv420p10le |
Zones | -z , --zones | Path |
Encoder -e
, --encoder
Video encoder to use.
Possible Values
Default
If not specified, aom
will be used.
Video Parameters -v
, --video-params
Parameters for video encoder.
These parameters are for the encoder binary directly, so the FFmpeg syntax cannot be used. For example, CRF is specified in ffmpeg via -crf <CRF>
, but the x264 binary takes this value with double dashes, as in --crf <CRF>
. See the --help
output of each encoder for a list of valid options. This list of parameters will be merged into Av1an's default set of encoder parameters unless --no-defaults
is specified.
Passes -p
, --passes
Number of encoder passes.
Two-pass mode is used by default for aom
and vpx
. Unlike other encoders which two-pass mode is used for more accurate VBR rate control, aom
and vpx
benefit from two-pass mode even with constant quality mode.
When using aom
or vpx
with RT mode (--rt
), one-pass mode is always used regardless of the value specified by this flag (as RT mode in aom
and vpx
only supports one-pass encoding).
Possible Values
Can be one of the following integers: 1
or 2
.
Default
If not specified, 1
is used unless encoding with aom
or vpx
without RT mode (--rt
), in which case 2
is used.
Tile Auto --tile-auto
Estimate tile count based on resolution, and set encoder parameters, if applicable.
FFmpeg Filter Arguments -f
, --ffmpeg
Video filter arguments (FFmpeg syntax).
Possible Values
Any of the valid FFmpeg Video Filter Options.
Examples
> av1an -i input.mkv -o output.mkv -f "-vf crop=100:100:100:100"
- Crops the video by 100 pixels from the top, left, bottom, and right> av1an -i input.mkv -o output.mkv -f "-vf scale=1920:1080"
- Scales the video to 1920x1080
Audio Parameters -a
, --audio-params
Audio encoding parameters (FFmpeg syntax).
Do not use FFmpeg's -map
syntax with this option. Instead, use the colon syntax (Stream specifiers) with each parameter you specify.
Subtitles are always copied by default.
Possible Values
Any of the valid FFmpeg Audio Options.
Default
If not specified, -c:a copy
is used.
Examples
> av1an -i input.mkv -o output.mkv -a "-c:a libopus -b:a 128k"
- Encodes all audio tracks with libopus at 128k> av1an -i input.mkv -o output.mkv --audio-params "-c:a:0 libopus -b:a:0 128k -c:a:1 aac -ac:a:1 1 -b:a:1 24k"
- Encodes the first audio track with libopus at 128k and the second audio track with aac at 24k and downmixed to a single channel
Ignore Frame Mismatch --ignore-frame-mismatch
Ignore any detected mismatch between scene frame count and encoder frame count
Chunk Method -m
, --chunk-method
Method used for piping exact ranges of frames to the encoder.
Some methods require external VapourSynth plugins to be installed. The rest only require FFmpeg.
Possible Values
lsmash
- L-SMASH-Works- Requires VapourSynth plugin
- Generally the best and most accurate method
- Does not require intermediate files
- Errors generally only occur if the input file itself is broken (for example, if the video bitstream is invalid in some way, video players usually try to recover from the errors as much as possible even if it results in visible artifacts, while lsmash will instead throw an error)
ffms2
- FFmpegSource- Requires VapourSynth plugin
- Accurate
- Slightly faster than lsmash for y4m input
- Does not require intermediate files
- Can sometimes have bizarre bugs that are not present in lsmash (that can cause artifacts in the piped output)
dgdecnv
- DGDecNV- Requires VapourSynth plugin
- Requires
dgindexnv
to be present in system path - Requires an NVIDIA GPU that supports CUDA video decoding
- Very fast but only decodes AVC, HEVC, MPEG-2, and VC1
bestsource
- BestSource- Requires VapourSynth plugin
- Slow but most accurate
- Linearly decodes input files
- Does not require intermediate files
hybrid
- Hybrid (Segment + Select)- Requires FFmpeg
- Usually accurate but requires intermediate files (which can be large)
- Avoids decoding irrelevant frames by seeking to the first keyframe before the requested frame and decoding only a (usually very small) number of irrelevant frames until relevant frames are decoded and piped to the encoder
select
- Select- Requires FFmpeg
- Extremely slow, but accurate
- Does not require intermediate files
- Decodes from the first frame to the requested frame, without skipping irrelevant frames (causing quadratic decoding complexity)
segment
- Segment- Requires FFmpeg
- Create chunks based on keyframes in the source
- Not frame exact, as it can only split on keyframes in the source
- Requires intermediate files (which can be large)
Default
If not specified, the first available method is used in this order:
lsmash
ffms2
dgdecnv
bestsource
hybrid
Examples
> av1an -i input.mkv -o output.mkv -m lsmash
- Use L-SMASH-Works for chunking> av1an -i input.mkv -o output.mkv -m ffms2
- Use FFmpegSource for chunking> av1an -i input.mkv -o output.mkv -m hybrid
- Use hybrid for chunking
Chunk Order --chunk-order
The order in which Av1an will encode chunks.
Possible Values
long-to-short
- The longest chunks will be encoded first. This method results in the smallest amount of time with idle cores, as the encode will not be waiting on a very long chunk to finish at the end of the encode after all other chunks have finished.short-to-long
- The shortest chunks will be encoded first.sequential
- The chunks will be encoded in the order they appear in the video.random
- The chunks will be encoded in a random order. This will provide a more accurate estimated filesize sooner in the encode.
Default
If not specified, long-to-short
is used.
Examples
> av1an -i input.mkv -o output.mkv --chunk-order short-to-long
- Encodes the shortest chunks first> av1an -i input.mkv -o output.mkv --chunk-order random
- Encodes the chunks in a random order
Photon Noise --photon-noise
Generates a photon noise table and applies it using grain synthesis.
Photon noise tables are more visually pleasing than the film grain generated by aomenc, and provide a consistent level of grain regardless of the level of grain in the source. Strength values correlate to ISO values, e.g. 1
= ISO 100, and 64
= ISO 6400. This option currently only supports aomenc, rav1e, and SvtAv1EncApp.
An encoder's grain synthesis will still work without using this option, by specifying the correct parameter to the encoder. However, the two should not be used together, and specifying this option will disable or overwrite the encoder's internal grain synthesis.
Possible Values
Can be any integer from 0
to 64
.
Default
If not specified, 0
is used.
Examples
> av1an -i input.mkv -o output.mkv --photon-noise 1
- Applies a ISO 100 photon noise table> av1an -i input.mkv -o output.mkv --photon-noise 12
- Applies a ISO 1200 photon noise table
Chroma Noise --chroma-noise
Adds chroma grain synthesis to the grain table generated by --photon-noise
.
Photon Noise Width --photon-noise-width
Manually set the width for the photon noise table.
Possible Values
Can be any positive integer.
Photon Noise Height --photon-noise-height
Manually set the height for the photon noise table.
Possible Values
Can be any positive integer.
Concatenation Method -c
, --concat
Determines method used for concatenating encoded chunks and audio into output file.
Possible Values
ffmpeg
- FFmpeg- Unfortunately, ffmpeg sometimes produces file with partially broken audio seeking, so
mkvmerge
should generally be preferred if available. FFmpeg concatenation also produces broken files with the--enable-keyframe filtering=2
option in aomenc, so it is disabled if that option is used. However, FFmpeg can mux into formats other than Matroska (.mkv
), such as WebM. To output WebM, use a.webm
extension in the output file.
- Unfortunately, ffmpeg sometimes produces file with partially broken audio seeking, so
mkvmerge
- Matroska- Generally the best concatenation method (as it does not have either of the aforementioned issues that ffmpeg has), but can only produce matroska (.mkv) files. Requires mkvmerge to be installed.
ivf
- IVF- Experimental concatenation method implemented in Av1an itself to concatenate to an IVF file (which only supports VP8, VP9, and AV1, and does not support audio).
Default
If not specified, ffmpeg
is used.
Pixel Format --pix-format
FFmpeg pixel format to use when encoding.
Possible Values
Any valid pixel format name. See FFmpeg for a full list.
Examples
> av1an -i input.mkv -o output.mkv
- Use YUV420P10LE by default> av1an -i input.mkv -o output.mkv --pix-format yuv420p
- Use YUV420P> av1an -i input.mkv -o output.mkv --pix-format yuv444p
- Use YUV444P
Default
If not specified, yuv420p10le
is used.
Zones --zones
Path to a file specifying zones within the video with differing encoder settings.
Possible Values
The zones file should include one zone per line, with each arg within a zone separated by spaces. No quotes or escaping are needed around the encoder args, as these are assumed to be the last argument.
The zone args on each line should be in this order:
start_frame end_frame encoder reset(opt) video_params
start_frame
is inclusive and end_frame
is exclusive and both will be used as scene cuts. Additional scene detection will still be applied within each zone. -1
can be used to indicate the end of the video.
The reset
keyword instructs Av1an to ignore any settings which affect the encoder, and use only the parameters from this zone.
The video parameters which may be specified include any parameters that are allowed by the encoder, as well as the following Av1an options:
- Extra Split Frames
-x
,--extra-split
- Minimum Scene Length
--min-scene-len
- Passes
-p
,--passes
- Photon Noise
--photon-noise
(aomenc/rav1e/SvtAv1EncApp only) - Photon Noise Width
--photon-noise-width
(aomenc/rav1e/SvtAv1EncApp only) - Photon Noise Height
--photon-noise-height
(aomenc/rav1e/SvtAv1EncApp only) - Chroma Noise
--chroma-noise
(aomenc/rav1e/SvtAv1EncApp only)
For segments where no zone is specified, the settings passed to av1an itself will be used.
Examples
> av1an -i input.mkv -o output.mkv --zones zones.txt
- Use the zones file./zones.txt
> av1an -i input.mkv -o output.mkv --zones C:\custom\configuration\zones.txt
- Use the zones fileC:\custom\configuration\zones.txt
./zones.txt
:
136 169 aom --photon-noise 4 --cq-level=32
169 1330 rav1e reset -s 3 -q 42
Line 1 will encode frames 136-168 using aomenc with the argument --cq-level=32
and enable Av1an's --photon-noise
option.
The default behavior as shown on line 1 is to preserve any options passed to --video-params
or --photon-noise
in Av1an, and append or overwrite the additional zone settings.
Line 2 will encode frames 169-1329 using rav1e with only the arguments -s 3 -q 42
.
VMAF
Name | Flag | Type | Default |
---|---|---|---|
VMAF | --vmaf | ||
VMAF Path | --vmaf-path | String | |
VMAF Resolution | --vmaf-res | String | 1920x1080 |
VMAF Threads | --vmaf-threads | Integer | |
VMAF Filter | --vmaf-filter | String |
VMAF --vmaf
Plot an SVG of the VMAF for the encode.
This option is independent of Target Quality (--target-quality
), i.e. it can be used with or without it. The SVG plot is created in the same directory as the Output file.
VMAF Path --vmaf-path
Path to VMAF model.
This option is also used by Target Quality (--target-quality
).
Default
If not specified, FFmpeg's default is used.
VMAF Resolution --vmaf-res
Resolution used for VMAF calculation.
If set to the input resolution, the output video will be scaled to the resolution of the input video.
Default
If not specified, 1920x1080
is used.
VMAF Threads --vmaf-threads
Number of threads to use for Target Quality (--target-quality
) VMAF calculation.
VMAF Filter --vmaf-filter
Filter applied to source at VMAF calcualation.
This option should be specified if the source is cropped, for example.
Target Quality
Name | Flag | Type | Default |
---|---|---|---|
Target Quality | --target-quality | Float | |
Probes | --probes | Integer | 4 |
Probing Rate | --probing-rate | Integer | 1 |
Probe Slow | --probe-slow | ||
Minimum Quantizer | --min-q | Integer | Based on Encoder |
Maximum Quantizer | --max-q | Integer | Based on Encoder |
Target Quality --target-quality
Target a VMAF score for encoding.
For each chunk, Target Quality searches for the quantizer/crf needed to achieve a certain VMAF score. Target Quality mode is much slower than normal encoding, but can improve the consistency of quality in some cases.
The VMAF score range is 0
-100
where 0
is the worst quality and 100
is the best.
Possible Values
Any float value between 0
and 100
.
Examples
> av1an -i input.mkv -o output.mkv --target-quality 80
- Target a VMAF score of 80> av1an -i input.mkv -o output.mkv --target-quality 90.5
- Target a VMAF score of 90.5
Probes --probes
Maximum number of probes allowed for Target Quality.
Possible Values
Can be any positive integer.
Default
If not specified, 4
is used.
Probing Rate --probing-rate
Framerate for probes.
Possible Values
Can be any integer from 1
to 4
.
Default
If not specified, 1
is used.
Probe Slow --probe-slow
Use encoding settings for probes specified by --video-params
rather than faster, less accurate settings.
Note that this always performs encoding in one-pass mode, regardless of --passes
.
Minimum Quantizer --min-q
Lower bound for Target Quality Quantizer-search early exit.
If the minimum quantizer is tested and the probe's VMAF score is lower than the Target Quality (--target-quality
), the Quantizer-search exits early and the minimum quantizer is used for the chunk.
Possible Values
Depends on the encoder.
Default
If not specified, the default value is used (chosen per encoder).
Maximum Quantizer --max-q
Upper bound for Target Quality Quantizer-search early exit.
If the maximum quantizer is tested and the probe's VMAF score is higher than the Target Quality (--target-quality
), the Quantizer-search exits early and the maximum quantizer is used for the chunk.
Possible Values
Depends on the encoder.
Default
If not specified, the default value is used (chosen per encoder).
Target Quality
Table of Contents
Description
Target Quality has a really simple goal, instead of guessing what the CQ/CRF value to choose for desired level of video quality we set quality level we want, quality goal is set in value of VMAF score we want to achieve and let the algorithm find CRF/CQ value that will result in that score, for each segment. Which simultaneously achieve 3 things, if compared to usual, single value CRF/CQ encode.
- Ensuring better level of visual consistency than default rate controls
- Give enough bitrate to complex segments to match target quality.
- Save bitrate by not overspending on scenes, which saves bit rate.
Requirements
-
Working VMAF setup
- FFMPEG with libvmaf (It's de facto default configuration from 2020)
- Installed or manually selected VMAF models
- by default it grabs /usr/share/model/vmaf_v0.6.1.pkl
-
Supported encoder
- aomenc
- rav1e
- svt-av1
- x265
- x264
- vpx
-
Quality/Constant Rate control (Target quality change crf/cq value for each segment). Which means that encoders must be in mode that use CRF/CQ and have those options specified (
--crf 30
,--cq-level=30
) those values get replaced for each segment
Commands
-
--target-quality FLOAT
- enables target quality with default settings for that encoder, targets FLOAT value -
--probes INT
- Overrides maximum amount of probes to make for each segment (Default 4) -
--min_q INT --max_q INT
- Overrides default CRF/CQ boundaries for search
Example of usage
av1an -i file --target-quality 90
- Will run aomenc with default settings of target-quality
av1an -i file --target-quality 95 --vmaf_path "vmaf_v.0.6.3.pkl" --probes 6
- With specified path to vmaf model and 6 probes per segment
Scaling
By default vmaf calculation is done at 1920x1080 with default model. VMAF calculation resolution can be changed
--vmaf-res 3840x2160
Cropping with target quality
Filter with crop should be supplied for both ffmpeg options and vmaf filter
--ffmpeg "-vf crop=3840:1900:0:0" --vmaf-filter "crop=3840:1900:0:0" --vmaf-res "3840x1900"
or cropping and resizing could be done with vapoursynth script
-i 4k_crop.vpy --vmaf-res "3840x1600" --target-quality 90 -o test.mkv
Compiling Av1an
You can natively build Av1an on Linux and Windows. Cross-compilation is not supported.
Compiling on Linux
To compile Av1an from source, you need the following dependencies:
- Rust (version 1.70.0 or higher)
- NASM
- clang/LLVM
- FFmpeg
- VapourSynth
On Arch Linux, you can install these dependencies by running
pacman -S --needed rust nasm clang ffmpeg vapoursynth
Installation instructions on other distros will vary.
After installing the dependencies, you need to clone the repository and start the build process:
git clone https://github.com/master-of-zen/Av1an && cd Av1an
cargo build --release
The resulting binary will be the file ./target/release/av1an
.
Compiling on Windows
If you just want a current build of Av1an that is newer than the last official release, you can find a pre-built binary of the current master
branch at https://github.com/master-of-zen/Av1an/releases/tag/latest.
If you want to build the binary yourself, you will need the following dependencies:
- Microsoft Visual C++ Build Tools - this is a dependency for Rust
- The Rust toolchain
- VapourSynth (download the portable version; the installed version could also work)
- NASM
- FFmpeg (thanks to gyan for providing these builds)
- LLVM
FFmpeg setup:
- Extract the file
ffmpeg-7.0.2-full_build-shared.7z
to a directory. - Create a new environment variable named
FFMPEG_DIR
and set it to the directory path where you extractedffmpeg-7.0.2-full_build-shared.7z
.- (For example, set
FFMPEG_DIR
toC:\Users\Username\Downloads\ffmpeg-7.0.2-full_build-shared
)
- (For example, set
VapourSynth setup:
- Extract the contents of the portable VapourSynth zip file to a directory.
- Create a new environment variable named
VAPOURSYNTH_LIB_DIR
and set it to the directory path where you extracted the file, appending\sdk\lib64
to the path.- (For example, set
VAPOURSYNTH_LIB_DIR
toC:\Users\Username\Downloads\VapourSynth64-Portable-R70\sdk\lib64
)
- (For example, set
Then, either clone the repository by running
git clone https://github.com/master-of-zen/Av1an
Or download and extract the source code manually.
Open a command prompt or PowerShell window inside the cloned repository/extracted ZIP folder and run the command cargo build --release
. If this command executes successfully with no errors, av1an.exe
will be in the folder target\release
.
To use av1an.exe
, copy all the .dll
files from ffmpeg-7.0.2-full_build-shared\bin
to the same directory as av1an.exe
, and ensure that ffmpeg.exe
is in a folder accessible via the PATH
environment variable.
Docker
The docker image is frequently updated and includes all supported encoders and all optional components. It is based on Arch Linux and provides recent versions of encoders and libraries.
The image provides three types of tags that you can use:
masterofzen/av1an:master
for the latest commit frommaster
masterofzen/av1an:sha-#######
for a specific git commit (short hash)
Examples
The following examples assume the file you want to encode is in your current working directory.
Linux
docker run --privileged -v "$(pwd):/videos" --user $(id -u):$(id -g) -it --rm masterofzen/av1an:master -i S01E01.mkv {options}
Windows
docker run --privileged -v "${PWD}:/videos" -it --rm masterofzen/av1an:master -i S01E01.mkv {options}
The image can also be manually built by running
docker build -t "av1an" .
in the root directory of this repository. The dependencies will automatically be installed into the image, no manual installations necessary.
To specify a different directory to use you would replace $(pwd) with the directory
docker run --privileged -v "/c/Users/masterofzen/Videos":/videos --user $(id -u):$(id -g) -it --rm masterofzen/av1an:master -i S01E01.mkv {options}
The --user flag is required on linux to avoid permission issues with the docker container not being able to write to the location, if you get permission issues ensure your user has access to the folder that you are using to encode.
Aomenc
GIT: AOM
Table of Contents
Important command line options
Command Line | Description |
---|---|
--help | Show usage options and exit |
--end-usage=arg | Rate control mode (vbr, cbr(default), cq, q). VBR and CBR are self explanatory. CQ (Constrained Quality) try to follow quantizer, adjusted to fit given rate , Q is for Quality. |
--cq-level=arg | Constant/Constrained Quality level, used in Q/CQ modes. |
--cpu-used=arg | CPU Used (0..6) Good mode, (5..9) realtime mode (default). Default is good mode(CPU-0 to CPU-6). If realtime flag(--rt), every speed set above 6 will default back to 6. Lower numbers are slower. |
--target-bitrate=arg | Bitrate (kbps) |
--bit-depth=arg | Bit depth (8, 10, 12). Default is the bit-depth recognized by aomenc from the source file. It's recommened to set 10-bit, even with 8-bit source, as it improves efficiency, 12-bit is not recommended for end compression, as it is not supported in the main AV1 HW decoding profile. |
--tile-columns=arg | Number of tile columns to use, log2 (number to power of 2). With --tile-columns=2, will result in 4 tile columns. |
--tile-rows=arg | Number of tile rows to use, log2 (number to power of 2). With --tile-rows=1 will result in 2 tile rows. |
--threads=arg | Limit on allowed number of threads to use. Up to 64. |
--lag-in-frames=arg | Number of lagged frames used by the encoder for lookahead and alternate reference frame placement(default 19, max 35). |
--enable-cdef=arg | Enable the constrained directional enhancement filter (0: false, 1: true (default)). CDEF is a filter used to clean up artifacts inflicted by encoder |
--aq-mode=arg | Adaptive quantization mode(0: default. 1: Variance. 2: Complexity. 3: Cyclic Refresh) |
--tune-content=arg | Tune content type (default,screen). |
--enable-fwd-kf=arg | Enable forward reference keyframes(default=0). |
--kf-min-dist=arg | Minimum keyframe interval in frames(default=12). |
--kf-max-dist=arg | Maximum interval in frames at which forced keyframes will be placed(default=9999, or adaptive keyframe placement only). |
--enable-keyframe-filtering=arg | Apply temporal filtering on key frame(0: no filter, 1: filter without overlay (default), 2: filter with overlay - experimental, may break random access in players.) |
--arnr-maxframes=arg | Maximum number of alternate reference noise reduced frames used by the encoder(default=7). |
--arnr-strength=arg | ARNR frames filtering strength(default=5). |
--enable-qm=arg | Enable quantisation matrices (0: false (default), 1: true). |
--quant-b-adapt=arg | Use adaptive quantize_b(default=0). |
--mv-cost-upd-freq=arg | Update freq for mv costs(motion vector estimation cost calculation) (0: SB(SuperBlock), 1: SB Row per Tile, 2: Tile, 3: Off.) |
--enable-chroma-deltaq=arg | Enable chroma delta quant (0: false (default), 1: true). May be broken below --cq-level=15. |
--color-primaries=arg | Color primaries (CICP) of input content: bt709, unspecified, bt601, bt470m, bt470bg, smpte240, film, bt2020, xyz, smpte431, smpte432, ebu3213. |
--transfer-characteristics=arg | Transfer characteristics (CICP) of input content(unspecified, bt709, bt470m, bt470bg, bt601, smpte240, lin, log100, log100sq10, iec61966, bt1361, srgb, bt2020-10bit, bt2020-12bit, smpte2084, hlg, smpte428. |
--matrix-coefficients=arg | Matrix coefficients (CICP) of input content: identity, bt709, unspecified, fcc73, bt470bg, bt601, smpte240, ycgco, bt2020ncl, bt2020cl, smpte2085, chromncl, chromcl, ictcp. |
Example settings and explanation
Constant quality
--end-usage=q --cq-level=30 --cpu-used=4 --threads=64
It is recommended to set it the rate control --end-usage=q to get the highest quality rate control method possible. Only use CQ if you are planning to stream with a maximum bitrate, and CBR/VBR for livestreaming.
It is recommended to the --cq-level in range 20-40 depending on your source.
Target Bitrate
--end-usage=vbr --target-bitrate=1000 --cpu-used=4 --threads=64
To get good efficiency with VBR, it is strongly recommended to use aomenc in 2-pass mode(which is the default in av1an).
Tiles(tile columns and rows)
... --tile-columns=2 --tile-rows=1 ...
If tiles required to improve playback on old devices or high framerates, set --tile-columns=2 and --tile-rows=1 at 1080p. For higher resolution/higher framerate encoding, set it to --tile-columns=3 and --tile-rows=2.
CPU preset
... --cpu-used=6 ...
--cpu-used=6 requires ~30% less bitrate than x265 for same quality, gains by preset increments are relatively smaller than x264/x265.
Bit-depth
... --bit-depth=10 ...
.. -b 8..
.. -b 10..
.. -b 12..
It is recommended to set it to 10-bit even for 8-bit content for higher efficiency (due to better compression efficiency) and less banding.
Lag-in-frames
... --lag-in-frames=48 ...
More is better, up to a limit of 48 (default is 35).
Content tune
... --tune-content=default ...
default: tuned for most content. screen: tuned for screen recordings
Flags used for most native 10-bit HDR content
... --color-primaries=bt2020 --transfer-characteristics=smpte2084 --matrix-coefficients=bt2020ncl ...
Example command line for good quality
--end-usage=q --cq-level=22 --cpu-used=4 --threads=8 --bit-depth=10 --lag-in-frames=35 --enable-fwd-kf=1 --enable-qm=1 --enable-chroma-deltaq=1 --quant-b-adapt=1 --mv-cost-upd-freq=2
Example command line for fast speed
--end-usage=q --cq-level=22 --cpu-used=6 --threads=64 --tile-columns=2 --tile-rows=1 --bit-depth=8
SVT-AV1
This will be a quick guide for setting options svt-av1 when using with Av1an. For more complete documentation, you should read the official documentation:
Make sure your svt-av1 encoder is up-to-date.
Rate control
--rc
The --rc
option selects what rate control strategy you want to use.
--rc 0
- Constant rate factor--rc 1
- Variable bit rate--rc 2
- Constant bit rate
Constant rate factor
--rc 0 --crf
Constant rate factor, a.k.a. constant quality. This is the most common way of determining video quality. You set --crf to be a number between 1-63, and the encoder will work out a bit-rate to keep constant quality. The lower the number, the less compression, the higher it is, the more compression will be used. Anything lower than 20 is considered "hi-fi", 30+ is for mini encodes.
Example:
av1an ... -v " --rc 0 --crf 24 --preset 4 --input-depth 10 --tune 0" ...
Variable bit-rate
--rc 1 --tbr
Variable bit-rate. Requires you to set target bit-rate --tbr
.
Example:
av1an ... --passes 2 -v " --rc 1 --tbr 2000 --preset 4 --input-depth 10 --tune 0" ...
Preset
--preset
If RC controls the compression strategy, then the preset determines what optimisation features get enabled (at the cost of encode time). Realistically the range for preset is 0-13, with 0 being the most optimized (and slow). 0-3 is only for the latest and fastest system, or the most patient of people. 4-6 is more common among enthusiasts. You should go as low as you can bare, 4 is a good starting place for most.
Example:
... --preset 4 ...
Tune
--tune
--tune 0
- VQ--tune 1
- PSNR
VQ is subjective quality, while PSNR is an objective measurement. Most will recommend using VQ, it seems to make the image sharper as well. Default is PSNR.
Film grain
--film-grain --film-grain-denoise
Synthesize film grain! --film-grain
can be set to 1-50 (default is 0 - off), the higher the number the stronger the effect. The default behaviour is to denoise, then add the synthesized noise. But this can remove fine detail, so it is recommended to disable the denoise stage by setting --film-grain-denoise
to 0.
You can also disable the encoders denoise, it is possible to use denoising filters provided by ffmpeg and vaporsynth. These will give better results than any of the encoders internal denoise filter. ffmpeg's hqdn3d, and nlmeans filters should be a good starting point. Common vaporsynth filters include: BM3D, DFTTest, SMDegrain, and KNLMeansCL.
Example:
... --film-grain 10 --film-grain-denoise 0 ...
Input depth
--input-depth 10
You can choose a bit-depth of 8bit or 10bit. It is almost always recommended to use 10bit, even if the source is only 8bit. It is by far the most optimized, and can even fix problems inherent with 8bit.
You might not want to use 10bit if fast encode/decode is more important than video quality.
Lookahead and key frames
--lookahead --keyint
These optimisations come at the cost of increased RAM usage during encode, and worse performance when seeking during playback. But they are worth the compromise.
Lookahead will affect how many future frames the encoder will look forward to. Increases effectiveness of several optimizations. Max is 120.
Modern video files include key frames which are Intra coded pictures, and Inter frames, which store only information changed since the previously encoded reference frames. Setting keyint=24
will give you 1 second in a 24fps video. It is recommended to have 10 seconds of GOP, for a 24fps video this will now be keyint=240
.
24fps:
--lookahead 120 --keyint 240
30fps:
--lookahead 120 --keyint 300
rav1e
GIT: rav1e
Table of Contents
Important command line options
Command Line | Description |
---|---|
--quantizer | Quantizer (0-255), smaller values are higher quality (default: 100) |
-s, --speed | Speed level 0-10 (0 is best quality, 10 is fastest) (default: 6) |