Boto3 Kinesis视频GetMedia和OpenCV [英] Boto3 Kinesis Video GetMedia and OpenCV

查看:162
本文介绍了Boto3 Kinesis视频GetMedia和OpenCV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use Boto3 to get a video stream from kinesis and then use OpenCV to display the feed and save it to a file at the same time.

获取签名的URL然后获取Getmedia请求的过程似乎完美地工作,只是当我试图使用OpenCV呈现它时,它似乎不起作用.

The process of getting the signed URL and then the Getmedia request seems to work perfectly it's just when I'm trying to render it using OpenCV it doesn't seem to work.

数据反抗地流向流

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 Output(可通过kineses视频流获得)的基本解决方案.已于2018年7月上市

To finally answer this I found a basic solution using the HLS Output available form kineses video streams. Which became available JUL 2018

博客文章:我在下面粘贴了我的代码的工作版本.

Ive pasted the working version of my code below.

我使用AWS ENV变量进行BOTO3身份验证.

Im using AWS ENV varables for the BOTO3 authtication.

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")

这篇关于Boto3 Kinesis视频GetMedia和OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