A video streaming application using RTSP/RTP protocols implemented in Python.
This project implements a client-server video streaming solution using:
- RTSP (Real Time Streaming Protocol) for session control
- RTP (Real-time Transport Protocol) for video data transmission
- UDP for video frame delivery
- Python >= 3.8.1
- Poetry for dependency management
- OpenCV for video processing
- Pillow for image handling
- Click for CLI interface
- Loguru for logging
- Install system dependencies:
sudo apt update
sudo apt install python3 python3-pip python3-venv python3-dev- Install Poetry:
curl -sSL https://install.python-poetry.org | python3 -- Clone the repository:
git clone https://github.com/gery25/prac1_xarxes_2025.git
cd prac1_xarxes_2025- Configure Poetry to create virtual environment in project:
poetry config virtualenvs.in-project true- Install dependencies:
poetry install- Verify installation:
poetry run xarxes2025 --versionIf you have errors with Pillow or OpenCV:
sudo apt install libjpeg-dev zlib1g-dev libopencv-dev
poetry installIf you have permission issues:
# Verify video file permissions
chmod 644 *.webm
chmod 644 *.webpIf you need to reinstall everything:
rm -rf .venv/
rm -f poetry.lock
poetry lock
poetry install- Start the server:
# Basic usage
poetry run xarxes2025 server
# With options
poetry run xarxes2025 server --port 4321 --host localhost --max-frames 100 --frame-rate 25- Start the client:
# Basic usage
poetry run xarxes2025 client
# With specific video file
poetry run xarxes2025 client rick.webm
# With all options
poetry run xarxes2025 client video.webm -p 4321 -h localhost -u 25000Both server and client support debug options:
# Enable debug logging
poetry run xarxes2025 --debug client
# Set debug level
poetry run xarxes2025 --debug --debug-level DEBUG client
# Log to file
poetry run xarxes2025 --debug --debug-file --debug-filename debug.log clientxarxes2025/
├── __init__.py # Package initialization and version
├── __main__.py # Entry point for CLI
├── cli.py # Command line interface implementation
├── client.py # RTSP client implementation
├── clienthandler.py # Server's client handler
├── server.py # RTSP server implementation
├── state_machine.py # RTSP state machine
├── udpdatagram.py # RTP packet handling
├── videoprocessor.py # Video frame processing
├── artificial.webm # Sample video file
├── operating.webm # Sample video file
├── rick.webm # Sample video file
└── rick.webp # Sample image file
- RTSP session management (SETUP, PLAY, PAUSE, TEARDOWN)
- RTP video streaming over UDP
- Real-time video display
- Packet loss detection
- Frame rate control
- Debug logging
- Multiple client support
- GUI client interface
- Activate virtual environment:
poetry shell- Install dependencies:
poetry install# Basic execution
poetry run xarxes2025 server
# With specific port
poetry run xarxes2025 server -p 4321
# With debug mode
poetry run xarxes2025 --debug server
# With specific debug level
poetry run xarxes2025 --debug --debug-level DEBUG server# Basic execution
poetry run xarxes2025 client
# With specific video
poetry run xarxes2025 client rick.webm
# With specific port
poetry run xarxes2025 client -p 4321
# With all options
poetry run xarxes2025 client artificial.webm -p 4321 -h localhost -u 25000
# With debug mode
poetry run xarxes2025 --debug client rick.webm
# With detailed debug
poetry run xarxes2025 --debug --debug-level DEBUG client operating.webm--debug: Enables debug mode--debug-level: Sets logging level (DEBUG, INFO, WARNING, ERROR)
-p, --port: RTSP port (default: 1234)-h, --host: Server IP address (default: localhost)
-p, --port: Server RTSP port (default: 1234)-h, --host: Server IP address (default: localhost)-u, --udp-port: Local UDP port for RTP (default: 3000)
rick.webm: Main test videoartificial.webm: Alternative videooperating.webm: Alternative videorick.webp: Test image
Server options:
--port: RTSP port (default: 4321)--host: Server IP address (default: localhost)--max-frames: Maximum frames to stream (default: None)--frame-rate: Frames per second (default: 25)
Client options:
--port: Server RTSP port (default: 4321)--host: Server IP address (default: localhost)--udp-port: Local UDP port for RTP (default: 25000)
Gerard Safont gsc23@alumnes.udl.cat or gerymaps200515@gmail.com
This project is based on the skeleton code from xarxes2025 by Carles Mateu. The original codebase was used as a starting point and has been modified and enhanced to meet the requirements of this project.