aws-samples / amazon-kinesis-video-streams-demos

A place to add different use cases for different Kinesis Video Stream Assets
Apache License 2.0
74 stars 42 forks source link

Add gstreamer plugin usage demo for kinesis webrtc (gst-launch pipeline) #281

Closed mariobaldini closed 8 months ago

mariobaldini commented 1 year ago

Although we have usage samples on how to integrate the gstreams libs into a program, another common pattern is run directly as a gst-launch-1.0 pipeline.

Sending a mkv file directly to a video stream channel: (works)

gst-launch-1.0 -v \
filesrc location=/path/Jellyfish_1080_10s_2MB.mkv \
! matroskademux name=demux  demux.video_0\
! decodebin \
! videoconvert \
! x264enc bframes=0 key-int-max=45 bitrate=500 ! video/x-h264,stream-format=avc,alignment=au,profile=baseline \
! kvssink stream-name="stream_name" storage-size=512 aws-region="us-west-2" \
iot-certificate="iot-certificate,endpoint=xxxx.credentials.iot.us-west-2.amazonaws.com,cert-path=/path/aws-iot-cert.pem.crt,key-path=/path/aws-iot-cert.pem.key,ca-path=/home/path/aws-iot-cert-rootca.pem,role-aliases=IoTRoleAlias,iot-thing-name=thing_name"

What is the equivalent pipeline allowing a mkv video to be sent to a signaling channel? (based on kvsplugin -- for webrtc)

I've read many samples in the official docs or across the web but am having a hard time making it to work with gst-launch-1.0 directly. (and found many others also struggling). Having a couple more samples based on gst-launch would be really nice.

I can test and prepare a PR with more cases (ex: webcam->webrtc, other sources, etc), but need help figuring out one initial working case of how to get kvsplugin to send a file to webrtc.

mariobaldini commented 1 year ago

Trying with:

gst-launch-1.0 -v \
autovideosrc ! \
queue ! \
videoconvert ! \
x264enc bframes=0 key-int-max=45 bitrate=2000 ! video/x-h264,stream-format=avc,alignment=au,profile=baseline ! \
kvsplugin channel-name="xxx1" storage-size=512 aws-region="us-west-2" log-level=8 \
iot-certificate="iot-certificate,endpoint=xxxx.credentials.iot.us-west-2.amazonaws.com,cert-path=/xxx/aws-iot-cert.pem.crt,key-path=/xxx/aws-iot-cert.pem.key,ca-path=/xxx/aws-iot-cert-rootca.pem,role-aliases=KvsHubIoTRoleAlias,iot-thing-name=xxx"

Gives:

Setting pipeline to PAUSED ...
2023-03-27 03:29:22 ERROR   blockingCurlCall(): Curl call response failed with http status 403
2023-03-27 03:29:22 ERROR   initKinesisVideoStructs(): operation returned status code: 0x16000001
2023-03-27 03:29:22 ERROR   gst_kvs_plugin_change_state(): Failed to initialize KVS structures with 0x16000001
ERROR: from element /GstPipeline:pipeline0/GstKvsPlugin:kvsplugin0: Could not initialize supporting library.
Additional debug info:
/host/temp/amazon-kinesis-video-streams-demos/gst/gst-kvs-plugin/src/GstPlugin.c(1296): gst_kvs_plugin_change_state (): /GstPipeline:pipeline0/GstKvsPlugin:kvsplugin0:
Failed to initialize with 0x16000001
ERROR: pipeline doesn't want to preroll.
Failed to set pipeline to PAUSED.
Setting pipeline to NULL ...
Freeing pipeline ...

I tested the certificates and auth endpoint and they work fine (token is generated successfully):

curl -H "x-amzn-iot-thingname:xxx" \
--cert /xxx/aws-iot-cert.pem.crt \
--key /xxx/aws-iot-cert.pem.key \
https://xxx.credentials.iot.us-west-2.amazonaws.com/role-aliases/KvsCameraIoTRoleAlias/credentials \
--cacert /xxx/aws-iot-cert-rootca.pem

{"credentials":{"accessKeyId":"ASIAxxxx","secretAccessKey":"feKtIxxxxx","sessionToken":"IQoJb3Jxxxxx","expiration":"2023-03-27T04:32:42Z"}}

And I also copied the https://www.amazontrust.com/repository/SFSRootCAG2.pem cert to /etc/ssl/cert.pem as indicated in https://docs.aws.amazon.com/kinesisvideostreams/latest/dg/troubleshooting.html#troubleshooting-producer-curl

What is wrong in that pipeline?

mariobaldini commented 1 year ago

Could someone please confirm if the kvsplugin (kvs webrtc/signaling gstreamer plugin) provided by AWS is functional in the latest releases?

sirknightj commented 1 year ago

kvsplugin appears to both send video to a signaling channel, and a video stream (multiple places). If you're looking for webrtc only, you can check this out.

mariobaldini commented 1 year ago

My problem with kvsplugin was that I couldn't get it working as is, from the samples. Specially when trying certificate based auth. I'll retry latest version and confirm if this issue is still valid or got fixed.

Thanks for sharing gst-plugins-rs, that's gold! :star_struck: Definitely going to try to contribute with them.