개발/Python
GCP 주피터 노트북 인스턴스로 GCP 버킷의 mp4 비디오 읽기
AimB
2021. 9. 5. 18:31
먼저 버킷을 공개 상태로 만들어야 한다.
https://cloud.google.com/storage/docs/access-control/making-data-public
참고.
이걸 바꾸면
버킷 - 한 파일을 누르면 다음과 같이 URL이 뜨는데
여기서 Public URL의 앞부분을 가져오면 된다.
from google.cloud import storage
bucket = storage.Client().get_bucket('버킷이름')
for blob in bucket.list_blobs():
print(blob.name)
버킷의 파일 이름은 이렇게 가져올 수 있는데,
def load_video(path, max_frames=0):
cap = cv.VideoCapture(path)
frames = []
while cap.isOpened():
ret, frame = cap.read()
# if frame is read correctly ret is True
if not ret:
break
frames.append(frame)
if len(frames) == max_frames:
break
return np.array(frames) / 255.0
X = []
bucket = storage.Client().get_bucket('버킷이름')
for blob in bucket.list_blobs():
arr=load_video('https://storage.googleapis.com/버킷이름/'+ blob.name)
X.append(arr)
이런 식으로 하면 비디오를 넘파이 어레이로 읽어올 수 있다.