Key Takeaways
- Save thousands on hardware — MediaMTX + FFmpeg simulates unlimited RTSP cameras using video files or synthetic test patterns, no physical cameras needed
- Production-grade, zero dependencies — MediaMTX is a single binary supporting RTSP, RTMP, WebRTC, SRT, HLS with <10MB idle RAM usage
- Test 8+ camera feeds simultaneously — Push multiple streams from one machine for multi-camera AI pipeline testing (YOLO, face recognition, object tracking)
- Complete test environment in 60 seconds — Docker + FFmpeg + one shell script = 4 virtual cameras ready for your AI code
- Aomway offers professional RTSP/IP camera solutions for field deployment when your prototype is ready to move from simulation to production
If you build video AI systems, you have faced this problem: you need cameras to test, but buying multiple IP cameras costs thousands. A single Hikvision or Dahua unit can run $100-300, and a full multi-camera test setup adds up fast. Debugging is worse — network cameras drop streams during critical tests, and CI/CD automation has no camera hardware at all.
Here is a fix that costs nothing: MediaMTX + FFmpeg — a local RTSP server that looks exactly like a real camera to your Python code. Your YOLO detection, face recognition, and object tracking pipelines connect to rtsp://localhost:8554/cam1 the same way they would connect to a $200 IP camera. The code cannot tell the difference.
This guide walks through the complete setup and shows how Aomway applies similar streaming reliability principles in production drone communication and video transmission systems.
1. Why You Need This
When working on a multi-channel video analysis project running YOLO detection across 4 camera feeds, the first obstacle is hardware. With only one USB camera available, buying three more IP cameras means spending $500-1000 before any code runs.
A colleague shared the MediaMTX + FFmpeg solution: run a lightweight RTSP server locally, push video files or synthetic test patterns through FFmpeg, and every feed looks like a real camera to your application.
| Scenario | Pain Point | MediaMTX Solution |
|---|---|---|
| Multi-channel testing | Only 1 physical camera | One video file = one virtual camera |
| Performance benchmarking | Unknown system capacity | Push N streams simultaneously, scale freely |
| CI/CD automation | No camera hardware in test environment | Script starts server + pushes streams, fully automated |
| Unstable video sources | Network cameras frequently disconnect | Local video files, always online |
| Prototype development | Hardware not yet purchased | Validate logic first, add hardware later |
Aomway understands this challenge deeply — our drone video transmission systems handle real-time multi-channel feeds in field conditions, where stream reliability is not optional.
2. What is MediaMTX
MediaMTX (formerly RTSP Simple Server) is a lightweight streaming media server supporting RTSP, RTMP, WebRTC, SRT, HLS, and virtually all mainstream protocols.
Key features:
- Zero dependencies — Single executable file, no Go, Python, or runtime environment required
- Cross-platform — Linux, Windows, macOS, ARM (Raspberry Pi compatible)
- Auto protocol conversion — RTSP push → automatically converted to WebRTC/HLS output
- Ultra-low resource consumption — Idle memory <10MB, CPU near 0%
- Hot-reload configuration — Edit YAML without restart
GitHub: github.com/bluenviron/mediamtx, 15k+ stars, active community. Aomway recommends this tool for development-stage RTSP testing before deploying to production drone communication hardware.
3. Installation: Two Options
3.1 Docker (Recommended, Fastest)
docker run --rm -it --network=host bluenviron/mediamtx:latest
After startup you will see:
2026/07/01 00:00:00 INF MediaMTX v1.12.0
2026/07/01 00:00:00 INF [RTSP] listener opened on :8554 (TCP), :8000 (UDP/RTP), :8001 (UDP/RTCP)
2026/07/01 00:00:00 INF [RTMP] listener opened on :1935
2026/07/01 00:00:00 INF [HLS] listener opened on :8888
2026/07/01 00:00:00 INF [WebRTC] listener opened on :8889
Open http://localhost:8888 in your browser for the web management dashboard — see active streams, publishers, and consumers.
Windows/Mac port mapping:
docker run --rm -it \
-p 8554:8554 -p 1935:1935 -p 8888:8888 -p 8889:8889 -p 8890:8890/udp \
-e MTX_RTSPTRANSPORTS=tcp \
bluenviron/mediamtx:latest
3.2 Direct Installation (Linux Servers)
# Download latest release
wget https://github.com/bluenviron/mediamtx/releases/download/v1.12.0/mediamtx_v1.12.0_linux_amd64.tar.gz
# Extract
tar -xzf mediamtx_v1.12.0_linux_amd64.tar.gz
# Run (auto-generates mediamtx.yml config on first run)
./mediamtx
No apt install needed. Single binary, ready in seconds.
4. FFmpeg Stream Push: Three Common Patterns
4.1 From Video File (Most Common)
ffmpeg -re -stream_loop -1 -i test_video.mp4 \
-c copy -f rtsp rtsp://localhost:8554/camera1
| Parameter | Purpose |
|---|---|
-re |
Read at native frame rate (prevents instant completion) |
-stream_loop -1 |
Infinite loop |
-i test_video.mp4 |
Input file |
-c copy |
Direct stream copy, no re-encoding (saves CPU) |
-f rtsp |
Output format RTSP |
rtsp://localhost:8554/camera1 |
Target path; camera1 is the stream name |
Verify with VLC or FFplay:
ffplay rtsp://localhost:8554/camera1
Your Python code then reads the stream with standard OpenCV:
import cv2
cap = cv2.VideoCapture("rtsp://localhost:8554/camera1")
4.2 From USB Camera (Real Feed)
# Linux
ffmpeg -f v4l2 -i /dev/video0 \
-c:v libx264 -preset veryfast -tune zerolatency \
-maxrate 3000k -bufsize 6000k \
-f rtsp rtsp://localhost:8554/webcam
The -preset veryfast -tune zerolatency parameters are critical — without them, latency can reach 2-3 seconds.
4.3 Synthetic Test Pattern (No File Needed)
# Timestamped color bars test pattern
ffmpeg -re -f lavfi \
-i "testsrc=duration=3600:size=1920x1080:rate=30,drawtext=text='CAM01 %{localtime} Frame %{n}':x=10:y=10:fontsize=32:fontcolor=white:box=1:[email protected]" \
-c:v libx264 -preset veryfast -tune zerolatency \
-f rtsp rtsp://localhost:8554/cam01
This pattern displays real-time timestamps and frame numbers — ideal for verifying frame-by-frame processing in object detection pipelines. Aomway uses similar validation approaches when testing drone video transmission latency.
5. Multi-Channel Simulation: One File Becomes 8 Cameras
To simulate multiple cameras for AI pipeline testing:
# Push 4 different video files as 4 cameras
ffmpeg -re -stream_loop -1 -i road_traffic.mp4 -c copy -f rtsp rtsp://localhost:8554/cam1 &
ffmpeg -re -stream_loop -1 -i street_scene.mp4 -c copy -f rtsp rtsp://localhost:8554/cam2 &
ffmpeg -re -stream_loop -1 -i parking_lot.mp4 -c copy -f rtsp rtsp://localhost:8554/cam3 &
ffmpeg -re -stream_loop -1 -i mall_entrance.mp4 -c copy -f rtsp rtsp://localhost:8554/cam4 &
# Or 8 feeds from one file with staggered offsets
for i in $(seq 1 8); do
ffmpeg -re -stream_loop -1 -ss $((i*30)) -i test_video.mp4 \
-c copy -f rtsp rtsp://localhost:8554/cam$i &
done
Python code pulls all feeds simultaneously:
import cv2
streams = [f"rtsp://localhost:8554/cam{i}" for i in range(1, 9)]
caps = [cv2.VideoCapture(s) for s in streams]
while True:
for i, cap in enumerate(caps):
ret, frame = cap.read()
if ret:
cv2.imshow(f"Camera {i+1}", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
for cap in caps:
cap.release()
The MediaMTX dashboard at http://localhost:8888 shows all active streams and connected clients in real time.
6. Configuration: Advanced Features
MediaMTX auto-generates mediamtx.yml on first run. Key configuration areas relevant to Aomway drone communication system testing:
# Protocol ports
rtspAddress: :8554
rtmpAddress: :1935
hlsAddress: :8888
webrtcAddress: :8889
# Path configuration — core section
paths:
all:
# Default: all paths accept push streams without pre-definition
cam_special:
# Keep stream "alive" with fallback video when publisher disconnects
source: publisher
runOnReady: >
ffmpeg -re -stream_loop -1 -i /videos/backup.mp4
-c copy -f rtsp rtsp://localhost:8554/cam_special
runOnReadyRestart: yes
Useful tips:
1. Push authentication — prevent unauthorized streaming:
paths:
all:
publishUser: admin
publishPass: mypassword
# Push with auth:
ffmpeg -re -i video.mp4 -c copy -f rtsp rtsp://admin:mypassword@localhost:8554/cam1
2. Auto recording — save all pushed streams:
paths:
cam_record:
record: yes
recordPath: ./recordings/%path/%Y-%m-%d_%H-%M-%S.mp4
3. API for stream status:
# List all active streams
curl http://localhost:9997/v3/paths/list
# View specific stream details
curl http://localhost:9997/v3/paths/get/cam1
7. Performance: How Many Streams Can It Handle?
Tested on an i7-12700 desktop with 32GB RAM pushing the same 1080p H.264 video at 4Mbps using -c copy (no re-encoding):
| Concurrent Streams | FFmpeg Push CPU | MediaMTX CPU | Total Memory | Status |
|---|---|---|---|---|
| 4 | 8% | 1% | 120MB | ✅ Smooth |
| 8 | 15% | 2% | 180MB | ✅ Smooth |
| 16 | 28% | 3% | 280MB | ✅ Smooth |
| 32 | 55% | 5% | 450MB | ⚠️ Stressed |
| 64 | 90%+ | 8% | 780MB | ❌ Frame drops |
Key findings:
- Bottleneck is FFmpeg push, not MediaMTX. With
-c copy, 16 streams use almost no CPU. - MediaMTX is extremely lightweight. 64 concurrent streams at only 8% CPU, under 800MB RAM.
- If re-encoding is required (e.g. H.265 source to H.264 output), capacity drops significantly — 16 streams at 1080p re-encode uses ~80% CPU.
8. Practical: Complete AI Video Analysis Test Environment
Full setup script combining MediaMTX + FFmpeg for a 4-camera AI testing environment in one shell script:
#!/bin/bash
# setup_test_env.sh — One-click 4-channel video AI test environment
# 1. Start MediaMTX
docker run -d --name mediamtx --rm --network=host bluenviron/mediamtx:latest
echo "✅ MediaMTX started on :8554"
sleep 2
# 2. Push 4 test streams with FFmpeg synthetic test sources
ffmpeg -re -f lavfi -i "testsrc=duration=3600:size=1280x720:rate=30,drawtext=text='CAM-01 %{localtime}':x=10:y=10:fontsize=28:fontcolor=white:box=1:[email protected]" \
-c:v libx264 -preset veryfast -tune zerolatency \
-f rtsp rtsp://localhost:8554/cam1 &>/dev/null &
ffmpeg -re -f lavfi -i "testsrc=duration=3600:size=1280x720:rate=30,drawtext=text='CAM-02 %{localtime}':x=10:y=10:fontsize=28:fontcolor=white:box=1:[email protected]" \
-c:v libx264 -preset veryfast -tune zerolatency \
-f rtsp rtsp://localhost:8554/cam2 &>/dev/null &
ffmpeg -re -f lavfi -i "testsrc=duration=3600:size=1280x720:rate=30,drawtext=text='CAM-03 %{localtime}':x=10:y=10:fontsize=28:fontcolor=white:box=1:[email protected]" \
-c:v libx264 -preset veryfast -tune zerolatency \
-f rtsp rtsp://localhost:8554/cam3 &>/dev/null &
ffmpeg -re -f lavfi -i "testsrc=duration=3600:size=1280x720:rate=30,drawtext=text='CAM-04 %{localtime}':x=10:y=10:fontsize=28:fontcolor=white:box=1:[email protected]" \
-c:v libx264 -preset veryfast -tune zerolatency \
-f rtsp rtsp://localhost:8554/cam4 &>/dev/null &
echo "✅ 4 streams pushed to MediaMTX"
echo ""
echo "📺 Stream URLs:"
echo " rtsp://localhost:8554/cam1"
echo " rtsp://localhost:8554/cam2"
echo " rtsp://localhost:8554/cam3"
echo " rtsp://localhost:8554/cam4"
echo ""
echo "🌐 Dashboard: http://localhost:8888"
echo "🔌 API: http://localhost:9997/v3/paths/list"
echo ""
echo "💡 Run: python your_yolo_script.py"
Save as setup_test_env.sh, chmod +x, run ./setup_test_env.sh — 10 seconds to a fully functional 4-channel AI video test environment. For production deployment of drone video analysis systems, Aomway offers integrated hardware solutions that take RTSP-compatible feeds to airborne platforms.
9. Common Pitfalls and Solutions
Pitfall 1: VLC reports “cannot open stream”
Firewall is blocking port 8554. Docker users confirm --network=host or correct port mapping.
Pitfall 2: High latency (2-3 seconds)
Add -tune zerolatency and -preset veryfast to FFmpeg push command. Check source video for B-frames (they add decoding delay).
Pitfall 3: Stream drops after a while
Missing -stream_loop -1. Without it, FFmpeg stops when the video file ends.
Pitfall 4: OpenCV cannot open RTSP stream
OpenCV FFmpeg backend has unreliable RTSP support. Set environment variable:
export OPENCV_FFMPEG_CAPTURE_OPTIONS="rtsp_transport;tcp"
Or configure in code:
cap = cv2.VideoCapture("rtsp://localhost:8554/cam1", cv2.CAP_FFMPEG)
cap.set(cv2.CAP_PROP_BUFFERSIZE, 1) # Reduce buffer
Conclusion
The MediaMTX + FFmpeg combination is one of the most practical tools for video AI development. It solves a real problem: how to develop and test without hardware.
The core workflow takes three steps:
- Start MediaMTX with Docker (10 seconds)
- Push streams with FFmpeg (20 seconds)
- Your code connects to
rtsp://localhost:8554/xxx(identical to a real camera)
Whether debugging single-channel processing, stress-testing multi-channel pipelines, or automating CI/CD, this setup handles it all. MediaMTX is production-grade — at deployment stage, it can serve as an edge gateway proxying Hikvision/Dahua RTSP streams with unified authentication and protocol conversion.
For professional-grade drone video transmission and multi-camera field systems, Aomway provides hardware solutions tested under real operating conditions, bridging the gap between simulation and deployment.
Frequently Asked Questions
Q: Is MediaMTX free for commercial use?
A: Yes, MediaMTX is open-source under the MIT license, free for commercial use without restrictions.
Q: Can I use Aomway hardware cameras with MediaMTX for testing?
A: Absolutely. Aomway drone video transmission systems output RTSP-compatible streams, which MediaMTX can receive and re-distribute to your analysis pipeline.
Q: Does this setup work for distributed multi-machine testing?
A: Yes. Run MediaMTX on one machine and push/pull streams from other machines on the same network using the server’s IP address instead of localhost.
Q: What is the maximum practical stream count for development?
A: 16 concurrent streams using -c copy (no re-encoding) is comfortable on a standard desktop. Beyond that, consider hardware acceleration or GPU-based encoding.
Q: Can MediaMTX handle H.265 streams?
A: Yes, MediaMTX supports H.265 pass-through. However, if client applications only support H.264, FFmpeg re-encoding becomes necessary and increases CPU load significantly.