[英]How can you effectively pull an Amazon Kinesis Video Stream for custom python processing?
我有一個流到 Amazon Kinesis Video Streams 的 RTSP 流。 我希望能夠在流的每一幀上運行自定義圖像處理。 我有python寫的自定義圖像處理算法,所以自然希望能用python拉出KVS,輸入到圖像處理算法中。 首先,我嘗試按照這篇文章中的建議制作一個只顯示 KVS 流的 Python 應用程序(但是這篇文章使用 Amazon Rekognition 進行自定義處理,我的用例(自定義 Python 處理)略有不同)。
我的問題是:
為什么我的 HLS python KVS 播放器滯后/斷斷續續(隨機暫停,然后很快播放過去幾秒鍾)? 然而, 這里可用的 HLS 流光看起來相當不錯。
如何有效地提取 Amazon Kinesis Video Stream 以進行自定義 Python 處理? 使用 HLS 與亞馬遜的 GetMedia API 的優缺點是什么?
為此使用 Sagemaker 是否值得? 對於我的圖像處理,我只想進行推理,不需要訓練網絡,它已經訓練好了。
kvs_player.py
代碼:
import boto3
import cv2
STREAM_NAME = "ExampleStream"
STREAM_ARN = "MY_STREAM_ARN"
AWS_REGION = 'us-east-1'
def hls_stream():
kv_client = boto3.client("kinesisvideo", region_name=AWS_REGION)
endpoint = kv_client.get_data_endpoint(
StreamName=STREAM_NAME,
APIName="GET_HLS_STREAMING_SESSION_URL"
)['DataEndpoint']
print(endpoint)
# # Grab the HLS Stream URL from the endpoint
kvam_client = boto3.client("kinesis-video-archived-media", endpoint_url=endpoint, region_name=AWS_REGION)
url = kvam_client.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")
if __name__ == '__main__':
hls_stream()
一些通用的答案
對於范圍更廣和更有針對性的問題,您可以直接轉到 GitHub 頁面,了解相關的相應項目/資產,並剪切問題,包括詳細描述和詳細日志。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.