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

Sound Not Playing When Cache Is Enabled in Manim v0.18.1 #4005

Open
Nico3369 opened this issue Nov 10, 2024 · 4 comments
Open

Sound Not Playing When Cache Is Enabled in Manim v0.18.1 #4005

Nico3369 opened this issue Nov 10, 2024 · 4 comments

Comments

@Nico3369
Copy link

Hello Manim Community,

I am experiencing an issue with Manim Community version v0.18.1 related to sound playback when caching is enabled. Specifically, when I render my animations with caching turned on, the add_sound() function does not play any sound in the final video output.

Here are the details:

Manim Version: v0.18.1

Environment: Windows 10, Python 3.10, using a virtual environment.

Description of the Issue: When I run my script without any special cache arguments, or when using --flush_cache, the resulting video does not include the expected sounds added via add_sound(). However, when I use --disable_caching, the sound plays correctly.

For instance, the following command does not play the sound in the output:

sh
Copier le code
manim -pql --fps 30 animation_demos.py AnimationTests
Whereas the following command does play the sound:

sh
Copier le code
manim -pql --fps 30 --disable_caching animation_demos.py AnimationTests
It seems that something goes wrong with the caching mechanism when handling the add_sound() feature.

Steps to Reproduce:

Create a simple Manim script that uses add_sound() to add an audio clip during an animation.
Render the script normally with caching (manim -pql).
Notice that the output video does not include the sound.
Render the script with --disable_caching and observe that the sound is included as expected.
Expected Behavior: The sound should be played in the final video regardless of caching settings.

Actual Behavior: The sound only plays when caching is disabled.

Additional Notes: I have tried flushing the cache (--flush_cache) and different audio file formats (e.g., .mp3 and .wav). The issue persists as long as caching is enabled.

This looks like a potential bug in how Manim handles caching, specifically regarding sounds added during animations. I hope this information helps with diagnosing and fixing the issue.

If there are any workarounds or additional debug steps I can try, please let me know. Thank you in advance for your help!

Best regards,

@behackl
Copy link
Member

behackl commented Nov 10, 2024

I cannot reproduce this locally. Instead of using --flush_cache (which I am not sure can be trusted to really clear all of the cache), can you try to delete the media directory that contains all of the render output?

@Nico3369
Copy link
Author

I recently did some additional testing to investigate the issue with sound not playing during the rendering process when caching is enabled. Here's what I found:

I deleted the specific media folder related to the script (animation_demos.py) that was used for rendering. This included all the cached output specific to this script but not the entire media directory.

After deleting the script-specific cache, I ran the rendering command as follows:

manim -pql --fps 30 animation_demos.py AnimationTests

During this first run after deleting the cache, the sound played correctly as expected.

On the second run, without deleting the cache again, I noticed that the sound was not playing in the output video. It seems that the first render after cache removal works correctly, but subsequent renders fail to play the sound, which suggests that the caching mechanism may be affecting how sounds are handled.

This behavior is consistent: deleting the cache before rendering works, but if the cache is left intact, the sounds do not play after the first successful run.

I hope this information helps in diagnosing the caching issues related to audio playback in Manim v0.18.1.

@OliverStrait
Copy link

This bug is caused by self.renderer.skip_animations flag that never got reseted to False after cached rendering cycle is done and stays True when next sound is added.

# scene.py: def  add sound()
if self.renderer.skip_animations:
     return
else:
      #save sound 

@Nico3369
Copy link
Author

Thank you so much for pointing out the issue with the self.renderer.skip_animations flag. This explanation makes a lot of sense and really helps me understand why the sound wasn't working properly during subsequent renders.

I'll avoid touching the source code myself for now, but I hope that this can be addressed in a future update of Manim. It's great to have a clearer understanding of the root cause, and I'm very grateful for your insight.

Please let me know if there's anything else I can do to help with diagnosing or testing a fix. Thanks again for your time and assistance!

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

No branches or pull requests

3 participants