Smart Speed Limiter – Intelligent Velocity Constraint Tool for Trajectory Actions

Resource

Get it on github

Introduce

Smart Speed Limiter is a lightweight Python script that automatically detects and corrects overspeed issues in JSON‑formatted action sequences. It keeps the movement speed between any two consecutive actions within a safe threshold of 600 units/second by redistributing time and reducing cycle repetition count, never by clipping stroke amplitude — preserving the overall shape and rhythm of the original trajectory as much as possible.

Written by DeepSeek.

Usage

(Python 3.6+ required. If you’re new to Python, just Google it or ask an AI.)

python limit_speed_deepseek.py <input.json> <output.json>
Key Features and How It Works

Funscript Speed Limiter v3.2

Overview

A speed limiter for funscripts that preserves amplitude, rhythm, and total duration. Instead of reducing stroke amplitude, it detects periodic blocks, reduces repetition count, and stretches the remaining cycles to fill the original block duration. Non-periodic overspeed gaps are re-timed, followed by a global speed correction pass.

Usage

python limit_speed_deepseek.py <input.funscript> <output.funscript>

Key Features

  • Preserves position amplitude whenever possible.
  • Preserves rhythm and total script duration.
  • Detects periodic blocks with period sizes P=2..30.
  • Reduces repeat count K and stretches cycles to lower speed.
  • Handles short non-periodic overspeed gaps up to MAX_GAP_PTS.
  • Applies global overspeed correction only above MAX_SPEED + SPEED_TOL.
  • Iterates global correction up to MAX_ITER times.
  • Cleans timestamps, removes duplicates, and enforces strictly increasing time.
  • Restores original first/last timestamps and positions.
  • Provides optional debug validation for outliers and overspeed segments.

How It Works

  1. Load and preprocess
    Sort actions by at and pos, drop near-duplicate points, and normalize same-timestamp conflicts.

  2. Detect periodic blocks
    Scan for repeated cycles where positions match within POS_TOL and relative timing matches within TIME_RATIO_TOL. Extend each match to count total repeats K. P=2 requires more repeats to avoid false positives.

  3. Limit periodic blocks
    For each detected block, try reducing K to K_new. Rescale the first K_new cycles uniformly into the original block duration T_block. This lowers speed without changing stroke amplitude. If even one cycle cannot fit, keep the original block.

  4. Handle non-periodic gaps
    For uncovered overspeed segments with at most MAX_GAP_PTS points, compute minimum required time per segment using MAX_SPEED, then distribute remaining slack proportionally to original segment durations.

  5. Global speed correction
    After merging all segments, correct only speeds above MAX_SPEED + SPEED_TOL. Push later timestamps forward as needed, then rescale total duration back to the original duration. Repeat up to MAX_ITER times.

  6. Final cleanup and output
    Sort, deduplicate, enforce increasing timestamps, restore original first/last points, and write compact JSON.

Parameters

Parameter Default Purpose
MAX_SPEED 600 Maximum speed in pos/s
SPEED_TOL 10 Global fix tolerance; only correct speeds above MAX_SPEED + SPEED_TOL
TIME_RATIO_TOL 0.15 Relative timing tolerance for period matching
MIN_PERIOD_SEGS 2 Minimum period segment count
MAX_PERIOD_SEGS 30 Maximum period segment count
MIN_REPEATS 3 Minimum repeats for normal periods
MIN_REPEATS_P2 5 Minimum repeats for P=2 periods
POS_TOL 0.5 Position tolerance for period matching
MAX_GAP_PTS 15 Maximum gap size eligible for re-timing
MAX_ITER 8 Maximum global correction iterations
DEBUG False Enable verbose validation output

Notes

  • The script cannot create time. If the original duration is insufficient, some overspeed may remain.
  • Speeds up to MAX_SPEED + SPEED_TOL are treated as acceptable to avoid unnecessary micro-adjustments.
  • Best suited for regular repetitive scripts, but designed to safely handle irregular segments.
  • Output preserves the original first/last timestamps and positions.

Comparison of Results

Before
before

After
after

Before

After

Compare

More compare and detail

For quite a long time, I had made quite a few iterations to my script speed-limiting tool, but they were not released. So this looks like a major update. In this version, it has become more stable and fixed more issues that existed in previous versions, such as inaccurate recognition of repeated waveforms, corrupting actions, and so on.

In my latest version, I tested it across multiple scripts, including some with very complex actions, random scripts, scripts with a random mix of irregular and regular patterns, and scripts with continuous overspeed. In these tests, the tool performed very well.

I recommend that you use this new version of the script. Below are some examples I used for testing. You can use my tool to process the original scripts and get the same results.

