이번에는 raspberry pi 에서도 gstream을 이용한 영상 전송 플랫폼을 사용해보았는데 뭔가 공식 문서가 업데이트가 안된 것들이 있어서 조금 수정하면서 해결한 상황에 대해서 기록 해보고자 한다.
우선 amazon에서 kinesis video stream에 대한 설명은 여기서 쉽게 찾아 볼 수 있다.
aws.amazon.com/ko/kinesis/video-streams/
Amazon Kinesis Video Streams - 분석 및 저장을 위한 안전한 비디오 수집 - Amazon Web Services
Amazon Kinesis Video Streams는 디바이스가 재생, 저장, 분석, 기계 학습 및 기타 처리를 위해 미디어를 AWS로 쉽고 안전하게 스트리밍할 수 있도록 지원하는 SDK를 제공합니다. Kinesis Video Streams는 엣지 디
aws.amazon.com
video를 단순 스트리밍을 해주는 목적도 있지만 비디오 분석을 통한 데이터셋을 모으기 위한 플랫폼으로도 적합한것으로 보인다. 하지만 여기서는 스트리밍만을 다룰수 있는 설치를 진행하고자 한다.
amazon kinesis video stream 다운로드
git clone --recursive https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-cpp.git
해당 git 을 받아준다.
git을 받으면 이러한 폴더가 생성된것을 볼 수 있다.
sudo mkdir -p amazon-kinesis-video-streams-producer-sdk-cpp/build
cd amazon-kinesis-video-streams-producer-sdk-cpp/build
다시 이전 폴더에서
해당 명령어를 통해서 build 폴더를 만들고 build 위치로 이동하면 된다.
해당 위치에서
cmake ..
해당 명령어를 실행해주면 된다.
약 5 - 10분정도 소요된후에
성공적으로 설치가 된다. 그뒤에는 라이브러리를 설치해주면 된다. 필요 라이브러리는 다음과 같다.
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
라이브러리를 설치가 완료 되었다면
상위 폴더로 올라와서
위와 같이 make 커맨드를 이용해주면 기본적으로 필요한 예제 코드나 빌드 파일들을 설치하게 된다.
위 과정 까지 약 1시간 정도 걸린다. gstream 이나 기본적으로 깔리는 패키지가 많다. 그러니 여유롭게 진행하는 것을 추천한다.
예제 실행하기에 앞서서 환경 변수를 설정해주면 오류의 영향을 줄일 수 있다.
export GST_PLUGIN_PATH=`pwd`/build
export LD_LIBRARY_PATH=`pwd`/open-source/local/lib
그러면 진짜로 환경 변수 및 설정은 끝났다.
설치가 잘 되었는지 확인 하는 방법은 간단하다.
gst-inspect-1.0 kvssink 해당 명령어를 실행하게 되면 아래와 같은 정보가 나오면 설치가 무사히 끝난것이다.(환경변수가 완료된 상태여야 해당 명령어를 사용 할 수 있다.
pi@raspberrypi:~/Desktop/amazon-kinesis-video-streams-producer-sdk-cpp $ export GST_PLUGIN_PATH=`pwd`/build
pi@raspberrypi:~/Desktop/amazon-kinesis-video-streams-producer-sdk-cpp $ export LD_LIBRARY_PATH=`pwd`/open-source/local/lib
pi@raspberrypi:~/Desktop/amazon-kinesis-video-streams-producer-sdk-cpp $ gst-inspect-1.0 kvssink
Factory Details:
Rank primary + 10 (266)
Long-name KVS Sink
Klass Sink/Video/Network
Description GStreamer AWS KVS plugin
Author AWS KVS <kinesis-video-support@amazon.com>
Plugin Details:
Name kvssink
Description GStreamer AWS KVS plugin
Filename /home/pi/Desktop/amazon-kinesis-video-streams-producer-sdk-cpp/build/libgstkvssink.so
Version 1.0
License Proprietary
Source module kvssinkpackage
Binary package GStreamer
Origin URL http://gstreamer.net/
GObject
+----GInitiallyUnowned
+----GstObject
+----GstElement
+----GstKvsSink
Pad Templates:
SINK template: 'video_%u'
Availability: On request
Capabilities:
video/x-h264
stream-format: avc
alignment: au
width: [ 16, 2147483647 ]
height: [ 16, 2147483647 ]
video/x-h265
alignment: au
width: [ 16, 2147483647 ]
height: [ 16, 2147483647 ]
SINK template: 'audio_%u'
Availability: On request
Capabilities:
audio/mpeg
mpegversion: { (int)2, (int)4 }
stream-format: raw
channels: [ 1, 2147483647 ]
rate: [ 1, 2147483647 ]
audio/x-alaw
channels: { (int)1, (int)2 }
rate: [ 8000, 192000 ]
audio/x-mulaw
channels: { (int)1, (int)2 }
rate: [ 8000, 192000 ]
Element has no clocking capabilities.
Element has no URI handling capabilities.
Pads:
none
Element Properties:
name : The name of the object
flags: readable, writable
String. Default: "kvssink0"
parent : The parent of the object
flags: readable, writable
Object of type "GstObject"
stream-name : Name of the destination stream
flags: readable, writable
String. Default: "DEFAULT_STREAM"
retention-period : Length of time stream is preserved. Unit: hours
flags: readable, writable
Unsigned Integer. Range: 0 - 4294967295 Default: 2
streaming-type : Streaming type
flags: readable, writable
Enum "GstKvsSinkStreamingType" Default: 0, "realtime"
(0): realtime - streaming type realtime
(1): near-realtime - streaming type near realtime
(2): offline - streaming type offline
content-type : content type
flags: readable, writable
String. Default: null
max-latency : Max Latency. Unit: seconds
flags: readable, writable
Unsigned Integer. Range: 0 - 4294967295 Default: 60
fragment-duration : Fragment Duration. Unit: miliseconds
flags: readable, writable
Unsigned Integer. Range: 0 - 4294967295 Default: 2000
timecode-scale : Timecode Scale. Unit: milliseconds
flags: readable, writable
Unsigned Integer. Range: 0 - 4294967295 Default: 1
key-frame-fragmentation: If true, generate new fragment on each keyframe, otherwise generate new fragment on first keyframe after fragment-duration has passed.
flags: readable, writable
Boolean. Default: true
frame-timecodes : Do frame timecodes
flags: readable, writable
Boolean. Default: true
absolute-fragment-times: Use absolute fragment time
flags: readable, writable
Boolean. Default: true
fragment-acks : Do fragment acks
flags: readable, writable
Boolean. Default: true
restart-on-error : Do restart on error
flags: readable, writable
Boolean. Default: true
recalculate-metrics : Do recalculate metrics
flags: readable, writable
Boolean. Default: true
framerate : Framerate
flags: readable, writable
Unsigned Integer. Range: 0 - 4294967295 Default: 25
avg-bandwidth-bps : Average bandwidth bps
flags: readable, writable
Unsigned Integer. Range: 0 - 4294967295 Default: 4194304
buffer-duration : Buffer duration. Unit: seconds
flags: readable, writable
Unsigned Integer. Range: 0 - 4294967295 Default: 120
replay-duration : Replay duration. Unit: seconds
flags: readable, writable
Unsigned Integer. Range: 0 - 4294967295 Default: 40
connection-staleness: Connection staleness. Unit: seconds
flags: readable, writable
Unsigned Integer. Range: 0 - 4294967295 Default: 60
codec-id : Codec ID
flags: readable, writable
String. Default: "V_MPEG4/ISO/AVC"
track-name : Track name
flags: readable, writable
String. Default: "kinesis_video"
access-key : AWS Access Key
flags: readable, writable
String. Default: "access_key"
secret-key : AWS Secret Key
flags: readable, writable
String. Default: "secret_key"
aws-region : AWS Region
flags: readable, writable
String. Default: "us-west-2"
rotation-period : Rotation Period. Unit: seconds
flags: readable, writable
Unsigned Integer. Range: 0 - 4294967295 Default: 3600
log-config : Log Configuration Path
flags: readable, writable
String. Default: "./kvs_log_configuration"
storage-size : Storage Size. Unit: MB
flags: readable, writable
Unsigned Integer. Range: 0 - 4294967295 Default: 128
credential-path : Credential File Path
flags: readable, writable
String. Default: ".kvs/credential"
iot-certificate : Use aws iot certificate to obtain credentials
flags: readable, writable
Boxed pointer of type "GstStructure"
stream-tags : key-value pair that you can define and assign to each stream
flags: readable, writable
Boxed pointer of type "GstStructure"
file-start-time : Epoch time that the file starts in kinesis video stream. By default, current time is used. Unit: Seconds
flags: readable, writable
Unsigned Integer64. Range: 0 - 4294967295 Default: 1602206036
기본적으로 명령어로 실행이 가능하다. aws에서 비디오 스트리밍을 설정을 해두었다면
gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert ! video/x-raw,format=I420,width=640,height=480 ! omxh264enc control-rate=2 target-bitrate=512000 periodicity-idr=45 inline-header=FALSE ! h264parse ! video/x-h264,stream-format=avc,alignment=au,profile=baseline ! kvssink stream-name="스트림 이름" access-key="액세스키" secret-key="시크릿키" aws-region="설정된 지역"
이렇게 명령어를 입력하게 되면
위와 같이 실행 정보가 나오는 화면으로 가득 차게 된다.
아마존 서비스에 들어가게 되면 스트림이 생성되는것을 볼수 있다. 이를 통해서 명령어를 통해서 스트림 내용을 생성하는 것도 가능하다라는 것을 알 수 있다.
이렇게 재생되는 화면이 보인다면 정상적으로 된것이다.
이외에도 build에 들어가면 smaple에 있는 cpp 코드를 이용해서 만든 실행 파일들이 있다. 이러한 스크립트는 수정하고 make 과정을 통해서 언제든지 build에 사용할 수 있다. 그러니 코드를 사용해야 하는 유저들은 해당 코드를 빌드하고도 사용이 가능하다.
이상으로 일반적으로 독스 보다가 고통 받다가 해결방법 찾아서 이렇게 나마 끄적여본것을 마치기로 한다.
'임베디드 > raspberry pi' 카테고리의 다른 글
raspberry pi aws iot에 연결해보기 (part.2 python3 raspberry pi 구동 확인) (0) | 2020.10.06 |
---|---|
raspberry pi aws iot에 연결해보기 (part.1 사물 생성 및 인증서) (0) | 2020.10.05 |