I have an image as base64 encoded data (in memory, not a file), how to pass base64 data directly to moviepy ImageClip instead of a file?
Asked
Active
Viewed 203 times
-1
-
Which part specifically is the issue? – AMC Jun 26 '20 at 22:54
-
1`base64` is just a way of making sure that byte values are within a certain range, to avoid data corruption when passing data through places that might try to interpret the data as text. The underlying decoded bytes could still be in any image format. It would help to show the code you have so far - especially the code that causes the image to be in memory in the first place. – Karl Knechtel Jun 26 '20 at 23:03
-
@AMC `ImageClip` take an image file as a parameter and I want to use the base64 buffer to create an ImageClip – Stéphane Busso Jun 26 '20 at 23:06
-
@KarlKnechtel and how do you use it with ImageClip ? – Stéphane Busso Jun 26 '20 at 23:08
-
1ImageClip does not only take a filename, it also accepts a pixel array. – Tom Burrows Jun 27 '20 at 00:26
-
@tburrows13 right, and how to you get a pixel array from a base64 string? For now I do – it kind of works but I get a black image instead of my imageStéphane Busso Jun 27 '20 at 00:47
1 Answers
1
here is the solution to pass a base64 data to ImageClip:
imgdata = base64.b64decode(base64_string)
img = imageio.imread(imgdata)
image_clip = ImageClip(img)

Stéphane Busso
- 135
- 2
- 12