kvs player downloader

New!er | Kvs Player Download

The downloader works by , processing the returned fragmented MP4 (fMP4) or MKV container, and writing a file that can be consumed by any standard media player. 2. Architecture Overview +-------------------+ HTTPS (Signed) +-----------------------+ | Client / Device | <---------------------------> | AWS Kinesis Video | | (Downloader) | GET /GetMedia?StreamARN=... | Streams (KVS) | +-------------------+ +-------------------+ | | | 1. Retrieve temporary credentials (if using IAM) | | 2. Sign request (SigV4) | | 3. Open persistent HTTP/2 connection | | 4. Receive binary fragments (fMP4/MKV) | | 5. Parse container (moov/mdat, EBML, etc.) | | 6. Optionally transcode (FFmpeg) / store to disk | | 7. Emit progress/events (bytes, timestamps) | v v +-------------------+ +-------------------+ | Downloader Core | | Media Store | | (Node/Go/Python) | | (S3, EFS, local) | +-------------------+ +-------------------+ Core Components | Component | Responsibility | Typical Implementation | |-----------|----------------|------------------------| | Credential Provider | Retrieves AWS temporary credentials (IAM role, Cognito, Web Identity). | AWS SDK credential chain; optional custom STS AssumeRole. | | Request Signer | Generates SigV4‑signed HTTP/2 request. | aws-sdk SignatureV4 class; aws4 library (Node). | | Transport Layer | Maintains an HTTP/2 stream, handles back‑pressure, reconnection logic. | http2 (Node), net/http2 (Go), aiohttp (Python). | | Fragment Parser | Reads the binary payload, extracts timestamps, key‑frames, and metadata. | mp4box.js , fluent-ffmpeg (for container handling), custom EBML parser for MKV. | | Writer / Transcoder | Writes to file, optionally pipes to FFmpeg for re‑packing. | Node fs.createWriteStream , Go os.File , Python io . | | Progress / Metrics | Emits events for UI or logging (bytes, fragment count, latency). | EventEmitter (Node), channels (Go), callbacks (Python). | 3. Getting Started – Sample Code Below are three minimal examples (Node.js, Python, Go) that illustrate a basic downloader that writes a continuous MP4 file to disk. 3.1 Node.js (TypeScript) import KinesisVideoClient, GetDataEndpointCommand from "@aws-sdk/client-kinesis-video"; import KinesisVideoMediaClient, GetMediaCommand from "@aws-sdk/client-kinesis-video-media"; import createWriteStream from "fs"; import pipeline from "stream/promises";

const ( region = "us-east-1" streamARN = "arn:aws:kinesisvideo:us-east-1:123456789012:stream/my-stream/1580000000000" output = "downloaded_stream.mp4" ) kvs player downloader

// 1️⃣ Get data endpoint for GET_MEDIA kvClient := kv.NewFromConfig(cfg) epOut, err := kvClient.GetDataEndpoint(ctx, &kv.GetDataEndpointInput APIName: kv.APINameGetMedia, StreamARN: aws.String(streamARN), ) if err != nil panic(err) mediaCfg := cfg.Copy() mediaCfg.EndpointResolver = aws.EndpointResolverFromURL(*epOut.DataEndpoint) The downloader works by , processing the returned

STREAM_ARN = "arn:aws:kinesisvideo:us-east-1:123456789012:stream/my-stream/1580000000000" REGION = "us-east-1" OUTPUT = "downloaded_stream.mp4" Open persistent HTTP/2 connection | | 4

def sign_request(url, method="GET"): # boto3's botocore can sign arbitrary requests from botocore.auth import SigV4Auth from botocore.awsrequest import AWSRequest from botocore.credentials import ReadOnlyCredentials