1

I want to convert frame from a video file to base64 without save in directory.

I use: img = frame.copy() to take a frame from my video and it return a numpy array.

How can i convert it into base64 to store in database and display it into web.

Thanks for your help.

1

1 Answer 1

1

The following code should work - note you'll have to switch around the format as needed, and the corresponding base64 string. In this example I've used PNG.

from PIL import Image
from io import BytesIO
import base64

data = frame.copy()

image_out = Image.fromarray(data)
buffer = BytesIO()
image_out.save(buffer, format="PNG")
base64_str = "data:image/png;base64," + base64.b64encode(buffer.getvalue()).decode("utf-8")

Output:

>>> base64_str
`data:image/png;base64,iVBORw...`
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.