如何在googlecloud bucket上准备一个可写文件,以便与库保存函数一起使用

2024-09-28 01:27:54 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,我使用moviepy库从位于googlecloud bucket上的视频文件中获取gif。到目前为止,我正在使用google-cloud-storage包执行save&read操作。但我用的是包方法。现在moviepy需要一个filepath作为参数来运行它的write_gif方法来生成gif。过了一段时间,我想我可以用gsutil的解决方案。我遇到了^{}。但问题是,我无法确定如何为^ {< CD3>}创建可写入文件,因为即使在这里,我也能使用^ {CD7>}方法在^ {CD5>}对象

上打开空白桶GIF文件。
vfile = 'https://storage.googleapis.com/test.appspot.com/dir/sample.mp4'
tfile = 'https://storage.googleapis.com/test.appspot.com/dir/sample.gif' #non-existant-file

clip = VideoFileClip(vfile)
gifClip = clip.subclip(8, 10)                  

target_gc_thumb = bucket.blob('dir/sample.gif')
target_gc_thumb.upload_from_string('',content_type='image/gif') #blank-gif-file-saved

fs = gcsfs.GCSFileSystem(project='test')
with fs.open('test.appspot.com/dir/sample.gif', 'w', metadata={"Content-Type":"image/gif"}) as f:
     gifClip.write_gif(f,fps=5) #raises-error-since-it-expects-a-local-file-path

clip.close()

由于未传递表示本地文件路径的字符串,因此出现此错误:

Could not find a format to write the specified file in mode '?'

**我使用的是谷歌应用引擎标准版。因此,不需要任何与写入本地存储相关的建议。你知道吗


Tags: 文件sample方法testcomclipbucketdir

热门问题