Sim*_*mon 5 python svg ffmpeg cairo python-imaging-library
我正在尝试将 Cairo ImageSurface 转换为 PIL Image 对象,以便可以将其传递到 ffmpeg 管道。
到目前为止我所拥有的是:
其中 svgstr 将图像的 SVG 数据保存为字符串。
img = cairo.ImageSurface(cairo.FORMAT_ARGB32, 386,1080)
ctx = cairo.Context(img)
#render the svg as a png
handle= rsvg.Handle(None, svgstr)
handle.render_cairo(ctx)
imgPIL = Image.frombuffer("RGBA",( img.get_width(),img.get_height() ),img.get_data(),"raw","RGBA",0,1)
img44 = imgPIL.convert("RGBA")
img44.save(p.stdin,"PNG")
Run Code Online (Sandbox Code Playgroud)
如果我将图像保存到文件而不是将其传递到管道,我会得到某种版本的灰度。当传递到管道时,它会给出“IOError:[Errno 32] Broken pipeline”
最终,我只是尝试将 SVG 数据转换为某种对象,我可以将其传递到 ffmpeg 管道以将图像连接到视频中,而无需先将图像保存到磁盘。
| 归档时间: |
|
| 查看次数: |
711 次 |
| 最近记录: |