def mp4_to_gif(input_fn, output_fn, framerate): # Generate the palette palette_name = 'palette.png' if get_os_name() == 'win': command = get_ffmpeg_path( ) + f" -loglevel panic -i {input_fn} -vf 'palettegen' -y {palette_name}" else: command = get_ffmpeg_path( ) + f" -loglevel panic -i {input_fn} -vf 'fps={framerate}," \ f"scale=320:640:flags=lanczos,palettegen' -y {palette_name}" # print command os.system(command) # Generate the GIF command = get_ffmpeg_path( ) + f" -loglevel panic -i {input_fn} -i {palette_name} -lavfi paletteuse -y {output_fn}" # print command os.system(command) os.remove(palette_name)
def vector_to_fast_image(img: template(), out: ndarray_type.ndarray()): # FIXME: Why is ``for i, j in img:`` slower than: for i, j in ndrange(*img.shape): r, g, b = 0, 0, 0 color = img[i, img.shape[1] - 1 - j] if static(img.dtype in [f16, f32, f64]): r, g, b = min(255, max(0, int(color * 255))) else: static_assert(img.dtype == u8) r, g, b = color idx = j * img.shape[0] + i # We use i32 for |out| since OpenGL and Metal doesn't support u8 types if static(get_os_name() != 'osx'): out[idx] = (r << 16) + (g << 8) + b else: # What's -16777216? # # On Mac, we need to set the alpha channel to 0xff. Since Mac's GUI # is big-endian, the color is stored in ABGR order, and we need to # add 0xff000000, which is -16777216 in I32's legit range. (Albeit # the clarity, adding 0xff000000 doesn't work.) alpha = -16777216 out[idx] = (b << 16) + (g << 8) + r + alpha