OPENCV-如何创建具有透明背景的WebM?

发布于 2025-02-02 20:05:34 字数 1215 浏览 4 评论 0原文

当我使用color_rgba2bgr都可以正常工作时,
但是,gif的透明背景成为黑色

示例gif grl: https://i.sstatic.net/wyoqb.gif

当我使用code> color_rgba2bgra 时, opencv 将生成无效的视频。

如何编写具有透明背景的WebM?

转换在这里起作用 https://www.aconvert.com/vide.com/video/gif-to-to-to-to-to-to-to-to--to-to--to--to--to--to--to-to--to--to--to--to--to--to--to-to---------- WebM/ 所以有可能以某种方式

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()

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

Example gif url: https://i.sstatic.net/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()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文