Bu proje, Raspberry Pi üzerinde çalışan MediaMTX sunucusundan gelen RTSP yayınını web tarayıcılarında görüntülemek için Flask tabanlı bir arayüz sağlar.
MediaMTX, RTSP yayınlarını otomatik olarak tarayıcı dostu formatlara (WebRTC ve HLS) dönüştürür.
- Raspberry Pi (veya Debian tabanlı Linux)
- Python 3.8+
- MediaMTX sunucusu çalışıyor ve 8888/8889 portlarında aktif
- Flask + Gunicorn + Gevent
# Sistem paketleri
sudo apt update && sudo apt install -y python3-pip python3-venv
# Proje klasörü
mkdir -p ~/transmind-pi && cd ~/transmind-pi
# Sanal ortam
python3 -m venv venv
source venv/bin/activate
# Python paketleri
pip install --upgrade pip
pip install Flask gunicorn gevent# Development
python app.py
# Production (Gunicorn)
gunicorn --worker-class gevent --workers 1 --bind 0.0.0.0:5000 app:appTarayıcıdan erişin: http://localhost:5000 (veya Pi'nin IP adresi)
MediaMTX henüz kurulu değilse:
# İndir ve kur
sudo mkdir -p /opt/mediamtx
cd /opt/mediamtx
sudo wget https://github.com/bluenviron/mediamtx/releases/download/v1.1.0/mediamtx_v1.1.0_linux_armv7.tar.gz
sudo tar -xzf mediamtx_v1.1.0_linux_armv7.tar.gz
# IPv4 dinlemesi açmak için yapılandırma
sudo nano /opt/mediamtx/mediamtx.ymlDosyada şu satırları bulup düzenle:
# HLS Sunucusu (Port 8888)
hlsAddress: 0.0.0.0:8888
# WebRTC Sunucusu (Port 8889)
webrtcAddress: 0.0.0.0:8889
# Stream yollarını yapılandır (paths bölümüne ekle)
paths:
cam:
# RTSP kaynağı (kendi kameranızın RTSP URL'si)
source: rtsp://your-camera-ip:554/stream
stream:
# Stream, cam ile aynı kaynağı kullanır
source: rtsp://your-camera-ip:554/streamServisi başlat:
sudo systemctl start mediamtx
sudo systemctl enable mediamtxEğer şu hatayı alıyorsanız:
path 'stream' is not configured
Bu, MediaMTX'in /stream yolunu tanımadığı anlamına gelir. Çözmek için:
-
MediaMTX config dosyasını düzenle:
sudo nano /opt/mediamtx/mediamtx.yml
-
paths:bölümünü bulup şu eklemeyi yap:paths: cam: # Kameranızın RTSP adresi source: rtsp://192.168.1.100:554/stream stream: # Stream yolu (cam ile aynı kaynağı kullanır) source: rtsp://192.168.1.100:554/stream
-
Servisi yeniden başlat:
sudo systemctl restart mediamtx
Not: rtsp://192.168.1.100:554/stream kısmını kendi kameranızın RTSP adresine göre değiştirin!
MediaMTX sunucusu iki farklı yayın yöntemi sağlar:
- URL:
http://172.28.117.8:8889/cam - Avantajları: En düşük gecikme, en yüksek kalite
- Dezavantajları: Özel tarayıcı desteği gerekebilir
- URL:
http://172.28.117.8:8888/cam/index.m3u8 - Avantajları: Tüm cihazlarda çalışır (iPhone, iPad, eski tarayıcılar)
- Dezavantajları: Biraz daha yüksek gecikme
transmind-pi/
├── app.py # Flask uygulaması
├── requirements.txt # Python bağımlılıkları
├── templates/
│ ├── index.html # Ana sayfa (WebRTC + HLS)
│ └── error.html # 404 hata sayfası
└── README.md # Bu dosya
Flask uygulaması sadece statik sayfa sunmaktadır:
- GET /: Ana sayfa (WebRTC ve HLS yayınları gösteren arayüz)
- GET /health: Sunucu sağlık kontrolü (basit "OK" döner)
- 404 Handler: Bulunamayan sayfalar için hata sayfası
@app.route('/')
def index():
return render_template('index.html')
@app.route('/health')
def health():
return ('OK', 200)index.html sayfası şunları sağlar:
✅ WebRTC Oynatıcı - MediaMTX'in yerleşik web arayüzünü iframe ile gösterir ✅ HLS Video Oynatıcı - HLS.js kütüphanesiyle video akışı oynatır ✅ Canlı Durum Göstergesi - Her iki yayının durumunu gösterir ✅ Responsive Tasarım - Mobil, tablet ve masaüstü cihazlarda uyumlu ✅ Dinamik Saat - Cihaz saatini gerçek zamanlı gösterir
/etc/systemd/system/transmind-pi.service dosyasını oluştur:
[Unit]
Description=TransMind Flask Web Server (MediaMTX Interface)
After=network.target mediamtx.service
Wants=mediamtx.service
[Service]
User=pi
Group=www-data
WorkingDirectory=/home/pi/transmind-pi
ExecStart=/home/pi/transmind-pi/venv/bin/gunicorn \
--worker-class gevent \
--workers 1 \
--bind 0.0.0.0:5000 \
app:app
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.targetAktifleştir:
sudo systemctl daemon-reload
sudo systemctl enable transmind-pi.service
sudo systemctl start transmind-pi.service
sudo systemctl status transmind-pi.service
# Logları izle
sudo journalctl -u transmind-pi.service -f/etc/nginx/sites-available/transmind-pi:
server {
listen 80;
server_name transmind.local;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}Aktifleştir:
sudo ln -s /etc/nginx/sites-available/transmind-pi /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginxGüvenli ve kurulumu kolay:
curl -fsSL https://tailscale.com/install.sh | sh
sudo tailscale upSonra http://<tailscale-ip>:5000 ile erişin.
./ngrok http 5000Router ayarlarında 5000 portunu forward et + DDNS (No-IP/DuckDNS) kullan.
# Portun açık olup olmadığını kontrol et
sudo netstat -tlnp | grep 5000
sudo netstat -tlnp | grep 8888
sudo netstat -tlnp | grep 8889
# Firewall kontrolü
sudo ufw status
sudo ufw allow 5000/tcp
sudo ufw allow 8888/tcp
sudo ufw allow 8889/tcp# MediaMTX servisi kontrol et
sudo systemctl status mediamtx
sudo journalctl -u mediamtx -f
# IPv4 dinlemesi sağla
sudo nano /opt/mediamtx/mediamtx.yml
# hlsAddress: 0.0.0.0:8888
# webrtcAddress: 0.0.0.0:8889
sudo systemctl restart mediamtxEğer harici kaynaktan erişiyorsan ve CORS hataları alıyorsan, Nginx'te header ekle:
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';- Python 3 + Flask kurulu
- MediaMTX çalışıyor (8888 ve 8889 portlarda dinleme)
-
http://localhost:5000tarayıcıda açılıyor - WebRTC yayını görünüyor
- HLS yayını görünüyor
- Systemd servisi otomatik başlıyor
TransMind - Akıllı Ulaştırma Yönetim Sistemi
Sorun varsa loglara bak:
# Flask uygulaması
sudo journalctl -u transmind-pi.service -f
# MediaMTX
sudo journalctl -u mediamtx.service -f
# Nginx
sudo tail -f /var/log/nginx/error.log