def get_ffmpeg_quality(quality_percent):
    """Convert a value between 0-100 to an ffmpeg quality value (2-31).

    Note that this is only applicable to the mjpeg encoder (which is used for
    jpeg images). mjpeg values works in reverse, i.e. lower is better.
    """
    if not 0 <= quality_percent <= 100:
        raise ValueError("Video quality must be between 0 and 100")

    low, high = 2, 31
    span = high - low
    factor = float(quality_percent) / 100.0
    return int(low + round(span * (1 - factor)))