In the case of this random waveform, its processing effect is as follows.
Before
cassie-cage-ponytail-facefuck-alt_1080p.funscript (1.2 KB)
After
output.funscript (1023 Bytes)

In the case of complex interleaved actions, its processing effect is as follows:
Before
1000 Bekscript special HMV (Hardcore).funscript (52.2 KB)
After
output.funscript (38.0 KB)

In cases where regular and irregular patterns alternate and mix randomly, its processing effect is as follows:
Before
zzbusio - I love HENTAI #9 (Hardcore).funscript (22.4 KB)
After
output.funscript (22.3 KB)

The overspeed value of 613 here is because 610 is the maximum tolerance, while the 3 is a rounding precision issue; in practice, it still meets the requirements.If you are still not satisfied with this value, you can make adjustments in the tool.
Before
overspeed.funscript (1.3 KB)
After
output.funscript (537 Bytes)

Apology

I sincerely apologize to anyone who was hurt by my previous behavior. Since then, I’ve been working hard on this issue and have gone through many iterations. With this latest version, I believe it now delivers what I originally promised, so I’ve updated the post to reflect this update.

2 Likes

Could you upload an example before/after script so I can see what it’s doing. If it’s moving points left or right on the timeline I can’t use it.

1 Like

OK, you can visit this topic, you will see the EP05 script, this max speed is 1500. Then you download that script, use this python script. And you will know what happened.
[yeyebirdie] Cow EP04+EP05 - Scripts / Free Scripts - EroScripts

Does it move lower speed for HJ/BJ and upper points for regular action? As that is how you reduce speed.

This is hard to explain. If it’s only two actions and he’s still overspeeding, then he’ll adopt a reduced-amplitude approach. But if it’s a continuous stretch where he’s overspeeding throughout, he’ll calculate, within that section, the maximum number of times he can run at 600 speed while keeping the amplitude unchanged.

Why don’t you take a closer look at the documentation? It clearly spells out the main function and working principle of this script. The questions you’re asking now are all already covered in the docs. You really should do more of your own homework, or go ask an AI.

If I get any more similar questions like this, I won’t be responding.

1 Like

This is very cool, similar to the basic Funscript.io - Create, Modify, Enjoy Funscripts limiter tool, but a bit more intelligent, (plus always nice to have offline tools with the .py script to mess with! Will defo come in useful!

Thanks!

1 Like

Thank you for your appreciation! Yes, you are free to modify the script to suit your specific needs. Feel free! : )

Thank you for your initiative.

I would advise to choose a less aggressive approach, considering there’s clearly a language barrier and use of LLMs for translations and therefore imprecision and misunderstandings are to be expected.

The question roa had, was about which point gets shifted, in the case of amplitude reductions. And I think that is what you called a “mid-point compression strategy”, correct? From the code I can deduce that this script changes both the top and bottom actions symmetrically.


I’ve skimmed through the code and have a general question: Does this assume, that there are only extrema in the actions? I can’t identify a mechanism by which acceleration- or end-points are differentiated from extrema (change of direction points). But maybe there’s something implicit going on I can’t see.

3 Likes

Thanks for the technical question – it’s a good one.

You asked: “Does this assume there are only extrema? How do you differentiate extrema from acceleration endpoints?”

The answer is: I don’t differentiate them, and I don’t need to.

The algorithm is purely kinematic: Speed = Δpos / Δt . It doesn’t care about geometric shapes like peaks or valleys.

  1. For 2-action isolated overspeeds: I take the midpoint and compress both actions symmetrically. Whether they are a peak/valley, or just two adjacent points on a straight ramp, it mathematically still works perfectly – because the physics rule (v = dp/dt ) is universal.
  2. For continuous blocks (3+ actions): It relies on sum(min_deltas) vs total duration. The script only cares about the time constraints imposed by the speed limit, not the trajectory geometry. If the total required time exceeds the available time, it stretches time or drops points. No “extrema detection” is needed.

In practice, detecting “extrema” on noisy Funscript data would be unreliable. Using pure kinematic constraints is far more robust and deterministic. It works the same way whether it’s a wave, a ramp, or a random scatter.

As for the tone: I speak directly, not rudely. If someone asks a question that’s already clearly answered in the docs, I’ll point them to the docs and an AI – it saves everyone’s time. That’s just how I work. But if you have deeper tech questions like this one, I’m always happy to answer them.

Thanks for the help Rando but I already set the thread to muted as its a script wrecker. The answer was hilarious though. Go ask AI is a new one. lol

1 Like

Okay I’ll do it I guess.

First test:


^One point was completely deleted. Unsure why?

Second test:


^(one point amid slow movement worked well, changed speed from 660 to 595)


^that random stray blue line on the output is where the script left it at exactly 600.


