Player Downloader [patched] — Kvs
// Build the GetMedia request (you can pass StartSelector for specific timestamps) const getMediaCmd = new GetMediaCommand( StreamARN: STREAM_ARN, StartSelector: StartSelectorType: "NOW" , // start at the latest fragment // Optional: FragmentNumber or Timestamp for exact start point );
// 1️⃣ Configure the SDK (region, credentials) const REGION = "us-east-1"; const STREAM_ARN = "arn:aws:kinesisvideo:us-east-1:123456789012:stream/my-stream/1580000000000"; kvs player downloader
"github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/config" kv "github.com/aws/aws-sdk-go-v2/service/kinesisvideo" kvmedia "github.com/aws/aws-sdk-go-v2/service/kinesisvideomedia" ) // Build the GetMedia request (you can pass
async with aiohttp.ClientSession() as session: async with session.get(url, headers=headers) as resp: resp.raise_for_status() with open(OUTPUT, "wb") as f: async for chunk in resp.content.iter_chunked(1024 * 256): f.write(chunk) # optional: print progress print(f"\rf.tell() // 1024 KiB received", end="") print("\n✅ Done →", OUTPUT) Open persistent HTTP/2 connection | | 4
// 4️⃣ Write to file (streamed) f, err := os.Create(output) if err != nil panic(err) defer f.Close()
func main() ctx := context.Background()
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";

