Streaming video from Android camera to server
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Streaming video from an Android device to a server is not just a camera problem. It is a pipeline problem: capture frames, encode them efficiently, choose a transport protocol, and make sure the server can ingest the stream without falling behind.
Pick The Right Transport First
Before writing camera code, decide what the server needs.
- Use
WebRTCfor low-latency two-way communication. - Use
RTMPorSRTfor broadcast-style publishing to a media server. - Use a simple
WebSocketor HTTP upload only for prototypes, diagnostics, or low-frame-rate computer-vision pipelines.
A common mistake is trying to send raw camera frames directly over HTTP as if that were equivalent to video streaming. It works for a prototype, but it wastes bandwidth and CPU because each frame is large and independently encoded.
In production, most systems capture camera frames, encode them with MediaCodec as H.264, and then send the encoded stream using a protocol the server already understands.
A Simple Prototype With CameraX And WebSocket
The following Android example is intentionally simple. It captures frames with CameraX, compresses them as JPEG, and sends them to a WebSocket server. That is not the most efficient production architecture, but it is easy to understand and runnable.
You would attach that analyzer to an ImageAnalysis use case in CameraX and point it at a ws:// endpoint on your server.
A Matching Python Server
A minimal Python receiver can accept the binary messages and write them to disk. This proves the transport works end to end.
This is enough for a prototype, a remote snapshot feed, or a CV ingestion service that analyzes individual frames.
What A Production Pipeline Usually Looks Like
For real video streaming, replace JPEG-per-frame transmission with encoded video.
The common Android path is:
- capture with
CameraXorCamera2 - encode with
MediaCodec - push the encoded stream to an ingestion server
If the destination is a media server such as NGINX with RTMP support, Ant Media, or a WebRTC gateway, the server usually expects timestamped encoded packets instead of standalone images.
That matters because bandwidth drops sharply once frames are encoded as continuous video rather than independent JPEGs. Latency and battery use also improve.
Keep Backpressure Under Control
The camera can produce frames faster than the network can send them. If the upload path blocks, the app becomes unstable or memory usage spikes.
Use backpressure intentionally. With CameraX ImageAnalysis, configure a strategy that drops old frames instead of queueing indefinitely. For example, a live analytics or streaming path usually cares about the newest frame, not every historical frame.
If you move to MediaCodec, the same principle applies: keep the encoder and network sender decoupled so a slow server does not stall camera capture.
Security And Reliability
Do not ship an unauthenticated raw socket endpoint that accepts arbitrary uploads from the internet. At minimum, protect the stream with:
- TLS
- per-device authentication
- server-side rate limits
- short-lived stream credentials
Also plan for reconnect logic. Mobile networks drop, rotate IPs, and change bandwidth frequently. A robust client should tolerate reconnects and resume streaming instead of assuming a perfect connection.
Common Pitfalls
- Sending raw or JPEG frames in production when the server really expects encoded video.
- Ignoring backpressure and letting frame queues grow without limit.
- Using the deprecated camera API when
CameraXorCamera2would be easier to maintain. - Forgetting that network jitter, not camera capture, often dominates stream quality.
- Treating transport choice as an afterthought instead of the main architectural decision.
Summary
- Android video streaming is a capture, encode, and transport pipeline.
- '
WebSocketframe upload is fine for a prototype, butWebRTC,RTMP, orSRTare better production transports.' - '
CameraXis a practical way to capture frames on modern Android.' - Production systems usually encode with
MediaCodecinstead of sending standalone JPEG frames. - Backpressure, reconnection, and authentication matter as much as camera code.
Related reading
- stringByAppendingPathComponent is unavailable
- Support for Tensorflow 2.0 in Object Detection API
- Suppress InsecureRequestWarning Unverified HTTPS request is being made in Python2.6
- Swagger async controller generation
- String Resource new line /n not possible?
- String search in string array in objective c
- swagger .net core API ambiguous HTTP method for Action Error
- Swagger TypeError Failed to execute 'fetch' on 'Window' Request with GET/HEAD method cannot have body

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.