From what I can see it does not move points left or right on the timeline, it only shortens stroke lengths. Not sure how this compares with Funscript.io’s speed limiter or other similar tools, but it seems to work okay.

Not that I’ve seen so far, other than that one weird deletion. (edit: it might break faster paced content than the sorts of things I make. I’m not going to bother testing it further.)

That said, it IS AI slop code and the author is pretty rude. I could get being arrogant if he actually made the script himself, but copy pasting deepseek code… idk man.

1 Like

You muted the thread, yet you came back to reply. That’s already inconsistent.

Calling it a “script wrecker” without any evidence, while the code is fully open for you to modify or ignore, says a lot more about you than about the script.

I won’t engage with baseless drive-by commentary. Mute it for good this time. Bye.

你有讨厌我的自由,你可以不喜欢我说话的方式,这是你的选择,与我无关。另外,关于代码来源,我已明确标注AI辅助,这在现代开发中毫无争议。

你说的这种情况我无法复现,我相信那个点被删除不是脚本导致的,很可能是有个粗鲁的人类删除了他。

况且相比之下,我只是直接不绕弯的说问题,而你直接人身攻击我,跳出了讨论脚本本身,我不知道谁更粗鲁。

如果你觉得这个脚本存在bug,你可以自己自由的更改,或者可以直接不使用。关于脚本出现的问题或者想问运作原理,我很愿意像回复评论区里另外一个人一样认真回答,但是如果是继续这样的对话是没有意义的。

如果你看不懂我在说什么,那就复制给Gemini让他亲自给你说。

"You’re free to dislike me; you can choose not to like the way I speak—that’s your choice, and it has nothing to do with me. Also, regarding the source of the code, I’ve clearly labeled it as AI-assisted, which is completely uncontroversial in modern development.

I can’t reproduce the situation you described. I believe that line wasn’t deleted by the script; it’s very likely that some rude human deleted it.

Besides, I’m simply pointing out the issue directly and without beating around the bush, while you’re launching personal attacks against me and straying from the discussion of the script itself. I’m not sure who’s being ruder here.

If you think this script has bugs, you’re free to modify it yourself or simply choose not to use it. Regarding issues with the script or questions about how it works, I’m more than happy to answer them seriously, just as I did for another person in the comments section. However, continuing this kind of conversation is pointless.

If you don’t understand what I’m saying, just copy this to Gemini and let it explain it to you."

Translated with deepl

2 Likes

There is definitely a language barrier and cultural difference here. Just because you can’t replicate bugs does not mean that said bug doesn’t exist you should be asking users of your program information to find the issue and fix it. It’s fine to be blunt but not everyone is tech savvy these are users of your program you can either ignore their questions or answer them knowing that there will be knowledge differences. Expecting a user to modify a program you made to fix it is not ideal although your program being open source is a good thing.

AI is still controversial in development although it’s not really relevant here. You are building a tool for scripters to use try to be more open or just ignore things to avoid arguments. You are the face of this program and how you act or are perceived influences how people view your program and it’s code. If you think there are personal attacks in the thread or derailment you can always report it to a mod.

3 Likes

You’re right. In fact, I’ve been reflecting on my behavior—perhaps my bluntness did come across as emotional or a bit sharp. I’ve changed the distribution method.

Now I’ve made it open source on GitHub, so everyone can access it more easily. It’s also more convenient to report issues there. I read everything you said carefully, and it all makes a lot of sense. Thank you for taking the time to reply to me. Have a nice day!

1 Like

test.funscript (1.2 KB)

That is the first script I tested it on. I just ran the process again and got the same outcome.
test.output.funscript (1.2 KB)

Fuck you I'm not a liar.

I think it is probably fair to say that your software does have some bugs, like all software. I’m not a liar (I just posted a recording of me doing the whole process of generating the limited script. Enjoy. Also fuck you.) and I didn’t manufacture a script just to point out a minor bug to a free piece of software. If you read my post I showed that your software mostly worked and didn’t destroy allscripts. Now, looking at your screenshots above, I can actually see why Roa might have come to that conclusion. That’s his opinion though.

My post was for other folks benefit so they could actually see what your script did. Clearly you thought that was a good idea since you updated your own post to include your own version of those screenshots – good. But first you were rude to me about asking for it. Why?

This has nothing to do with like or dislike. Out of all the folks in the comments, I’ve probably posted the most in-depth analysis of your python script, and I’ve now ran it about 5 times just so we can have this conversation. I may even be the only person in these comments who has actually run the script. If you don’t want feedback, fine, but then again why be a jerk about it? Just don’t respond if you aren’t looking for bugs/feedback?

