#compdef av1an

autoload -U is-at-least

_av1an() {
    typeset -A opt_args
    typeset -a _arguments_options
    local ret=1

    if is-at-least 5.2; then
        _arguments_options=(-s -S -C)
    else
        _arguments_options=(-s -C)
    fi

    local context curcontext="$curcontext" state line
    _arguments "${_arguments_options[@]}" : \
'*-i+[Input file to encode]:INPUT:_files' \
'*--proxy=[Input proxy file for Scene Detection and Target Quality]:PROXY:_files' \
'-o+[Video output file]:OUTPUT_FILE:_files' \
'--temp=[Temporary directory to use]:TEMP:_files' \
'-l+[Log file location]:LOG_FILE:_default' \
'--log-file=[Log file location]:LOG_FILE:_default' \
'--log-level=[Set log level for log file (does not affect command-line log level)]:LOG_LEVEL:_default' \
'(-i)--completions=[Generate shell completions for the specified shell and exit]:SHELL:(bash elvish fish powershell zsh)' \
'--max-tries=[Maximum number of chunk restarts for an encode]:MAX_TRIES:_default' \
'-w+[Number of workers to spawn \[0 = automatic\]]:WORKERS:_default' \
'--workers=[Number of workers to spawn \[0 = automatic\]]:WORKERS:_default' \
'--set-thread-affinity=[Pin each worker to a specific set of threads of this size (disabled by default)]:SET_THREAD_AFFINITY:_default' \
'--scaler=[Scaler used for scene detection (if --sc-downscale-height XXXX is used) and VMAF calculation]:SCALER:_default' \
'*--vspipe-args=[Pass python argument(s) to the script environment --vspipe-args "message=fluffy kittens" "head=empty"]' \
'-s+[File location for scenes]:SCENES:_files' \
'--scenes=[File location for scenes]:SCENES:_files' \
'--split-method=[Method used to determine chunk boundaries]:SPLIT_METHOD:_default' \
'--sc-method=[Scene detection algorithm to use for av-scenechange]:SC_METHOD:_default' \
'--sc-downscale-height=[Optional downscaling for scene detection]:SC_DOWNSCALE_HEIGHT:_default' \
'--sc-pix-format=[Perform scene detection with this pixel format]:SC_PIX_FORMAT:_default' \
'-x+[Maximum scene length]:EXTRA_SPLIT:_default' \
'--extra-split=[Maximum scene length]:EXTRA_SPLIT:_default' \
'--extra-split-sec=[Maximum scene length, in seconds]:EXTRA_SPLIT_SEC:_default' \
'--min-scene-len=[Minimum number of frames for a scenecut]:MIN_SCENE_LEN:_default' \
'--force-keyframes=[Comma-separated list of frames to force as keyframes]:FORCE_KEYFRAMES:_default' \
'-e+[Video encoder to use]:ENCODER:_default' \
'--encoder=[Video encoder to use]:ENCODER:_default' \
'-v+[Parameters for video encoder]:VIDEO_PARAMS:_default' \
'--video-params=[Parameters for video encoder]:VIDEO_PARAMS:_default' \
'-p+[Number of encoder passes]:PASSES:_default' \
'--passes=[Number of encoder passes]:PASSES:_default' \
'-f+[FFmpeg filter options]:FFMPEG_FILTER_ARGS:_default' \
'--ffmpeg=[FFmpeg filter options]:FFMPEG_FILTER_ARGS:_default' \
'-a+[Audio encoding parameters (ffmpeg syntax)]:AUDIO_PARAMS:_default' \
'--audio-params=[Audio encoding parameters (ffmpeg syntax)]:AUDIO_PARAMS:_default' \
'-m+[Method used for piping exact ranges of frames to the encoder]:CHUNK_METHOD:_default' \
'--chunk-method=[Method used for piping exact ranges of frames to the encoder]:CHUNK_METHOD:_default' \
'--chunk-order=[The order in which av1an will encode chunks]:CHUNK_ORDER:_default' \
'--photon-noise=[Generates a photon noise table and applies it using grain synthesis \[strength\: 0-64\] (disabled by default)]:PHOTON_NOISE:_default' \
'--photon-noise-width=[Manually set the width for the photon noise table]:PHOTON_NOISE_WIDTH:_default' \
'--photon-noise-height=[Manually set the height for the photon noise table]:PHOTON_NOISE_HEIGHT:_default' \
'-c+[Determines method used for concatenating encoded chunks and audio into output file]:CONCAT:_default' \
'--concat=[Determines method used for concatenating encoded chunks and audio into output file]:CONCAT:_default' \
'--pix-format=[FFmpeg pixel format]:PIX_FORMAT:_default' \
'--zones=[Path to a file specifying zones within the video with differing encoder settings.]:ZONES:_files' \
'--cache-mode=[Set chunk cache index mode]:CACHE_MODE:_default' \
'--vmaf-path=[Path to VMAF model (used by --vmaf and --target-quality)]:VMAF_PATH:_files' \
'--vmaf-res=[Resolution used for VMAF calculation]:VMAF_RES:_default' \
'--probe-res=[Resolution used for Target Quality metric calculation in the form of \`widthxheight\` where width and height are positive integers]:PROBE_RES:_default' \
'--vmaf-threads=[Number of threads to use for target quality VMAF calculation]:VMAF_THREADS:_default' \
'--vmaf-filter=[Filter applied to source at VMAF calcualation]:VMAF_FILTER:_default' \
'--target-quality=[Target a metric score range for encoding (disabled by default)]:TARGET_QUALITY:_default' \
'--qp-range=[Quantizer range bounds for target quality search (disabled by default)]:QP_RANGE:_default' \
'--interp-method=[Interpolation methods for target quality probing]:INTERP_METHOD:_default' \
'--target-metric=[The metric used for Target Quality mode]:TARGET_METRIC:_default' \
'--probes=[Maximum number of probes allowed for target quality]:PROBES:_default' \
'--probing-rate=[Only use every nth frame for VMAF calculation, while probing]:PROBING_RATE:_default' \
'--probe-video-params=[Parameters for video encoder during Target Quality probing]:PROBE_VIDEO_PARAMS:_default' \
'*--probing-vmaf-features=[VMAF calculation features for target quality probing]' \
'--probing-stat=[Statistical method for calculating target quality from sorted probe scores]:PROBING_STAT:_default' \
'(--verbose)-q[Disable printing progress to the terminal]' \
'(--verbose)--quiet[Disable printing progress to the terminal]' \
'--verbose[Print extra progress info and stats to terminal]' \
'-r[Resume previous session from temporary directory]' \
'--resume[Resume previous session from temporary directory]' \
'-k[Do not delete the temporary folder after encoding has finished]' \
'--keep[Do not delete the temporary folder after encoding has finished]' \
'--force[Do not check if the encoder arguments specified by -v/--video-params are valid]' \
'--no-defaults[Do not include Av1an'\''s default set of encoder parameters]' \
'-y[Overwrite output file, without confirmation]' \
'(-y)-n[Never overwrite output file, without confirmation]' \
'--sc-only[Run the scene detection only before exiting]' \
'--tile-auto[Estimate tile count from source]' \
'--ignore-frame-mismatch[Ignore any detected mismatch between scene frame count and encoder frame count]' \
'--chroma-noise[Adds chroma grain synthesis to the grain table generated by \`--photon-noise\`. (Default\: false)]' \
'--vmaf[Plot an SVG of the VMAF for the encode]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
&& ret=0
}

(( $+functions[_av1an_commands] )) ||
_av1an_commands() {
    local commands; commands=()
    _describe -t commands 'av1an commands' commands "$@"
}

if [ "$funcstack[1]" = "_av1an" ]; then
    _av1an "$@"
else
    compdef _av1an av1an
fi
