feat: rate based sync
This commit is contained in:
39
README.md
39
README.md
@@ -7,9 +7,11 @@ A Python video player using VLC SDK with synchan server timecode synchronization
|
||||
- VLC-based video playback with full media support
|
||||
- Real-time synchronization with synchan server
|
||||
- Reactive programming with RxPY
|
||||
- Automatic timecode correction
|
||||
- **Advanced synchronization with latency compensation**
|
||||
- **Playback rate adjustment for smooth sync**
|
||||
- Automatic timecode correction with smart seeking
|
||||
- Playback state synchronization
|
||||
- Volume and fullscreen controls
|
||||
- Volume, playback rate, and fullscreen controls
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -110,8 +112,11 @@ poetry run python -m vlchan.player video.mp4 http://192.168.1.100:3000
|
||||
- `get_volume() -> int`: Get current volume
|
||||
- `set_fullscreen(fullscreen: bool)`: Toggle fullscreen
|
||||
- `get_position() -> float`: Get current position in seconds
|
||||
- `get_compensated_position(latency: float) -> float`: Get latency-compensated position
|
||||
- `get_duration() -> float`: Get video duration in seconds
|
||||
- `is_playing() -> bool`: Check if playing
|
||||
- `get_rate() -> float`: Get current playback rate
|
||||
- `set_rate(rate: float)`: Set playback rate (1.0 = normal speed)
|
||||
- `cleanup()`: Clean up resources
|
||||
|
||||
#### Properties
|
||||
@@ -128,12 +133,32 @@ Data class containing synchronization state:
|
||||
|
||||
## Synchronization
|
||||
|
||||
The player automatically synchronizes with the synchan server:
|
||||
The player uses advanced synchronization logic similar to the synchan VideoPlayer component:
|
||||
|
||||
1. **Playback State**: Play/pause commands are synchronized
|
||||
2. **Time Position**: Video seeks to match synchan timecode
|
||||
3. **Threshold**: Only seeks if time difference exceeds 100ms
|
||||
4. **Reconnection**: Automatically attempts to reconnect on connection loss
|
||||
1. **Latency Compensation**: Server time is adjusted by network latency
|
||||
2. **Smart Seeking**: Large time differences (>1s) trigger immediate seeking
|
||||
3. **Playback Rate Adjustment**: Small differences are corrected by adjusting playback speed
|
||||
4. **Rate Formula**: `rate = 1 + min(max(diff * 0.5, -0.05), 0.05)`
|
||||
5. **Playback State**: Play/pause commands are synchronized
|
||||
6. **Reconnection**: Automatically attempts to reconnect on connection loss
|
||||
|
||||
### Synchronization Algorithm
|
||||
|
||||
```python
|
||||
# Apply latency compensation
|
||||
compensated_time = server_time + latency / 1000
|
||||
|
||||
# Calculate difference
|
||||
diff = compensated_time - local_time
|
||||
|
||||
# Large difference: seek immediately
|
||||
if diff > 1.0:
|
||||
player.seek(compensated_time)
|
||||
|
||||
# Small difference: adjust playback rate
|
||||
rate = 1 + min(max(diff * 0.5, -0.05), 0.05)
|
||||
player.set_rate(rate)
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
|
||||
Reference in New Issue
Block a user