The “personal attacks” you’re talking about are responses to your own words in this post. If you don’t want people to say you are being rude, don’t treat people like they are idiots or they are beneath you. This whole “go ask gemini” or “go translate my words for me,” “go do your homework,” is inconsistent for someone who claims to be direct and clear. Just say “I am not bugfixing, sorry. Feel free to make changes.”

1 Like

说起来有点复杂,我在现实里遇到了一些事情,那些事让我一蹶不振,我已经很长时间没更新了,你可以从我主页看到我以前也是一个script制作者并一直保持免费。

所以我想通过做点东西来冲淡我的悲伤。制作这个脚本确实用到了ai,但是他也不是一下就能做出来的,我反复修改了几个小时,可能我比较笨才花了这么久,但是他确实不仅仅是ai制作的脚本。有些部分是我的代码,有些部分是我的想法,我觉得我用到了ai于是我诚实的标注了他。

但是这都是我的问题,这一切都不是对你无礼的理由,何况你还真的帮我测试,愿意花时间。真的很抱歉,我确实是反应过度了,尤其是你说的bug,他真的存在。我盲目自大的指责你,那是恶意揣测没有证据。

我犯下的错误还包括对人不友好然后以自己说话直为理由,我回看了自己的话,他们很多确实很粗鄙不友善。我自己说自己说话直,然后看到别人说话也直就觉得生气,这是言行不一的,这一点我承认。

我和人争辩通常是为了维护我的自尊,但是我认识到事实比尊严重要。事实上,找到错误并改进他才是真正的自尊,否则就是无理取闹、没有道理的,根本谈不上自尊。然而其实我很害怕和人争吵,一旦这么做我就会手脚发凉感到害怕。

我再次真诚的道歉,这之后我会把精力更多的放在修复问题上。代码现在在GitHub上,那里可以更方便的提出问题和提出可能改进,对于你说的最新的bug,我正在着手修复。

汉语是我的母语,所以我出于尊重用我的语言亲手写下这些话,没有任何ai成分的,真诚的和你对话。然后我尊重社区的文化,下面是我为你翻译的英文版本:

It’s a bit complicated to explain. I’ve been going through some things in real life that really knocked me down, and I haven’t updated anything in a long time. If you look at my profile, you’ll see that I used to be a script creator too, and I always kept everything free.

So I wanted to make something to take my mind off the sadness. I did use AI when putting this script together, but it’s not like it just popped out in one go. I spent hours tweaking and revising it — maybe I’m just slow and that’s why it took so long — but it’s genuinely more than just an AI-generated script. Some parts are my own code, some parts are my own ideas. I used AI, and I honestly labeled it as such.

But all of that is my problem. None of it is an excuse to be rude to you, especially since you actually helped me test things and were willing to spend your time. I’m truly sorry. I really overreacted, especially about the bug you pointed out — it does exist. I arrogantly blamed you based on nothing, and that was malicious speculation with zero evidence.

I’ve also made the mistake of being unfriendly and then excusing it by calling myself “blunt.” I went back and read my own words; a lot of them were honestly vulgar and unkind. I call myself blunt, but then I get upset when others are blunt with me — that’s inconsistent, and I admit it.

I often argue with people to protect my ego, but I’ve realized that facts matter more than pride. Actually, finding mistakes and fixing them is what real self-respect is. Otherwise, it’s just unreasonable and makes no sense — it has nothing to do with self-respect at all. The truth is, I’m actually very afraid of arguments. Whenever it happens, my hands and feet go cold and I feel scared.

I sincerely apologize again. From now on, I’ll put more energy into fixing the problems. The code is now on GitHub, where it’s easier to raise issues and suggest improvements. As for the latest bug you mentioned, I’m already working on fixing it.

Chinese is my mother tongue, so out of respect I wrote these words by hand in my own language, with no AI involvement, to speak to you sincerely. And out of respect for the community culture, so this is the version I’ve translated for you.

3 Likes

The issue you mentioned has now been fixed. You can get the script from the link at the beginning of this post — click on the v1.0.1 release to obtain the latest version.

Below is the latest script execution result:

Before
cassie-cage-ponytail-facefuck-alt_1080p.funscript (1.2 KB)
After
output.funscript (1.2 KB)

1 Like

Ah, so the problem was that the section was labelled continuous since it had 3 points and points 1 & 3 both had the same value. Since continuous sections are candidate for deletion, it deleted the mid point and left a flat section.

The solution implemented still leaves the possibility of a similar result. If the high speed section is 3 points and the difference in start/end points is small (1 or 2 units) then it still leaves a plateau. I altered the original script so the start and end points would vary by 1 and you’ll see it still leaves a flat section.

test.funscript (1.2 KB)

test.output.funscript (1.2 KB)

My suggestion would be to rework the definition of a continuous section to be a minimum of an even number of points (ie. 4) since that will guarantee the start/end points are on opposite values.

1 Like