在 Python 中迭代 Google Cloud Storage 对象

问题描述

我在一个云存储桶中有大约 40,000 张图像,我需要使用 Python 检索它们以便从图像中制作视频。目前我在 Python 中使用 for 循环,40k 图像需要 2-3 小时。如何使用多处理来加快速度?

当前伪代码

import cv2
from google.cloud import storage

frameSize = (1920,1080)
storage_client = storage.Client()
bucket_name = "name-of-my-bucket"
out = cv2.VideoWriter('output_video.mp4',cv2.VideoWriter_fourcc(*'MPEG'),2,frameSize,True)

blobs = storage_client.list_blobs(bucket_name)

for blob in blobs:
    image_string = blob.download_as_text()

    # Pre-processing the base64 string
    image_string = image_string.split(",",1)[1]

    # Decoding base64 string
    nparr = np.frombuffer(base64.b64decode(image_string),np.uint8)

    image = cv2.imdecode(nparr,cv2.IMREAD_COLOR)
    image = cv2.rotate(image,cv2.ROTATE_180)

    # Writing image to VideoWriter
    out.write(image)


out.release()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)