Estoy tratando de usar Boto3 para obtener una transmisión de video de Kinesis y luego usar OpenCV para mostrar la transmisión y guardarla en un archivo al mismo tiempo.
El proceso de obtener la URL firmada y luego la solicitud de Getmedia parece funcionar perfectamente, pero cuando intento renderizarlo con OpenCV, parece que no funciona.
Los datos van desafiantemente a la corriente
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()Para finalmente responder a esto, encontré una solución básica utilizando la salida HLS disponible en las transmisiones de video de Kineses. Que estuvo disponible JUL 2018
He pegado la versión de trabajo de mi código a continuación.
Estoy usando variables ENV de AWS para la autenticación 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")