gpt4 book ai didi

python - Boto3 Kinesis Video GetMedia 和 OpenCV

转载 作者:太空狗 更新时间:2023-10-29 21:56:07 25 4
gpt4 key购买 nike

我正在尝试使用 Boto3 从 kinesis 获取视频流,然后使用 OpenCV 显示提要并同时将其保存到文件中。

获取签名 URL 和 Getmedia 请求的过程似乎完美无缺,只是当我尝试使用 OpenCV 呈现它时,它似乎不起作用。

数据正在挑衅地流向流

import boto3
import numpy as np
import cv2

kinesis_client = boto3.client('kinesisvideo',
region_name='eu-west-1',
aws_access_key_id='ACC',
aws_secret_access_key='KEY'
)

response = kinesis_client.get_data_endpoint(
StreamARN='ARN',
APIName='GET_MEDIA'
)
video_client = boto3.client('kinesis-video-media',
endpoint_url=response['DataEndpoint']
)
stream = video_client.get_media(
StreamARN='ARN',
StartSelector={'StartSelectorType': 'NOW'}
)
# print(stream)


datafeed = stream['Payload'].read()
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))

while(True):
ret, frame = stream['Payload'].read()


out.write(frame)

cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()

最佳答案

为了最终回答这个问题,我找到了一个使用 HLS 输出的基本解决方案,该输出可从 kineses 视频流中获取。 2018 年 7 月可用

博文:https://aws.amazon.com/blogs/aws/amazon-kinesis-video-streams-adds-support-for-hls-output-streams/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+AmazonWebServicesBlog+%28Amazon+Web+Services+Blog%29

我在下面粘贴了我的代码的工作版本。

我正在使用 AWS ENV 变量进行 BOTO3 身份验证。

import boto3
import cv2

STREAM_NAME = "test-stream"
kvs = boto3.client("kinesisvideo")
# Grab the endpoint from GetDataEndpoint
endpoint = kvs.get_data_endpoint(
APIName="GET_HLS_STREAMING_SESSION_URL",
StreamName=STREAM_NAME
)['DataEndpoint']

print(endpoint)

# # Grab the HLS Stream URL from the endpoint
kvam = boto3.client("kinesis-video-archived-media", endpoint_url=endpoint)
url = kvam.get_hls_streaming_session_url(
StreamName=STREAM_NAME,
PlaybackMode="LIVE"
)['HLSStreamingSessionURL']


vcap = cv2.VideoCapture(url)

while True:
# Capture frame-by-frame
ret, frame = vcap.read()

if frame is not None:
# Display the resulting frame
cv2.imshow('frame',frame)

# Press q to close the video windows before it ends if you want
if cv2.waitKey(22) & 0xFF == ord('q'):
break
else:
print("Frame is None")
break

# When everything done, release the capture
vcap.release()
cv2.destroyAllWindows()
print("Video stop")

关于python - Boto3 Kinesis Video GetMedia 和 OpenCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50061634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com