def convert_mp4_to_gif()

in generate_side_by_side.py [0:0]


def convert_mp4_to_gif(path_to_mp4, path_to_gif, slow_motion=False):
    path_to_gif = str(path_to_gif)
    fps = 30
    # Use slow motion for more subtle differences
    if slow_motion:
        fps = 100
        path_to_gif = path_to_gif.replace(".gif", "-slow-motion.gif")

    # Generate palette for a better quality
    subprocess.check_output(
        [
            "ffmpeg",
            "-i",
            str(path_to_mp4),
            "-vf",
            f"fps={fps},scale=1024:-1:flags=lanczos,palettegen",
            "-y",
        ]
        + [path_to_gif.replace(".gif", "-palette.gif")]
    )

    subprocess.check_output(
        [
            "ffmpeg",
            "-i",
            str(path_to_mp4),
            "-i",
            path_to_gif.replace(".gif", "-palette.gif"),
            "-filter_complex",
            f"fps={fps},scale=1024:-1:flags=lanczos[x];[x][1:v]paletteuse",
            "-loop",
            "-1",
        ]
        + [str(path_to_gif)]
    )
    subprocess.check_output(["rm", path_to_gif.replace(".gif", "-palette.gif")])

    return str(path_to_gif)