Closed Br1el closed 12 months ago
@Br1el Hey, I noticed that you used requestAnimationFrame but did not handle the currentTime provided in the callback. The WVC recorded content should be an animation on a timeline, while the audio input synthesizer is a real-time animation creation process. If you want to accurately capture it, please first pre organize the PWM amplitude of the audio and play it back using anime.js or other animation libraries that support timelines. :D
Thanks for the response! Will try to adjust my code accordingly and let you know if it worked out for me. :)
I will close this issue and you can reopen it at any time if you have other questions. 😸
Problem Description
I am encountering an issue with synchronizing real-time audio-driven animation when capturing video using WebVideoCreator. The animation is based on audio frequency data and is rendered in real time in a browser environment.
The visualizer, implemented in JavaScript, creates a series of bars whose heights vary according to the frequency data obtained from the audio. This is achieved using the Web Audio API and the requestAnimationFrame method for smooth animations.
The problem I'm facing is capturing the real-time animation synchronously with the audio. When attempting to record the animation using tools like the Web Video Capture (WVC) API, I encounter synchronization issues where the audio and the visual elements are not perfectly aligned in the final video output. This desynchronization becomes more pronounced as the recording progresses, leading to a noticeable lag between the audio and the visual animation.
Attempted Solutions
FPS Logging and Performance Tweaks: I've added code to log the frames per second (FPS) to monitor the performance and ensure the animation runs smoothly. Adjustments were made to optimize the animation's performance.
Code Refinements: Throughout the development, I've tried several refinements to the code, aiming to optimize both the audio processing and the animation rendering.
Different Capture Methods with WVC: I tried various capturing setups using the Web Video Capture API to try and resolve the synchronization issues. Also running on Macbook or AWS EC2 instances gave similar results.
Code Snippets:
This is my audio processing setup:
This is my animation loop:
Following is my WebVideoCreator capturing setup:
Recordings
"Normal Screen Recording" gives the expected result when capturing the animation and represents the animation when looking at it in the browser window.
Normal Screen Recording:
https://github.com/Vinlic/WebVideoCreator/assets/48747427/e6e56a33-48d2-4af2-8e9b-b7d00eda6675
At 60 fps the animation in the recorded video runs too fast when combining with the audio:
WebVideoCreator 60 fps:
https://github.com/Vinlic/WebVideoCreator/assets/48747427/e4bdfff4-2ced-4d26-9b5f-4cdfff906606
At 30 fps the animation in the recorded video runs too slow when combining with the audio:
WebVideoCreator 30 fps:
https://github.com/Vinlic/WebVideoCreator/assets/48747427/d33811d6-d3de-4fec-99be-5919db2637a7