from typing import Mapping
from typing import Iterable


def video_quality_options() -> Mapping[int, Iterable[str]]:
    """Map quality settings to libavcodec options.

    Keys are choices for the `-q` CLI parameter. Values are ffmpeg / libavcodec
    encoder options, see https://ffmpeg.org/ffmpeg-codecs.html and
    `ffmpeg -h encoder=mpeg1video`"""
    # libavcodec options shared between both quality settings
    lavcopts_base = [
        "-mbd", "2",
        "-trellis", "1",
        "-mpv_flags", "+cbp_rd",
        "-mpv_flags", "+mv0",
        "-b:v", "256k",
    ]
    return {
        # default quality
        1: lavcopts_base + [
            "-cmp", "2",
            "-subcmp", "2",
            "-precmp", "2",
        ],
        # high quality
        2: lavcopts_base + [
            "-cmp", "6",
            "-subcmp", "6",
            "-precmp", "6",
            "-dia_size", "3",
            "-pre_dia_size", "3",
            "-last_pred", "3",
        ],
    }