注册了亚马逊海外账号(这部分就绑定信-用卡比较麻烦,但可以tb搜索解决办法)
本实验让用户可以通过亚马逊云科技,快速实现视频推流、内容识别、视频流播放、识别结果推送这几大功能。主要是方便搭建出海业务。
虽然手上有实验指导文档,但是指导文档并不方便复制粘贴。而且自己再记录一遍,便于记录一些arn等实验过程中特有的字符串。
由于本实验最后,有删除服务的操作,因此,本文带有的一些特定值(用户密码、token、云服务的arn等),已经无效,因此不怕。
us-east-1
添加用户
user1/pass@1234
创建访问密钥
- AKIA5QQHAJ5RJ6KAJUEQ
- g5n9zcXuJ+0VtD1nR/eFtnTHLHCHZWKLX31JXXBy
https://928801378146.signin.aws.amazon.com/console
(树莓派推流和电脑推流二选一,本次实验不用树莓派推流)
- $ sudo apt-get update
- $ sudo apt-get install libssl-dev libcurl4-openssl-dev liblog4cplus-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev gstreamer1.0-plugins-base-apps gstreamer1.0-plugins-bad gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-tools cmake
- $ cd ~/Downloads/
- $ git clone --recursive https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-cpp.git
-
- $ cd ~/amazon-kinesis-video-streams-producer-sdk-cpp
- $ git submodule update --init
-
- mkdir build && cd build
- cmake .. -DBUILD_GSTREAMER_PLUGIN=ON -DBUILD_DEPENDENCIES=OFF
**注意:**这里的ACCESS_KEY和SECRET_KEY都是你前面账号生成的凭证,需要自行修改
- export AWS_DEFAULT_REGION="eu-west-1"
- export AWS_ACCESS_KEY_ID="AKIA5QQHAJ5RJ6KAJUEQ"
- export AWS_SECRET_ACCESS_KEY="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"
- export GST_PLUGIN_PATH=$HOME/Downloads/amazon-kinesis-video-streams-producer-sdk-cpp/build
- export LD_LIBRARY_PATH=$HOME/Downloads/amazon-kinesis-video-streams-producer-sdk-cpp/open-source/local/lib
-
- cd ~/amazon-kinesis-video-streams-producer-sdk-cpp/build
-
- libcamera-vid -n -t 0 -o - | gst-launch-1.0 -v fdsrc do-timestamp=TRUE ! h264parse config-interval=1 ! video/x-h264,stream-format=avc,alignment=au ! kvssink stream-name="kvs-workshop-stream"
(设备推流和电脑推流二选一)
安装库(步骤4)
- $ sudo apt update
- $ sudo apt install -y cmake gstreamer1.0-plugins-bad gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-tools libgstreamer-plugins-base1.0-dev
磁盘空间扩展
在Cloud9终端中执行以下命令,它将扩展磁盘并重新启动实例
请等到实例重新启动,因为您将在实例重新启动时看到Connecting...
- $ wget https://awsj-iot-handson.s3-ap-northeast-1.amazonaws.com/kvs-workshop/resize_volume.sh
- $ chmod +x resize_volume.sh
- $ ./resize_volume.sh
实例重新启动后,点击link后,在终端中运行以下命令以检查磁盘空间
$ df -h
- $ cd ~/
- $ git clone --recursive https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-cpp.git # 克隆仓库
注意: 如果您忘记向命令添加--recursive,请执行以下命令;如果已增加该参数请忽略。
- $ cd ~/amazon-kinesis-video-streams-producer-sdk-cpp
- $ git submodule update --init
构建SDK(步骤6)
此步骤大约需要 10 到 15 分钟才能完成。您可以在等待期间继续执行下面的“创建流”和“下载视频以供播放”步骤。
以下命令下载并构建依赖库。此命令大约需要10分钟才能完成。
- $ mkdir -p ~/amazon-kinesis-video-streams-producer-sdk-cpp/build
-
- $ cd ~/amazon-kinesis-video-streams-producer-sdk-cpp/build
-
- $ cmake -DBUILD_GSTREAMER_PLUGIN=ON ..
- $ make -j2
下载测试视频
- $ cd ~/Downloads
- $ wget https://awsj-iot-handson.s3-ap-northeast-1.amazonaws.com/kvs-workshop/sample.mp4
下载awscli
- $ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
- $ unzip awscliv2.zip
- $ sudo ./aws/install
- $ aws --version
CLI完成安装后,在自己的电脑终端进行以下操作:
- $ aws configure # 配置aws临时凭证
- AWS Access Key ID [None]: [输入自己账号的AWS Access Key ID]
- AWS Secret Access Key [None]: [输入自己账号的AWS Secret Access Key]
- Default region name [None]: eu-west-1
- Default output format [None]: json
- $ aws sts get-session-token
- {
- "Credentials": {
- "AccessKeyId": "ASIA5QQHAJ5RELIPKRN2",
- "SecretAccessKey": "KQw2GrAzI95682joCv/SGRBSQUDY7v+ewoq1/yVo",
- "SessionToken": "IQoJb3JpZ2luX2VjEHgaCWV1LXdlc3QtMSJHMEUCIQCgRM77w+avc5u8CBtLAiYcaLbhlNyYhGLpH+tlcZNxyQIgT0HvWvHuDv9SlkUbU0mDRUXwJqUXXbKfOFhAthyiimwq9AEI0f//ARAAGgw5Mjg4MDEzNzgxNDYiDIId1K5mWVnLNPpbkCrIAVaR6BsD6FRswWPWLr7+1FufVqzpZrLIjtgC2nw6tQ3KRGkhj810XeQXr7rwAaZoWiGTSCKOsVMGoMXseZmtNLJFmPvIIDsdmZCWIAfaMRnHSja+uO3P3bG7WXgYbK6rFp9s3wnbXpGD886kuln2jnyCV2noaCwaB1+Vygt83Vhromp60wIiRr9pYf8iaUOBGCPOFgPBIswcSnoBT63dADIBbh9RAyGHdyIL16kikjoeB4xIjD6ENSxd3Cfhw5C+3lNOJHQKrtTJMMq5uJcGOpgBtts/kfedZtNoRIRSJ03kTLLK7jZaMwJjsVS96ygzjvDTpiotn0EJ3HzgqE8elgxy+EbQZWbZEHpkUcl/zBpSFmoi0GkF/FN2GynyoFjA+ncigdp4n/eEUU8BSCvWEzZrCD9KXwzg2jotoOdeY5dZJiMBYY5PHsfHib8UuX9vAuz165Skb7LjfdVjzr2f+9AFtZ/N50H6gfY=",
- "Expiration": "2022-08-06T19:48:26+00:00"
- }
- }
接下来,打开Cloud9终端并执行以下命令来设置环境变量。
**注意:**这里的ACCESS_KEY和SECRET_KEY与SESSION_TOKEN都是上一步json返回获得的,需要自行修改【此凭证是一次性的,再次操作需要重新生成上一步的值】
- export AWS_DEFAULT_REGION="eu-west-1"
- export AWS_ACCESS_KEY_ID="ASIA5QQHAJ5RELIPKRN2"
- export AWS_SECRET_ACCESS_KEY="KQw2GrAzI95682joCv/SGRBSQUDY7v+ewoq1/yVo"
- export AWS_SESSION_TOKEN="IQoJb3JpZ2luX2VjEHgaCWV1LXdlc3QtMSJHMEUCIQCgRM77w+avc5u8CBtLAiYcaLbhlNyYhGLpH+tlcZNxyQIgT0HvWvHuDv9SlkUbU0mDRUXwJqUXXbKfOFhAthyiimwq9AEI0f//ARAAGgw5Mjg4MDEzNzgxNDYiDIId1K5mWVnLNPpbkCrIAVaR6BsD6FRswWPWLr7+1FufVqzpZrLIjtgC2nw6tQ3KRGkhj810XeQXr7rwAaZoWiGTSCKOsVMGoMXseZmtNLJFmPvIIDsdmZCWIAfaMRnHSja+uO3P3bG7WXgYbK6rFp9s3wnbXpGD886kuln2jnyCV2noaCwaB1+Vygt83Vhromp60wIiRr9pYf8iaUOBGCPOFgPBIswcSnoBT63dADIBbh9RAyGHdyIL16kikjoeB4xIjD6ENSxd3Cfhw5C+3lNOJHQKrtTJMMq5uJcGOpgBtts/kfedZtNoRIRSJ03kTLLK7jZaMwJjsVS96ygzjvDTpiotn0EJ3HzgqE8elgxy+EbQZWbZEHpkUcl/zBpSFmoi0GkF/FN2GynyoFjA+ncigdp4n/eEUU8BSCvWEzZrCD9KXwzg2jotoOdeY5dZJiMBYY5PHsfHib8UuX9vAuz165Skb7LjfdVjzr2f+9AFtZ/N50H6gfY="
**在本实验中,AWS CLI用于获取IAM用户的临时凭据,以简化过程,但每次在真正的相机设备上都很难做到这一点。在现实世界的用例中,您可以使用AWS IoT管理的客户端证书来获取凭据。如何使用AWS IoT凭据提供商消除设备中对硬编码AWS凭据的需求 **
在Cloud9终端中运行以下命令来设置环境变量。
- export GST_PLUGIN_PATH=$HOME/amazon-kinesis-video-streams-producer-sdk-cpp/build
- export LD_LIBRARY_PATH=$HOME/amazon-kinesis-video-streams-producer-sdk-cpp/open-source/local/lib
然后运行以下命令上传视频。
- cd ~/amazon-kinesis-video-streams-producer-sdk-cpp/build
- while true; do ./kvs_gstreamer_file_uploader_sample kvs-workshop-stream ~/sample.mp4 $(date +%s) audio-video && sleep 10s; done
arn:aws:s3:::video-event-analytics-user1
arn:aws:sns:eu-west-1:928801378146:video-event-sns
arn:aws:kinesisvideo:eu-west-1:928801378146:stream/kvs-workshop-stream/1659770096408
arn:aws:iam::928801378146:role/Rekognition_call_s3_kvs_Role
因为Rekognition Streaming Video Events是2022年4月底才发布的新功能,要采用aws cli创建rekognition-stream-processor使用该功能,需要将您的cli升级到包含rekognition这个新特性的版本,这里我们将cli升级到最新版本。
执行如下命名升级AWS Cli到最新版本
- cd
- curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
- unzip awscliv2.zip
- sudo ./aws/install
- sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update
File -> New FIle
创建createstreamprocessor.json
- {
- "DataSharingPreference": {
- "OptIn":true
- },
- "Input": {
- "KinesisVideoStream": {
- "Arn": "你的kvs ARN值"
- }
- },
- "Name": "video_event_stream_processor",
- "Output": {
- "S3Destination": {
- "Bucket": "你的桶名",
- "KeyPrefix": "video-result"
- }
- },
- "NotificationChannel": {
- "SNSTopicArn": "你的SNS主题 ARN值"
- },
- "RoleArn": "你的角色 ARN值",
- "Settings": {
- "ConnectedHome": {
- "Labels": [
- "PERSON"
- ],
- "MinConfidence": 80
- }
- },
- "RegionsOfInterest": [
- {
- "BoundingBox": {
- "Top": 0.11,
- "Left": 0.22,
- "Width": 0.33,
- "Height": 0.44
- }
- },
- {
- "Polygon": [
- {
- "X": 0.11,
- "Y": 0.11
- },
- {
- "X": 0.22,
- "Y": 0.22
- },
- {
- "X": 0.33,
- "Y": 0.33
- }
- ]
- }
- ]
- }
cloud9 上传
- $ aws rekognition create-stream-processor --region eu-west-1 --cli-input-json file:///home/ubuntu/environment/createstreamprocessor.json
-
- $ aws rekognition describe-stream-processor --name video_event_stream_processor --region eu-west-1
准备启动rekognition-stream-processor的json文件
使用之前的上传办法再上传一个文件
startstreamprocessor.json内容如下所示:
- {
- "Name": "video_event_stream_processor",
- "StartSelector": {
- "KVSStreamStartSelector": {
- "ProducerTimestamp": 1651702500
- }
- },
- "StopSelector": {
- "MaxDurationInSeconds": 30
- }
- }
$ aws rekognition start-stream-processor --region eu-west-1 --cli-input-json file:///home/ubuntu/environment/startstreamprocessor.json
stream-processor按照start-stream-processor中设定的视频检测起始与结束条件完成对设置的目标标签(Person/Package/Pet/ALL)检测处理后,将检测结果保存到S3并通过配置的SNS发送出去。
观测S3中保存的检测结果
执行
注意: 这里的video-event-analytics-123123123123是示例桶的名字,这里需要改成你自己的s3桶名
$ aws s3 ls video-event-analytics-user1 --recursive
- $ aws s3 rm s3://video-event-analytics-user1 --recursive
- $ aws s3 rb s3://video-event-analytics-user1
- $ aws kinesisvideo delete-stream --stream-arn arn:aws:kinesisvideo:eu-west-1:928801378146:stream/kvs-workshop-stream/1659770096408
- $ aws sns delete-topic --topic-arn arn:aws:sns:eu-west-1:928801378146:video-event-sns
- $ aws sns unsubscribe --subscription-arn arn:aws:sns:eu-west-1:928801378146:video-event-sns:8aac545e-0779-40fe-8b0a-d93b2c7a6185
- $ aws rekognition delete-stream-processor --name=video_event_stream_processor
后面还把cloud9的服务删除了。
技术方面:亚马逊开源的kvs不错。然后就是我之前用过腾讯服务器、阿里云服务器,亚马逊的服务器做得更有弹性,能增能删除。不过就是未用熟,信-用卡也是别人帮忙的,因此怕消费多了钱。不过这次活动说是账号加入了组织,由组织统一交钱的。亚马逊云服务的创建和使用,让人体验出科技的先进感。
心情:这个实验是在周末做的,有点折腾啊。不过做完实验第二天就收到了礼物-一件T恤,曾经收到过google活动的T恤我胖了穿不下,现在的这件是大概后颈处有“亚马逊云科技”几个字和LOGO,因此我平时可能就在家里穿穿而已啦哈哈。