A proof-of-concept project demonstrating real-time video transcoding and streaming using AWS Lambda Response Streaming with FFmpeg.
This project showcases how to use AWS Lambda's response streaming feature to transcode and resize videos on-the-fly. Videos are fetched from S3, processed with FFmpeg, and streamed directly to the client without storing intermediate files.
- Real-time video transcoding using FFmpeg
- Dynamic video resizing via query parameters
- Lambda Response Streaming
- AWS Account
- AWS CLI configured
- AWS SAM CLI installed
- Node.js 20.x
- An S3 bucket with a video file (preferably MP4 format)
Create an S3 bucket and upload a video file (MP4 recommended):
aws s3 mb s3://your-bucket-name
aws s3 cp your-video.mp4 s3://your-bucket-name/Edit the samconfig.toml file and update the following parameters:
parameter_overrides = [
"Project=PoC",
"Name=Lambda Response Streaming",
"Owner=Your Name",
"S3BucketName=your-bucket-name", # Change this!
"S3VideoKey=your-video.mp4" # Change this!
]Parameters:
S3BucketName: The name of your S3 bucket containing the videoS3VideoKey: The S3 key (path/filename) of your video file
# Build and deploy with SAM
sam build
sam deployAfter deployment, SAM will output the Lambda Function URL.
The Lambda Function URL accepts two query parameters to dynamically resize the video:
width- Target video width (default: 640)height- Target video height (default: 480)
Default resolution (640x480):
https://your-function-url.lambda-url.us-west-2.on.aws/
Custom resolution (1280x720):
https://your-function-url.lambda-url.us-west-2.on.aws/?width=1280&height=720
You can open these URLs directly in a browser
┌─────────┐ ┌──────────┐ ┌────────┐ ┌────────┐
│ Client │─────▶│ Lambda │─────▶│ S3 │─────▶│ FFmpeg │
└─────────┘ │ Function │ │ Bucket │ └────────┘
▲ │ URL │ └────────┘ │
│ └──────────┘ │
│ │
└──────────────────────────────────────────────────┘
Streaming Response
- Client requests video via Lambda Function URL
- Lambda fetches video from S3 using environment variables
- FFmpeg transcodes and resizes the video stream
- Lambda streams the result back to the client in real-time
The Lambda function uses the following environment variables (automatically configured via template.yaml):
S3_BUCKET_NAME: S3 bucket containing the video fileS3_VIDEO_KEY: S3 key (path) to the video file
These are set through the CloudFormation parameters during deployment.
- Runtime: Node.js 20.x
- Memory: 256 MB
- Timeout: 30 seconds
- Architecture: x86_64
The transcoding uses the following FFmpeg settings (configurable in src/app.ts):
- Video codec: H.264 (libx264)
- Preset: ultrafast (optimized for speed)
- CRF: 23 (quality level, lower = better quality)
- Audio codec: AAC
- Audio bitrate: 128k
- Video size: Limited by Lambda's memory and timeout settings
- Processing time: Max 15 minutes (Lambda timeout) - Default: 30 seconds
