Skip to content

Commit 359ebe7

Browse files
author
HavenCTO
authored
Add FunscriptHaven plugin (#652)
1 parent 1a9a777 commit 359ebe7

4 files changed

Lines changed: 2087 additions & 0 deletions

File tree

plugins/FunscriptHaven/README.md

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# Funscript Haven
2+
3+
A StashApp plugin that automatically generates funscript files from video scenes using optical flow analysis.
4+
5+
## Overview
6+
7+
Funscript Haven analyzes video content using computer vision techniques to detect motion patterns and automatically generate funscript files compatible with interactive devices. The plugin integrates seamlessly with StashApp, allowing you to queue scenes for processing by simply adding a tag.
8+
9+
## Features
10+
11+
- **Automatic Funscript Generation** - Analyzes video motion using optical flow algorithms to generate accurate funscript files
12+
- **Tag-Based Workflow** - Simply tag scenes with a trigger tag to queue them for processing
13+
- **VR Support** - Automatically detects VR content and adjusts processing accordingly
14+
- **Multi-Axis Output** - Optional generation of secondary axis funscripts (Roll, Pitch, Twist, Surge, Sway)
15+
- **POV Mode** - Specialized processing mode for POV content
16+
- **Keyframe Reduction** - Intelligent compression to reduce file size while maintaining quality
17+
- **Batch Processing** - Process multiple scenes in sequence with progress tracking
18+
- **Configurable Settings** - Extensive options available through StashApp UI or config file
19+
- **Enjoying Funscript Haven?** Check out more tools and projects at https://github.com/Haven-hvn
20+
21+
## Requirements
22+
23+
- **StashApp** - This plugin requires a running StashApp instance
24+
- **Python 3.8+** - Python interpreter with pip
25+
- **Dependencies** (automatically installed):
26+
- `stashapp-tools` (>=0.2.58)
27+
- `numpy` (v1.26.4)
28+
- `opencv-python` (v4.10.0.84)
29+
- `decord` (v0.6.0)
30+
31+
## Installation
32+
33+
1. Copy the plugin files to your StashApp plugins directory:
34+
```
35+
<StashApp>/plugins/funscript_haven/
36+
├── funscript_haven.py
37+
├── funscript_haven.yml
38+
└── funscript_haven_config.py
39+
```
40+
41+
2. Reload plugins in StashApp (Settings → Plugins → Reload Plugins)
42+
43+
3. Configure plugin settings as needed (Settings → Plugins → Funscript Haven)
44+
45+
## Usage
46+
47+
### Basic Usage
48+
49+
1. **Tag a Scene**: Add the tag `FunscriptHaven_Process` to any scene you want to process
50+
2. **Run the Plugin**: Go to Settings → Tasks → Run Plugin Task → Funscript Haven → "Process Tagged Scenes"
51+
3. **Wait for Processing**: The plugin will process each tagged scene and generate funscript files
52+
4. **Check Results**: Funscript files are saved alongside the video files with `.funscript` extension
53+
54+
### Tag Workflow
55+
56+
| Tag | Purpose |
57+
|-----|---------|
58+
| `FunscriptHaven_Process` | Add to scenes to queue them for processing |
59+
| `FunscriptHaven_Complete` | Automatically added when processing succeeds |
60+
| `FunscriptHaven_Error` | Automatically added if an error occurs |
61+
62+
## Configuration
63+
64+
Settings can be configured in two ways:
65+
1. **StashApp UI** (Settings → Plugins → Funscript Haven) - Takes priority
66+
2. **Config File** (`funscript_haven_config.py`) - Fallback defaults
67+
68+
### Processing Settings
69+
70+
| Setting | Default | Description |
71+
|---------|---------|-------------|
72+
| `threads` | CPU count | Number of threads for optical flow computation |
73+
| `detrend_window` | 2 | Detrend window in seconds - controls drift removal (integer 1-10) |
74+
| `norm_window` | 4 | Normalization window in seconds - calibrates motion range (integer 1-10) |
75+
| `batch_size` | 3000 | Frames per batch - higher is faster but uses more RAM |
76+
| `overwrite` | false | Whether to overwrite existing funscript files |
77+
| `keyframe_reduction` | true | Enable intelligent keyframe reduction |
78+
79+
**Note:** StashApp UI only accepts integer values 0-10 for NUMBER type settings. Decimal values are converted internally.
80+
81+
### Mode Settings
82+
83+
| Setting | Default | Description |
84+
|---------|---------|-------------|
85+
| `pov_mode` | false | Improves stability for POV videos |
86+
| `balance_global` | true | Attempts to cancel out camera motion |
87+
88+
### Multi-Axis Settings
89+
90+
| Setting | Default | Description |
91+
|---------|---------|-------------|
92+
| `multi_axis` | false | Generate secondary axis funscripts |
93+
| `multi_axis_intensity` | 5 | Intensity of secondary axis motion (0-10, where 10 = maximum) |
94+
| `random_speed` | 3 | Speed of random motion variation (0-10, where 10 = fastest) |
95+
| `auto_home_delay` | 1 | Seconds of inactivity before returning to center (integer 0-10) |
96+
| `auto_home_duration` | 1 | Time to smoothly return to center position in seconds (integer 0-10) |
97+
| `smart_limit` | true | Scale secondary axis with primary stroke activity |
98+
99+
**Note:** Settings like `multi_axis_intensity` and `random_speed` use 0-10 integer scale in the UI but are converted to 0.0-1.0 decimal values internally.
100+
101+
### VR Detection
102+
103+
The plugin automatically detects VR content by checking for these tags (case-insensitive):
104+
- VR
105+
- Virtual Reality
106+
- 180°
107+
- 360°
108+
109+
You can customize VR tag detection in `funscript_haven_config.py`.
110+
111+
## Multi-Axis Output
112+
113+
When `multi_axis` is enabled, the plugin generates additional funscript files for secondary axes:
114+
115+
| Axis | File Suffix | Description |
116+
|------|-------------|-------------|
117+
| L1 (Surge) | `.surge.funscript` | Forward/Backward motion |
118+
| L2 (Sway) | `.sway.funscript` | Left/Right motion |
119+
| R0 (Twist) | `.twist.funscript` | Rotational twist |
120+
| R1 (Roll) | `.roll.funscript` | Roll rotation |
121+
| R2 (Pitch) | `.pitch.funscript` | Pitch rotation |
122+
123+
Secondary axes use OpenSimplex noise generation for natural, organic motion patterns that correlate with the primary stroke activity.
124+
125+
## Technical Details
126+
127+
### Algorithm Overview
128+
129+
1. **Frame Extraction** - Video frames are extracted and downsampled using decord
130+
2. **Optical Flow** - Farneback optical flow algorithm detects motion between frames
131+
3. **Divergence Analysis** - Maximum divergence points identify primary motion centers
132+
4. **Radial Motion** - Weighted radial motion calculation extracts stroke direction
133+
5. **Integration** - Piecewise integration of motion values
134+
6. **Detrending** - Rolling window detrending removes drift artifacts
135+
7. **Normalization** - Local normalization scales output to 0-100 range
136+
8. **Keyframe Reduction** - Direction changes are used to reduce keyframe count
137+
138+
### Performance Tips
139+
140+
- **RAM Usage**: Lower `batch_size` if running out of memory
141+
- **Speed**: Increase `threads` to match available CPU cores
142+
- **Quality**: Adjust `detrend_window` and `norm_window` based on video content
143+
- **File Size**: Keep `keyframe_reduction` enabled for smaller files
144+
145+
## Troubleshooting
146+
147+
### Common Issues
148+
149+
**"No scenes found with tag"**
150+
- Ensure the trigger tag exists and is applied to scenes
151+
- Check tag name matches exactly (case-sensitive)
152+
153+
**"Video file not found"**
154+
- Verify the scene has a valid file path in StashApp
155+
- Check file permissions
156+
157+
**Processing is slow**
158+
- Reduce `batch_size` to lower memory usage
159+
- Ensure sufficient CPU threads are allocated
160+
- VR content takes longer due to higher resolution processing
161+
162+
**Poor funscript quality**
163+
- Try adjusting `detrend_window` (higher for stable cameras)
164+
- Enable `pov_mode` for POV content
165+
- Disable `balance_global` if camera doesn't move
166+
167+
### Log Messages
168+
169+
Check StashApp logs for detailed processing information and error messages.
170+
171+
## License
172+
173+
This project is part of the StashApp Community Scripts collection.
174+
175+
## Credits
176+
177+
- Uses OpenCV for optical flow computation
178+
- Uses decord for efficient video frame extraction
179+
- OpenSimplex noise algorithm for multi-axis generation
180+
- Built for integration with StashApp

0 commit comments

Comments
 (0)