aws/amazon-kinesis-video-streams-parser-library

Frames creation from Kinesis Video Stream stop every 45 minutes

Closed this issue · 6 comments

Hi,

I'm using the Kinesis Video Consumer SDK (for Java/Kotlin) with the following process:

  • My application take frames from a Kinesis Video Stream
  • For each frames available on the stream, it will save it as a file on the local machine (as jpeg file)
  • When i stop sending stream, the frame creation also stop

But there is something strange. I try to send a stream with 5 FPS or with 30 FPS, every time, after 45 minutes (not the same number of images generated), the stream still available (I can't view the video on HLS), my frame creation app stop, without any errors or something else (just stop to create frames, like there is no more frames available on the stream)

Each time it's a timeout around 45 minutes. And there is not timeout in my code.

So I check some things:

Called every 45 minutes to refresh the streaming token for most PutMedia/GetMedia use cases. Caching data endpoints is safe if the application reloads them on failure.

Maybe my issue is based on this note. How can we avoid this ? There is a parameter or something else that I can try if my problem is caused by GetDataEndpoint ?

To be clear, this is a part of my code.

`
        val serviceEndpoint = awsService.getServiceEndpoint(AWS_KINESIS_VIDEO_SERVICE_NAME, "https", kinesisProperties.regionName)

        val kinesisEndPointConfiguration = EndpointConfiguration(
                serviceEndpoint.toString(),
                kinesisProperties.regionName
        )

        val amazonKinesisVideo = AmazonKinesisVideoClientBuilder.standard()
                .withEndpointConfiguration(kinesisEndPointConfiguration)
                .withCredentials(awsService.generateCredentials())
                .build()

        process(amazonKinesisVideo, streamName)
    }
`

process() function:

`
val getMediaWorker = GetMediaWorker.create(
                Regions.EU_CENTRAL_1,
                awsService.generateCredentials(),
                streamName,
                StartSelector().withStartSelectorType(StartSelectorType.NOW),
                amazonKinesisVideo,
                getMediaProcessingArguments
        )

        executorService.execute(getMediaWorker)
        executorService.shutdown()
        executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS)
`

And for the frame creation, I use a code on your repo which is https://github.com/aws/amazon-kinesis-video-streams-parser-library/blob/master/src/main/java/com/amazonaws/kinesisvideo/parser/utilities/FrameRendererVisitor.java

Have you any idea on how I can fix this ? Maybe I need to update the endpoint every 45 minutes and run the frame creation again ? Or my problem isn't caused by this ?

Thanks for your help,

Kind regards,
Florian

@FlorianRuen sorry for the confusion. KVS sessions are limited to around 50 minutes after which the Inlet will close the connection. The Producer SDK handles this with proactive token rotation. What it does is it's limiting the session to exactly 45 minutes max. Around 30 seconds before the token expiration, it re-creates a parallel session which is made available and it switches over to streaming over to the new session as soon as the last bit of the previous session is sent, thus, achieving a seamless streaming even on high-latency networks.

NOTE: The producer SDK will add a small random jitter by default to the amount of time the session is viable to ensure a flatter peak curve distribution of API calls when an account has tens of thousands of devices and all starting up at the same time.

Getting back to your scenario. I would advise you to track the duration of the consumer session. Once the session expires, request a new endpoint and issue a new GetMedia with the timestamp of the last fragment you've ingested. Even if the fragment is slightly behind the "head" it will catch-up faster than the realtime if your network and processing speed allow it.

@MushMal So as you said, I just need to create a new GetMedia (endpoint keep the same) to generate new credentials (stop my executor, new get media that begin at the latest ingered timestamp, and begin new executor, every 43 minutes to be sure it will not stop), correct ?

I will try this on tomorrow morning, hope this will not create some lattence between the app that send the stream and the frame creation as file.

Unfortunately, we currently don't have a proper "Consumer" side SDK that will handle all these tasks, including seamless token rotation, checkpointing, credential integration, buffering like in case of the Producer SDK.

But yeah, that's what you will need to do. If the latency is of a big issue, you might also try to kick off the token refresh before the expiration and get the endpoint slightly before and do GetMedia right after your current connection terminates.

Generally though, most of the scenarios are running GetMedia on a more capable device which is also better connected so having a simple sequential code might be just fine.

Entirely forgot about your question on encryption. KVS has a default KMS key to encrypt the data at rest. You could overwrite the default key and specify your own as well when creating the stream. GetMedia will decrypt the data before sending over the transport protected layer.

I am going to resolve this for now. Please feel free to reopen if needed or cut a new issue

This topic is closed, you are right, I make something to create a pipeline every 40 minutes, because it close automatically around 45 minutes of KVS Session.

So every 40 minutes, I stop my loop and run it again to avoid this.