LoginSignup
3
2

More than 5 years have passed since last update.

コンビニで買った育てるサラダをrasPiで撮ってKinesisに流してゴニョゴニョする 中編

Last updated at Posted at 2018-11-14

朝起きると・・

終わってた

芽も出てた。

そんなわけで昨日のつづきです。

IAM

じゃあ、認証の設定。いきなりアンチパターンをぶっこみますよ。

2018-11-13 (1).png

専用アカウントを作ってなおかつKinesisVideoStreamsFullAccessをつけたりました。まあ、個人アカウントだしいいよね。

アクセスキーはこちらに。

~/.aws/credentials
[default]
aws_access_key_id = your_access_key_id
aws_secret_access_key = your_secret_access_key

なんとなくchmod 600もしておく。
そして./startすると・・・

 $ ./start
./start: error while loading shared libraries: liblog4cplus-1.2.so.5: cannot open shared object file: No such file or directory

ここにきて初怒られいただきました。このままスムーズにいくかとおもいきや。でもなんかありがちなライブラリな気がするな。log4c+?

ググってみたらこんなのがみつかって、
https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-java/issues/7
さらには

Release 1.4.1 (8th May 2018)
Update log4cplus download link in install-script

最近のにはdownloadする仕組みが入ってるってこと。でもまあ入れればいいんでしょ。要は。
あれ、でもfindしてみたらここにあんで。
上のdownload linkうんぬんは関係なしか。

/home/pi/RaspiStream/amazon-kinesis-video-streams-producer-sdk-cpp/kinesis-video-native-build/downloads/local/lib/liblog4cplus-1.2.so.5
/home/pi/RaspiStream/amazon-kinesis-video-streams-producer-sdk-cpp/kinesis-video-native-build/downloads/local/lib/liblog4cplus-1.2.so.5.1.4
/home/pi/RaspiStream/amazon-kinesis-video-streams-producer-sdk-cpp/kinesis-video-native-build/downloads/local/lib/liblog4cplus.so
/home/pi/RaspiStream/amazon-kinesis-video-streams-producer-sdk-cpp/kinesis-video-native-build/downloads/local/lib/liblog4cplus.la

しかし、ここのliblog4cplus.soにpath通ればいいだけやないの?カッコ悪いけどダイレクトにpath通してみるか。

$  sudo /bin/bash -c  "echo '/home/pi/RaspiStream/amazon-kinesis-video-streams-producer-sdk-cpp/kinesis-video-native-build/downloads/local/lib/' > /etc/ld.so.conf.d/raspistream.conf"
$ sudo ldconfig

通した。そして再スタート。

$ ./start

なんか画面にどばっと出てきたけどどうかねこれ。なんか赤文字もあんで。

[0x0000000076fec000] [level 3] platform-utils
TestBody(): Allocator perf time: 44154769, time per iteration: 44.154769/home/pi/RaspiStream/amazon-kinesis-video-streams-producer-sdk-cpp/kinesis-video-pic/src/heap/tst/HeapApiFunctionalityTest.cpp:403: Failure
Value of: duration <= durationSystem * 1.2
  Actual: false
Expected: true
/home/pi/RaspiStream/amazon-kinesis-video-streams-producer-sdk-cpp/kinesis-video-pic/src/heap/tst/HeapApiFunctionalityTest.cpp:404: Failure
Value of: iterationDuration <= iterationDurationSystem * 1.2
  Actual: false
Expected: true
[  FAILED  ] HeapApiFunctionalityTest.randomAllocFreeWindowedPerf (7631 ms)
[ RUN      ] HeapApiFunctionalityTest.randomAllocFreeMultiStreamWindowedPerf

[0x0000000076fec000] [level 3] platform-utils
heapInitialize(): Initializing native heap with limit size 268435456, spill ratio 20% and flags 0x00000002
[0x0000000076fec000] [level 3] platform-utils
heapInitialize(): Creating system heap.
[0x0000000076fec000] [level 3] platform-utils

heapInitialize(): Heap is initialized OK
[0x0000000076fec000] [level 3] platform-utils
heapRelease(): Freeing native heap.
[0x0000000076fec000] [level 3] platform-utils
TestBody(): System Allocator perf time: 298739127, time per iteration: 298.739127
[0x0000000076fec000] [level 3] platform-utils
heapInitialize(): Initializing native heap with limit size 268435456, spill ratio 20% and flags 0x00000001
[0x0000000076fec000] [level 3] platform-utils
heapInitialize(): Creating AIV heap.
[0x0000000076fec000] [level 3] platform-utils

と思ってたらSegmentation faultで落ちた。
メモリ?heapInitialize(): Initializing native heap with limit size 268435456, spill ratio 20% and flags 0x00000001

