Vin*_*rma 5 opencv video-processing amazon-s3 python-3.x boto3
import boto3
import cv2
import numpy as np
s3 = boto3.resource('s3')
vid = (s3.Object('bucketname', 'video.blob').get()['Body'].read())
cap = cv2.VideoCapture(vid)
Run Code Online (Sandbox Code Playgroud)
这是我的代码。我在 s3 存储桶中有一个视频文件。我想用 OpenCV 对它做一些处理,我不想下载它。所以我试图将该视频文件存储到vid. 现在的问题是这type(vid)是byte导致TypeError: an integer is required (got type bytes)
第 6 行出现此错误的原因。我尝试将其转换为整数或字符串,但无法转换。
在尝试将字节转换为整数时:我提到了这个并且遇到了长度问题。这只是一个示例视频文件。当转换为字节对象时,我想要处理的实际文件会很大。
尝试将对象作为字符串获取,然后将其转换为整数:我提到了this。即使这对我来说似乎也不起作用。
如果有人能帮我解决这个问题,我将不胜感激。如果您对我的问题有任何不确定,请发表评论,我会尽力提供更多详细信息。
Vai*_*v K -6
请参阅下面的有用代码片段以在 S3 存储桶上执行各种操作。
import boto3
s3 = boto3.resource('s3', region_name='us-east-2')
Run Code Online (Sandbox Code Playgroud)
for bucket in s3.buckets.all():
print(bucket.name)
Run Code Online (Sandbox Code Playgroud)
my_bucket=s3.create_bucket(Bucket='Bucket Name', CreateBucketConfiguration={
'LocationConstraint': 'us-east-2'
})
Run Code Online (Sandbox Code Playgroud)
my_bucket = s3.Bucket('Bucket Name')
for file in my_bucket.objects.all():
print (file.key)
Run Code Online (Sandbox Code Playgroud)
import os
print(os.getcwd())
fileName="B01.jpg"
bucketName="Bucket Name"
file = open(fileName)
s3.meta.client.upload_file(fileName, bucketName, 'test2.txt')
Run Code Online (Sandbox Code Playgroud)
import matplotlib.pyplot as plt
s3 = boto3.resource('s3', region_name='us-east-2')
bucket = s3.Bucket('Bucket Name') # bucket name
object = bucket.Object('maisie_williams.jpg') # image name
object.download_file('B01.jpg') #donwload image with this name
img=plt.imread('B01.jpg') #read the downloaded image
imgplot = plt.imshow(img) #plot the image
plt.show(imgplot)
Run Code Online (Sandbox Code Playgroud)
import boto3
s3 = boto3.resource('s3', region_name='us-east-2')
bucket = s3.Bucket('Bucket Name') # bucket name
object = bucket.Object('maisie_williams.jpg') # image name
object.download_file('B01.jpg')
fileName="B01.jpg"
bucketName="Bucket Name"
file = open(fileName)
s3.meta.client.upload_file(fileName, bucketName, 'testz.jpg')
Run Code Online (Sandbox Code Playgroud)
如果您有访问密钥,那么您可能可以执行以下操作
keys = pd.read_csv('accessKeys.csv')
#creating Session for S3 buckets
session = boto3.session.Session(aws_access_key_id=keys['Access key ID'][0],
aws_secret_access_key=keys['Secret access key'][0])
s3 = session.resource('s3')
buck = s3.Bucket('Bucket Name')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2658 次 |
| 最近记录: |