2022-05-29

OpenCV - How to create webM with a transparent background?

When I'm using COLOR_RGBA2BGR all works fine,
but transparent background of the GIF become black

Example gif url: https://i.stack.imgur.com/WYOQB.gif

When I'm using COLOR_RGBA2BGRA, then OpenCV will generate an invalid video.

How can I write webM with transparent background?

Conversion works here https://www.aconvert.com/video/gif-to-webm/ so it's possible somehow

import cv2
import imageio as imageio

fourcc = cv2.VideoWriter_fourcc(*'vp09')
output = cv2.VideoWriter("video.webm", fourcc, 30.0, (512, 500))

frames_ = imageio.mimread("crazy.gif")

# frames = [cv2.cvtColor(frame, cv2.COLOR_RGBA2BGRA) for frame in frames_]
frames = [cv2.cvtColor(frame, cv2.COLOR_RGBA2BGR) for frame in frames_]

for frame in frames:
    frame = cv2.resize(frame, (512, 500))
    output.write(frame)
output.release()


No comments:

Post a Comment