Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync video speed with treadmill speed #4

Open
AMA3 opened this issue Jan 12, 2025 · 3 comments
Open

sync video speed with treadmill speed #4

AMA3 opened this issue Jan 12, 2025 · 3 comments

Comments

@AMA3
Copy link

AMA3 commented Jan 12, 2025

Hello! Thank you for creating this project.

I have create a video of my normal running route, which I edited to a consistent speed of 6.5 MPH. I have played the video at while running on my treadmill. I am about to buy a new treadmill with FTMS 4.0. and would like to be able to adjust the speed of the video to match the speed of my treadmill.

The browser provides an API for adjusting playback speed (HTML5 video playbackRate).

Would you be able to add a feature to your project to play a video and, given its recorded speed, adjust the playback speed to match the treadmill speed? If not, could you provide advice on how I might do it?

@janposselt
Copy link
Owner

Hi Andrew,

maybe the easiest would be to calculate a factor from the recorded speed and the reported speed. That factor could be used to set the playbackRate. For example when running at 7 MPH on the treadmill, the factor would be 1.07, based on a recording speed of 6.5 MPH.

I think there would be some prework (some controls for selecting a video, setting the base speed ...) to do but maybe I'll give it a try if there is some time.

Is your video public available?

@AMA3
Copy link
Author

AMA3 commented Jan 14, 2025

Thank you for the reply, Jan! No, my video is not publicly available (it is not high-enough quality to share with the world!). I'm sure you could use any video for testing purposes. There are many running videos on YouTube, for example.

@janposselt
Copy link
Owner

I’ve uploaded a simple demo script to https://ichbinlaufen.de/running-video/video-player.html. It demonstrates how to use TreadmillCommands.js and TreadmillControl.js in combination with an HTML video player and WebVTT to create a synchronized video player. The video may lag slightly when slowing down, likely because it was recorded at 30 fps. Using a higher frame rate could potentially improve the output.

The video-player.html file references https://ichbinlaufen.de/running-video/js/VideoPlayer.js, which serves as a good starting point for understanding how the synchronization works. Here are some key points:

  • treadmillControl.addDataHandler() registers a handler that is notified whenever the connected treadmill sends an update.
  • If there is an active TextTrack from the VTT file and treadmill data available, the playbackRate is dynamically adjusted based on the treadmill’s speed and the current segment speed defined in the VTT file.
  • observeTrack() and processMetadata() handle cues and commands, such as controlling the inclination.

To test it, simply open the link above and click the "Connect" button. Once the device is connected, press "Load Demo Data" and start the video. When you begin using the treadmill, the playbackRate and inclination adjustments should activate automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants