Automated Funscript Generation: How It Works

Deep dive into the technology behind automated funscript generation. Learn about the optical flow, motion tracking, and post-processing that power AI-based haptic scripting.

Automated funscript generation uses computer vision to convert video content into synchronized haptic device instructions. This article explains the underlying technology: how optical flow detects motion, how that motion is filtered and quantified, and how the raw data gets transformed into a smooth, device-ready funscript.

The Problem with Manual Scripting

Manual funscript creation requires watching a video frame by frame and placing keyframes that describe device movement at each moment. For high-quality scripts, scripters typically place keyframes at every significant change in motion direction or speed.

A one-minute video might require 120-240 keyframes for smooth playback. At a rate of roughly 2 keyframes per minute of work (including reviewing, adjusting, and testing), a single minute of scripted content takes 60-120 minutes of labor. This ratio makes manual scripting economically unviable at scale and limits the available library of scripted content.

The community has long needed a way to automate this process. Early attempts used audio waveform analysis, but haptic movement rarely correlates with audio. The breakthrough came from applying computer vision techniques that actually analyze what is happening visually in the video.

Optical Flow: The Foundation

Optical flow is a computer vision technique that estimates the motion of pixels between consecutive frames. By analyzing how brightness patterns shift from one frame to the next, optical flow produces a vector field that describes the direction and magnitude of movement at every point in the image.

HaptiQ uses dense optical flow (specifically the Farneback algorithm via OpenCV) to compute motion vectors for every pixel in the frame. This produces a detailed motion map that captures all movement in the scene.

How Dense Optical Flow Works

The Farneback method approximates each image neighborhood as a polynomial. By comparing polynomial coefficients between consecutive frames, the algorithm estimates displacement at each pixel. The result is two channels of data: horizontal (dx) and vertical (dy) displacement.

For funscript generation, the vertical component (dy) is typically the most relevant, as most haptic devices operate on a single linear axis. HaptiQ's pipeline extracts the dominant vertical motion vector within the region of interest and converts its magnitude to a position value.

Why Not Sparse Optical Flow?

Sparse methods like Lucas-Kanade track specific feature points rather than every pixel. While faster, sparse tracking can lose track of features during occlusions or rapid movement -- common in haptic content. Dense optical flow provides more robust motion estimation at the cost of computation time, which cloud-based processing makes acceptable.

Region of Interest: Focusing the Analysis

Raw optical flow captures all motion in the frame: camera shake, background movement, multiple subjects, lighting changes. For funscript generation, only a specific subset of this motion is relevant.

HaptiQ's guided tracking system addresses this by letting users define a region of interest (ROI). The ROI tells the pipeline exactly where to focus motion analysis, so motion elsewhere in the frame is ignored.

Manual ROI Selection

In the guided tracking interface, you draw a rectangle over the area of the video that should drive haptic output. The pipeline then only analyzes optical flow vectors within this region, filtering out irrelevant motion from the rest of the frame.

Automatic Cropping

For VR content, HaptiQ detects the stereo layout from the frame geometry, crops side-by-side or over-under footage to one eye, and trims letterbox bars, requiring zero manual input. It does not identify subjects: tracking works from motion alone.

Converting Motion to Position Values

Once the pipeline has isolated relevant motion vectors within the ROI, it needs to convert them into funscript position values (0-100). This conversion is not trivial and involves several steps:

1. Vector Aggregation

Within the ROI, thousands of individual optical flow vectors are aggregated into a single representative value. HaptiQ uses a weighted average that gives more importance to high-magnitude vectors (significant motion) while filtering out noise (small random fluctuations).

2. Temporal Integration

Optical flow gives velocity, but funscripts need position. The pipeline integrates velocity over time to produce position values. A constant upward motion translates to a rising position value; a reversal in direction creates a peak in the funscript.

3. Normalization

Raw integrated values can have arbitrary range. The pipeline removes slow drift and maps each passage onto the 0-100 range that funscript devices expect, using a rolling window a few seconds wide, so depth is kept relative within that window.

4. Keyframe Placement

Rather than creating a keyframe at every sampled frame (which would produce unnecessarily large files), the pipeline uses peak and valley detection to place keyframes at motion extremes. The RDP (Ramer-Douglas-Peucker) simplification algorithm further reduces keyframe count while preserving the essential shape of the motion curve.

Post-Processing: From Raw to Refined

The raw funscript from the generation stage is functional but rough. The pipeline's own post-processing smooths it, limits speed, simplifies points and normalises the range. After that, the editor's optional transform plugins let you refine it further (3 on Free, all 14 on HaptiQ Pro):

Smoothing Filters

Two smoothing approaches are available: moving average (fast, simple) and Savitzky-Golay (preserves peaks while reducing noise). The Savitzky-Golay filter fits polynomial curves to local neighborhoods of keyframes, producing smoother output that still feels responsive.

Anti-Jerk Filter

The anti-jerk plugin detects unrealistic acceleration in the script -- moments where the device would need to change direction instantly. It inserts transitional keyframes that smooth out these sharp reversals, making the output physically plausible for the device.

Speed Limiter

Different devices have different maximum speeds. The speed limiter plugin caps the rate of position change (50 to 500 position units per second, default 300), so you can keep the script within what your device can follow.

Amplitude Adjustment

The amplify plugin scales position values around the midpoint. Increasing amplitude makes strokes longer and more intense; decreasing it creates gentler, subtler movements. This lets users tune the script's intensity to their preference without re-generating.

Plugin Chaining

Plugins execute in sequence, with each plugin receiving the output of the previous one. HaptiQ's plugin chain editor lets you arrange, configure, and preview the effect of each plugin before committing changes. You can save plugin chains as presets for reuse across projects.

Multi-Axis Generation

Standard funscripts control a single axis of motion (typically linear stroke). Multi-axis devices like the OSR2+ and SR6 support up to 8 axes of motion including rotation, twist, and vibration.

HaptiQ Pro exports multi-axis T-code (8 axes: L0-L2, R0-R2, V0, A0). Secondary axes can be derived algorithmically from the primary motion pattern.

Quality Analysis and Validation

After generation and post-processing, HaptiQ's quality analyzer scores the script on a 0-100 scale across several dimensions:

Batch Processing at Scale

For users with large video libraries, HaptiQ's batch processing system processes multiple videos concurrently. Each video runs through the same pipeline as its own job, and the batch page shows each job's progress live over WebSocket for real-time monitoring.

Batch processing uses asyncio-based concurrency with configurable semaphore limits to balance throughput against server resources. Pro users get unlimited batch jobs; free tier users have 10 per month.

How Accurate Is Automated Generation?

Accuracy depends heavily on the source material and ROI configuration. We haven't measured it against hand-made scripts on real footage, so here is what to expect rather than a percentage:

For most users, generating first and then spending a few minutes on manual refinement takes a fraction of the time of scripting by hand.

Privacy and Security

HaptiQ does not sell your personal information. How long uploaded videos are kept, and how they are deleted, is set out in the privacy policy. See our privacy policy for complete details.

Experience Automated Funscript Generation

Upload a video and see HaptiQ's 5-stage pipeline in action. Free accounts can keep up to 3 projects and 5 videos.

Frequently asked questions

How does AI generate a funscript from a video?

HaptiQ uses a 5-stage pipeline built on OpenCV dense optical flow. Stage 1 analyzes the video. On VR footage HaptiQ detects the stereo layout, crops to one eye and trims letterbox bars before tracking. Stage 2 extracts frames. Stage 3 runs the Farneback optical-flow algorithm to compute motion vectors between frames sampled at a fixed time step (on small grayscale frames), optionally scoped to a region of interest drawn in the guided tracker. Stage 4 aggregates vectors, integrates velocity over time, normalizes to the 0–100 funscript range, and places keyframes at motion extremes. Stage 5 post-processes the result (smoothing, filtering and simplification) to produce a device-ready .funscript. The entire pipeline streams progress over WebSocket so you watch each stage live.

What is optical flow and why is it used for funscript generation?

Optical flow estimates how pixels move between consecutive video frames by analyzing brightness-pattern shifts. It produces a vector field describing direction and magnitude at every point. HaptiQ uses dense optical flow (Farneback via OpenCV) instead of sparse feature tracking like Lucas-Kanade because sparse methods lose track during occlusions or rapid movement — common in haptic content. Dense flow computes motion at every pixel, giving a detailed map that holds up through difficult scenes. For funscript generation, the vertical component (dy) drives the primary linear axis since most devices operate on a single up/down stroke. Audio-waveform analysis was tried in earlier tools but abandoned because haptic motion rarely correlates with audio.

How accurate is automated funscript generation compared to manual scripting?

Accuracy depends heavily on source footage, and we haven't measured it against hand-made scripts on real videos, so we don't quote a percentage. Well-framed, stable shots work best. VR footage is cropped to one eye automatically and tends to have consistent framing. Camera pans, shake and zoom are subtracted before motion is measured, but strong camera movement can still leave rough passages; guided tracking (Pro) lets you pick the region to follow. Complex multi-subject scenes are hardest, because tracking works from motion alone. Generating first and then spending a few minutes on the roughest scenes in the HaptiQ timeline editor is usually quicker than scripting the whole video by hand. The built-in quality analyzer scores each script 0–100 and flags specific weak sections — dead zones, sync gaps, unrealistic speeds — so you know where to polish.

What post-processing does HaptiQ apply to automated scripts?

The pipeline's own post-processing smooths the motion, limits speed, simplifies points with Ramer-Douglas-Peucker and normalises the range. On top of that, the editor has 14 optional transform plugins you apply yourself (3 on Free, all 14 on Pro). Two smoothing options are available: a fast moving average and Savitzky-Golay, which fits polynomial curves to local neighborhoods and preserves peaks while reducing noise. The anti-jerk plugin removes sudden jerky movements by limiting maximum speed. The speed limiter caps the speed between consecutive actions (50 to 500 position units per second), so you can keep the script within what your device can follow. Amplify scales positions around the midpoint for longer or gentler strokes. RDP simplification reduces keyframe count while preserving motion shape. Plugins chain in any order, and you can save configurations as presets for reuse across projects.

Create a free HaptiQ account to generate a funscript from your own video.