あ、これテストなのか。スルーして進めてみよう。

パラメーターはちょろっと調整。512mのとこを256mに。

$ vi ../kinesis-video-gst-demo/kinesis_video_gstreamer_sample_app.cpp
126c126
<         device_info.storageInfo.storageSize = 512 * 1024 * 1024;
---
>         device_info.storageInfo.storageSize = 256 * 1024 * 1024;

ちなみにソースみてたらこんなの書いてあった

"Usage: AWS_ACCESS_KEY_ID=SAMPLEKEY AWS_SECRET_ACCESS_KEY=SAMPLESECRET ./kinesis_video_gstreamer_sample_app -w width -h height -f framerate -b bitrateInKBPS my-stream-name

こんなオプションなのね。やってみよう。

$ ./kinesis_video_gstreamer_sample_app -w 640 -h 360 -f 10 -b 128 RaspiStreamturtle

createKinesisVideoStream(): Creating Kinesis Video Stream.
[DEBUG][2018-11-13 12:12:40] describeStreamHandler invoked
[DEBUG][2018-11-13 12:12:40] Awaiting for the stream to become ready...
[INFO ][2018-11-13 12:12:40] Refreshing credentials. Force refreshing: 0 Now time is: 1542111160 Expiration: 0
[WARN ][2018-11-13 12:12:41] HTTP Error 403: Response: {"message":"The security token included in the request is invalid."}
Request URL: https://kinesisvideo.us-west-2.amazonaws.com/describeStream
Request Headers:
Authorization: AWS4-HMAC-SHA256 Credential=AccessKey/20181113/us-west-2/kinesisvideo/aws4_request, SignedHeaders=content-type;host;user-agent;x-amz-date, Signature=074c61164a62a796e32e7b52ed1cd191be958696a963b87ca11d9ca6a14ffdd9
content-type: application/json
host: kinesisvideo.us-west-2.amazonaws.com
user-agent: AWS-SDK-KVS/1.5.0 GCC/4.9.2 Linux/4.1.13-v7+ armv7l
X-Amz-Date: 20181113T121240Z
[DEBUG][2018-11-13 12:12:41] describeStream response: {"message":"The security token included in the request is invalid."}
[INFO ][2018-11-13 12:12:41] Describe stream did not find the stream RaspiStreamturtle in Kinesis Video (stream will be created)
[INFO ][2018-11-13 12:12:41]
describeStreamResultEvent(): Describe stream result event.
[ERROR][2018-11-13 12:12:41] Submitting event result for stream: 8258454 failed with: 1375731728
[ERROR][2018-11-13 12:12:41] Reporting stream error. Errored timecode: 0 Status: 1375731728
[INFO ][2018-11-13 12:13:10] Freeing Kinesis Video Stream RaspiStreamturtle
[INFO ][2018-11-13 12:13:10]
freeKinesisVideoStream(): Freeing Kinesis Video stream.
[ERROR][2018-11-13 12:13:10] Failed to create Kinesis Video Stream - timed out.
terminate called after throwing an instance of 'std::runtime_error'
what(): Failed to create Kinesis Video Stream - timed out.
Aborted
```

やっぱ怒られたか。。
なんか認証の問題っぽいかな。

ほー。credentials読んでくれないとかか??
https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-cpp/issues/22

こうしてやる

export AWS_ACCESS_KEY_ID={AccessKeyId}
export AWS_SECRET_ACCESS_KEY={SecretAccessKey}

なんかまたずらずらと文字が出てきてなんか動いたっぽかったけど、awsのコンソールでみると・・

2018-11-13 (3).png

って出ちゃってダメ。うーん。ハマったか。メモリの設定を128にしてみたりする。そしてしばしググる。

ん~。
gstreamerとかいうやつ入れなだめ?USBのカメラだと。
いや、sample_appがやってることをコマンドでやってる感じなのか試してみよう。

例 7: Raspberry Pi のカメラからビデオをストリーミングしてリージョンを指定する

sudo apt-get install gstreamer1.0-*
gst-launch-1.0 v4l2src do-timestamp=TRUE device=/dev/video0 ! videoconvert ! video/x-raw,format=I420,width=640,height=480,framerate=30/1 ! omxh264enc control-rate=1 target-bitrate=5120000 periodicity-idr=45 inline-header=FALSE ! h264parse ! video/x-h264,stream-format=avc,alignment=au,width=640,height=480,framerate=30/1,profile=baseline ! kvssink stream-name="RaspiStreamturtle" frame-timestamp=dts-only access-key="****" secret-key="****" aws-region="ap-northeast-1"

あかん。なんかエラーでる。

ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Internal data stream error.
Additional debug info:
gstbasesrc.c(2939): gst_base_src_loop (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
streaming stopped, reason not-negotiated (-4)
EOS on shutdown enabled -- waiting for EOS after Error

よくわからんからカメラをチェック

$ v4l2-ctl --list-formats-ext --device=/dev/video0
ioctl: VIDIOC_ENUM_FMT
        Index       : 0
        Type        : Video Capture
        Pixel Format: 'YUYV'
        Name        : YUV 4:2:2 (YUYV)
                Size: Discrete 640x480
                        Interval: Discrete 0.033s (30.000 fps)
                        Interval: Discrete 0.067s (15.000 fps)
                Size: Discrete 352x288
                        Interval: Discrete 0.033s (30.000 fps)
                        Interval: Discrete 0.067s (15.000 fps)
                Size: Discrete 320x240
                        Interval: Discrete 0.033s (30.000 fps)
                        Interval: Discrete 0.067s (15.000 fps)
                Size: Discrete 176x144
                        Interval: Discrete 0.033s (30.000 fps)
                        Interval: Discrete 0.067s (15.000 fps)
                Size: Discrete 160x120
                        Interval: Discrete 0.033s (30.000 fps)
                        Interval: Discrete 0.067s (15.000 fps)

Pixel Formatってのには'YUYV'ってのしか表示されてない。

参考:
http://tnoho.com/web/webrtc/689

ようわからん。今日はおしまい。

.....
.....

さて、仕切り直し。一旦初心に帰ろう。

Raspberry Pi で C++ プロデューサー SDK を使用する

どうもアカンかったのはkvs_sinkってプラグインの部分なんじゃないかと思ってる。kinesis video stream sinkって感じか。ローカルでエンコーダー通したストリームをそのままkinesisにsinkするやつなんだと思う。

Raspberry Pi で C++ プロデューサー SDK をセットアップする前に、次の前提条件が完備されていることを確認してください。
以下の設定の Raspberry Pi デバイス
Board バージョン: 3 Model B 以降。
接続されたカメラモジュール。
少なくとも 8 GB の容量がある SD カード。
Raspbian オペレーティングシステム (カーネルバージョン 4.9 以降) がインストールされている

おぉぅ。。
もうこの時点でアカンがな。俺のPiはver2やで。カーネルも4.1。アカンかも。。
でもま、一応進めよう。

じゃあ見なかったことにしてここまでスキップ。

Raspberry Pi カメラを設定する

/etc/modulesにbcm2835-v4l2を追加だって。ないから足しとけばいいのかな。やります。
そしてsudo reboot

......

無事立ち上がった。もう起きてこなかったらどうしようかと思ったわ。
では手順通りに。

sudo raspi-config

なんかInterfacing Options ってのがなかったので、Enable Cameraって項目をOnにしてみる。そしたらRebootする?するのかい?って聞かれたのでしとく。
本体からPinでつなぐカメラの設定だったりする?USB関係なし?

でテスト

raspistill -v -o test.jpg

あ、アカンかも。 Camera is not detected.って言われた。やっぱUSBのカメラ関係ないのか。
ちなみにこっちはできた。
https://www.raspberrypi.org/documentation/usage/webcams/

ライブラリ入れた気がするけど入れなおす。

$ sudo apt-get install byacc flex
$ sudo apt-get install openjdk-8-jdk
$ sudo apt-get install cmake
$ sudo curl https://www.amazontrust.com/repository/SFSRootCAG2.pem -o /etc/ssl/cert.pem

でもってイチかバチか再チャレンジ
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_DEFAULT_REGION=ap-northeast-1を設定していざ。

$ ./kinesis_video_gstreamer_sample_app RaspiStreamturtle

・・はい、あきませんね。でもHeapsizeがどうこうってエラーだし、パラメータで調整できんもんかな。-wやら-hやら-fをいろいろ試す。

・・そして

2018-11-14 (3).png

映ったわーーー!!

めっちゃ画質悪いけど。結局-fオプションで を1にしたらいけた。コマ切れもいいとこやけど、実際要件的には足りるな。ひとまず良しとしよう。

そしてホントは中編で、cogniteとcloudfrontとS3のさわりだけでもやっとこうかと思ってたんだけど次にします。次は後の前編となりそうです。つまり全4回。

なんとなくだけどcogniteとサーバーレスな組み合わせでvideoJsかなんか使いつつ再生できたらいいなって思ってる。

あ、無線LANのUSBのやつamazonから届いたし、これでも設定しよう、今日は。

追記:
ん~、無線LANにしてみたけど安定しないかもしれんな。一回落ちた。
ちなみにだけど、最初アカンかったのはリージョンの指定してなかったからかなと思ってる。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2