0

Now, I am working on client-side of Amazon Kinesis Video Streams, using video.js and http-streaming to display video.

However, on stream server there are some metadata (text only) for each fragment (as this link: https://aws.amazon.com/about-aws/whats-new/2018/10/kinesis-video-streams-fragment-level-metadata-support/).

I don't know how to get this data by using AWSJavaScriptSDK (Ex: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/KinesisVideoMedia.html).

I've test with getMedia function, but it not working as expectation (just get media info one time, not each fragment)

var kinesisvideomedia = new AWS.KinesisVideoMedia({
                    //apiVersion: '2017-09-30',
                    region: options.region,
                    accessKeyId: options.accessKeyId,
                    secretAccessKey: options.secretAccessKey,
                    endpoint: response.DataEndpoint
                });
                //  3.  Create the parameters for getMedia()
                var mopts = {
                    StartSelector: {
                        StartSelectorType: 'EARLIEST'
                    },
                    StreamName: streamName
                };
                kinesisvideomedia.getMedia(mopts, function (error, vmresp) {
                    if (error) {
                        console.log(error);
                    }
                    //console.log(vmresp);
                });

Many thanks for any support!

huynhtuanh
  • 327
  • 1
  • 5
  • 17

2 Answers2

0

Your parameters only tells getMedia to grab the earliest fragment from the stream. If you want to get all the following fragments you have to use the ContinuationToken that was returned in the response from the previous call to getMedia when doing additional calls to getMedia.

Regarding the metadata on the fragment level, you need to parse the response payload, for example like in this example, using the video streams parser library

Jon Lindeheim
  • 582
  • 4
  • 10
0

getMedia is not well documented in the js aws-sdk, the main trick is to use request.createReadStream() in order to stream the media chunks.

You could do it like

var kinesisvideomedia = new AWS.KinesisVideoMedia();
var kinesisvideo = new AWS.KinesisVideo();
const params = {
  APIName: "GET_MEDIA",
  StreamName: streamName
}
kinesisvideo.getDataEndpoint(params, function(err, data) {
  if (err) {
    throw(err)
  }
  console.log("Changing endpoint to", data.DataEndpoint);
  kinesisvideomedia.endpoint = data.DataEndpoint;
  var mopts = {
    StartSelector: {
      StartSelectorType: 'EARLIEST'
    },
    StreamName: streamName
  };
  const request = kinesisvideomedia.getMedia(mopts);
  const stream = request.createReadStream();
  stream.on('data', function(data) { console.log("data", data)})
});
piercus
  • 1,136
  • 9
  • 17