droidtui 0.2.9

A beautiful Terminal User Interface (TUI) for Android development and ADB commands
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# Screen Streaming Feature 📺

DroidTUI now includes a screen streaming feature that displays your Android device screen in a separate window with real video, just like [scrcpy](https://github.com/Genymobile/scrcpy)!

## Overview

The screen streaming feature captures your Android device's screen and displays it in a native window with real-time video decoding. This provides a lightweight alternative to scrcpy that's integrated directly into DroidTUI.

## Features

- **Real-time Video Streaming**: View your device screen with actual video (not ASCII art)
- **Separate Window**: Opens in a dedicated window that can be resized
- **Multiple Quality Modes**: Choose between quality and performance
- **H.264 Video Decoding**: Uses FFmpeg for efficient video decoding
- **Adjustable Bitrates**: Configure video quality for your needs
- **Aspect Ratio Preservation**: Maintains correct screen proportions

## How to Use

### Prerequisites

Before using screen streaming, ensure you have:

1. **ADB (Android Debug Bridge)**: Must be installed and in your PATH
   ```bash
   # Test ADB installation
   adb version
   ```

2. **FFmpeg**: Required for video decoding
   ```bash
   # Test FFmpeg installation
   ffmpeg -version
   
   # Install if needed:
   # macOS: brew install ffmpeg
   # Ubuntu/Debian: sudo apt install ffmpeg
   # Arch: sudo pacman -S ffmpeg
   # Windows: Download from ffmpeg.org
   ```

3. **Connected Device**: Android device with USB debugging enabled
   ```bash
   # Verify device connection
   adb devices
   ```

### Starting a Stream

1. Launch droidtui: `droidtui`
2. Navigate to **📺 Screen Stream** in the menu
3. Select one of the streaming options:
   - **📺 Start Screen Stream** - Standard quality (1080x1920, 8Mbps)
   - **🔍 High Quality Stream** - Best quality (1080x1920, 12Mbps)
   - **⚡ Fast Stream** - Lower resolution for speed (720x1280, 4Mbps)
4. A new window will open showing your device screen
5. Close the window or press Q/Esc in it to stop streaming

### Controls in Streaming Window

| Key | Action |
|-----|--------|
| `Q` or `Esc` | Close streaming window |
| Window Close Button | Stop streaming |

The window can be:
- **Resized**: Drag corners to resize
- **Moved**: Drag title bar to reposition
- **Minimized**: Minimize to taskbar/dock

## Technical Details

### How It Works

1. **Screen Recording**: Uses `adb exec-out screenrecord --output-format=h264` to capture screen
2. **Video Encoding**: Device encodes screen as H.264 video stream
3. **Streaming**: Raw H.264 data is piped from ADB to FFmpeg
4. **Decoding**: FFmpeg decodes H.264 to raw RGB24 frames
5. **Display**: minifb renders frames in a native window

### Architecture

```
Android Device → ADB screenrecord → H.264 Stream → FFmpeg → RGB Frames → Window Display
```

### Performance Characteristics

- **Frame Rate**: Up to 60 FPS (depends on device and bitrate)
- **Latency**: ~100-300ms (lower than ASCII implementation)
- **CPU Usage**: Moderate (video decoding)
- **Quality**: True video (not ASCII representation)
- **Resolution**: Native device resolution or configured size

### Quality Modes

| Mode | Resolution | Bitrate | FPS | Use Case |
|------|-----------|---------|-----|----------|
| Standard | 1080x1920 | 8Mbps | 60 | General use |
| High Quality | 1080x1920 | 12Mbps | 60 | Best quality |
| Fast | 720x1280 | 4Mbps | 60 | Performance |

## Requirements

### System Requirements

- **Operating System**: Linux, macOS, or Windows
- **RAM**: 100MB+ available
- **CPU**: Dual-core or better recommended
- **Graphics**: Any modern GPU

### Android Requirements

- **Android Version**: 5.0+ (API 21+)
- **USB Debugging**: Must be enabled
- **Screen Recording**: Device must support screenrecord command
- **Connection**: USB or WiFi ADB

### Software Dependencies

- **ADB**: Android SDK Platform Tools
- **FFmpeg**: Video codec library
- **DroidTUI**: This application

## Troubleshooting

### "Failed to start screenrecord" Error

**Cause**: ADB connection issue or device doesn't support screenrecord

**Solutions**:
```bash
# 1. Check ADB connection
adb devices

# 2. Test screenrecord manually
adb shell screenrecord --help

# 3. Reconnect device
adb kill-server
adb start-server
adb devices
```

### "Failed to start ffmpeg" Error

**Cause**: FFmpeg not installed or not in PATH

**Solutions**:
```bash
# 1. Check FFmpeg installation
ffmpeg -version

# 2. Install FFmpeg:
# macOS
brew install ffmpeg

# Ubuntu/Debian
sudo apt install ffmpeg

# Arch Linux
sudo pacman -S ffmpeg

# Windows - Add to PATH after downloading from ffmpeg.org
```

### Black or Frozen Screen

**Possible Causes**:
- Device screen is locked
- Device is in sleep mode
- USB connection is unstable
- Device is streaming to another application

**Solutions**:
1. Unlock device screen
2. Keep device screen on
3. Try a different USB cable/port
4. Close other apps using ADB screenrecord
5. Restart streaming

### Poor Video Quality

**Solutions**:
- Select "High Quality Stream" mode
- Use USB connection instead of WiFi ADB
- Ensure device isn't throttling (battery saver, overheating)
- Close background apps on device
- Increase bitrate in config

### Lag or Stuttering

**Solutions**:
- Select "Fast Stream" mode for lower latency
- Close other applications on computer
- Use USB connection (faster than WiFi)
- Reduce window size
- Check CPU usage

### Window Doesn't Open

**Possible Causes**:
- Display/graphics driver issues
- Window manager restrictions
- Insufficient permissions

**Solutions**:
1. Check error message in DroidTUI
2. Update graphics drivers
3. Try running with different user permissions
4. Check display configuration

## Comparison with Scrcpy

| Feature | DroidTUI Streaming | Scrcpy |
|---------|-------------------|--------|
| Display Method | Native window | Native window |
| Video Quality | H.264 decoded | H.264/H.265 decoded |
| Performance | 60 FPS capable | 30-120 FPS |
| Latency | ~100-300ms | ~35-70ms |
| Device Control | View only | Full control (touch, keyboard) |
| Installation | Single Rust binary | C binary + Java server |
| Integration | Built into DroidTUI | Standalone application |
| Requirements | ADB + FFmpeg | More dependencies |
| Audio | Not supported | Supported (Android 11+) |
| Recording | Not yet | Yes |

### When to Use DroidTUI Streaming

✅ **Good for:**
- Quick device screen viewing
- Integrated ADB workflow
- Simple monitoring tasks
- Already using DroidTUI for Android dev
- Want lightweight alternative to scrcpy
- View-only screen mirroring

❌ **Use Scrcpy instead for:**
- Full device control (touch, keyboard)
- Audio streaming
- Screen recording
- Minimum latency requirements
- Advanced features (HID, OTG, etc.)
- Gaming or real-time interaction

## Advanced Configuration

### Custom Resolution

Modify the StreamConfig in the code:

```rust
StreamConfig {
    width: 720,   // Custom width
    height: 1280, // Custom height
    bitrate: "6M".to_string(), // Custom bitrate
}
```

### Environment Variables

Set these for debugging:

```bash
# Enable verbose logging
export RUST_LOG=debug

# Force specific FFmpeg path
export FFMPEG_PATH=/path/to/ffmpeg

# Force specific ADB path
export ADB_PATH=/path/to/adb
```

## Known Limitations

1. **View Only**: Cannot control device (no touch/keyboard input)
2. **No Audio**: Audio streaming not implemented
3. **No Recording**: Cannot record streams yet
4. **Single Device**: Only one device at a time
5. **No Rotation**: Does not auto-rotate with device
6. **Basic Window**: No advanced window features yet

## Future Enhancements

Potential improvements being considered:

- [ ] Touch input support
- [ ] Keyboard input forwarding
- [ ] Screen recording to file
- [ ] Multiple simultaneous device streams
- [ ] Audio streaming support
- [ ] Rotation handling
- [ ] Better error recovery
- [ ] Configurable keyboard shortcuts
- [ ] Picture-in-picture mode
- [ ] Hardware acceleration
- [ ] Lower latency optimizations

## Tips for Best Experience

### 1. Optimal Setup
- Use USB 3.0 connection for best bandwidth
- Keep device screen brightness high
- Disable battery saver mode on device
- Close unnecessary background apps
- Use a short, high-quality USB cable

### 2. Quality vs. Performance
- **For Quality**: Use High Quality mode, higher bitrate
- **For Speed**: Use Fast mode, lower resolution
- **For Battery**: Lower bitrate, disconnect when not needed

### 3. Network Considerations
- USB is faster and more stable than WiFi ADB
- If using WiFi ADB, ensure strong signal
- Avoid network congestion

## Examples

### Basic Usage

```bash
# Start DroidTUI
droidtui

# Navigate to: 📺 Screen Stream → Start Screen Stream
# Window opens showing device screen
# Close window when done
```

### Quick Check Workflow

```bash
# Open DroidTUI
droidtui

# 1. Check device is connected: List Devices
# 2. Start screen stream
# 3. Verify app is running correctly
# 4. Close stream
# 5. Continue with other ADB commands
```

### Development Workflow

```bash
# 1. Deploy app to device
adb install -r myapp.apk

# 2. Start DroidTUI
droidtui

# 3. Start screen stream
# 4. Launch app on device
# 5. Monitor app behavior in stream
# 6. Check logs if needed: System Log
```

## Performance Benchmarks

Typical performance on modern hardware:

| Metric | Value |
|--------|-------|
| Startup Time | 1-3 seconds |
| Frame Rate | 50-60 FPS |
| Latency | 100-300ms |
| CPU Usage | 10-30% |
| Memory Usage | 50-150MB |
| Network/USB | 4-12 Mbps |

## Troubleshooting Checklist

Before reporting issues:

- [ ] ADB is installed and in PATH
- [ ] FFmpeg is installed and working
- [ ] Device is connected and authorized
- [ ] USB debugging is enabled
- [ ] Device screen is unlocked
- [ ] No other app is using screenrecord
- [ ] DroidTUI is up to date
- [ ] Tried restarting device
- [ ] Tried different USB port/cable

## Contributing

Want to improve streaming? Contributions welcome:

- Performance optimizations
- Touch input implementation
- Audio streaming support
- Better error handling
- Additional quality modes
- Documentation improvements

## Credits

- Inspired by [scrcpy]https://github.com/Genymobile/scrcpy - The gold standard for Android screen mirroring
- Uses [minifb]https://github.com/emoon/rust_minifb for window creation
- Uses [FFmpeg]https://ffmpeg.org/ for video decoding
- Built with ❤️ for the Android development community

## License

This feature is part of DroidTUI and licensed under the MIT license.

---

**Made with ❤️ and ☕ for Android developers who want integrated screen streaming**