ManimCommunity / manim-voiceover

Manim plugin for all things voiceover
https://voiceover.manim.community/en/stable
MIT License
186 stars 25 forks source link

Temp file not found when running GTTSExample #41

Open azampa opened 1 year ago

azampa commented 1 year ago

Description of bug / unexpected behavior

After installing manim-voiceover I checked installation with gtts-example.py running

manim -pql gtts-example.py --disable_caching GTTSExample

but obtained an error saying that the file GTTSExample_temp.mp4 has not been found. The voiceovers and the video get created, but the video has no voiceover

Expected behavior

Manim should produce the video with a voiceover and should report no errors. Indeed, if I remove the manim-voiceover stuff from the python file, using a run_time of 2 seconds, all works smoothly

How to reproduce the issue

Code for reproducing the problem See gtts-example.py distributed file

Additional media files

Images/GIFs

Logs

Terminal output ``` Manim Community v0.17.2 [03/19/23 17:32:19] INFO Caching disabled. cairo_renderer.py:68 DEBUG List of the first few animation hashes of the scene: cairo_renderer.py:87 ['uncached_00000'] INFO Animation 0 : Partial movie file written in scene_file_writer.py:527 'C:\Users\ale\Python\media\videos\gtts-example\480p15\partial_mov ie_files\GTTSExample\uncached_00000.mp4' [03/19/23 17:32:20] INFO Caching disabled. cairo_renderer.py:68 DEBUG List of the first few animation hashes of the scene: cairo_renderer.py:87 ['uncached_00000', 'uncached_00001'] INFO Animation 1 : Partial movie file written in scene_file_writer.py:527 'C:\Users\ale\Python\media\videos\gtts-example\480p15\partial_mov ie_files\GTTSExample\uncached_00001.mp4' INFO Caching disabled. cairo_renderer.py:68 DEBUG List of the first few animation hashes of the scene: cairo_renderer.py:87 ['uncached_00000', 'uncached_00001', 'uncached_00002'] [03/19/23 17:32:21] INFO Animation 2 : Partial movie file written in scene_file_writer.py:527 'C:\Users\ale\Python\media\videos\gtts-example\480p15\partial_mov ie_files\GTTSExample\uncached_00002.mp4' INFO Caching disabled. cairo_renderer.py:68 DEBUG List of the first few animation hashes of the scene: cairo_renderer.py:87 ['uncached_00000', 'uncached_00001', 'uncached_00002', 'uncached_00003'] INFO Animation 3 : Partial movie file written in scene_file_writer.py:527 'C:\Users\ale\Python\media\videos\gtts-example\480p15\partial_mov ie_files\GTTSExample\uncached_00003.mp4' DEBUG Animation with empty mobject animation.py:174 INFO Caching disabled. cairo_renderer.py:68 DEBUG List of the first few animation hashes of the scene: cairo_renderer.py:87 ['uncached_00000', 'uncached_00001', 'uncached_00002', 'uncached_00003', 'uncached_00004'] [03/19/23 17:32:22] INFO Animation 4 : Partial movie file written in scene_file_writer.py:527 'C:\Users\ale\Python\media\videos\gtts-example\480p15\partial_mov ie_files\GTTSExample\uncached_00004.mp4' DEBUG Animation with empty mobject animation.py:174 INFO Caching disabled. cairo_renderer.py:68 DEBUG List of the first few animation hashes of the scene: cairo_renderer.py:87 ['uncached_00000', 'uncached_00001', 'uncached_00002', 'uncached_00003', 'uncached_00004'] INFO Animation 5 : Partial movie file written in scene_file_writer.py:527 'C:\Users\ale\Python\media\videos\gtts-example\480p15\partial_mov ie_files\GTTSExample\uncached_00005.mp4' INFO Combining to Movie file. scene_file_writer.py:617 DEBUG Partial movie files to combine (6 files): scene_file_writer.py:561 ['C:\\Users\\ale\\Python\\media\\videos\\gtts-example\\480p15\\pa rtial_movie_files\\GTTSExample\\uncached_00000.mp4', 'C:\\Users\\ale\\Python\\media\\videos\\gtts-example\\480p15\\par tial_movie_files\\GTTSExample\\uncached_00001.mp4', 'C:\\Users\\ale\\Python\\media\\videos\\gtts-example\\480p15\\par tial_movie_files\\GTTSExample\\uncached_00002.mp4', 'C:\\Users\\ale\\Python\\media\\videos\\gtts-example\\480p15\\par tial_movie_files\\GTTSExample\\uncached_00003.mp4', 'C:\\Users\\ale\\Python\\media\\videos\\gtts-example\\480p15\\par tial_movie_files\\GTTSExample\\uncached_00004.mp4'] [mp3 @ 0000022C2CC8FE00] Failed to read frame size: Could not seek to 1026. C:\Users\ale\Python\media\videos\gtts-example\480p15\GTTSExample.wav: Invalid argument ┌─────────────────────────────── Traceback (most recent call last) ────────────────────────────────┐ │ C:\Users\ale\anaconda3\envs\my-manim-environment\lib\shutil.py:816 in move │ │ │ │ 813 │ │ if os.path.exists(real_dst): │ │ 814 │ │ │ raise Error("Destination path '%s' already exists" % real_dst) │ │ 815 │ try: │ │ > 816 │ │ os.rename(src, real_dst) │ │ 817 │ except OSError: │ │ 818 │ │ if os.path.islink(src): │ │ 819 │ │ │ linkto = os.readlink(src) │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘ FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\Users\\ale\\Python\\media\\videos\\gtts-example\\480p15\\GTTSExample_temp.mp4' -> 'C:\\Users\\ale\\Python\\media\\videos\\gtts-example\\480p15\\GTTSExample.mp4' During handling of the above exception, another exception occurred: ┌─────────────────────────────── Traceback (most recent call last) ────────────────────────────────┐ │ C:\Users\ale\anaconda3\envs\my-manim-environment\lib\site-packages\manim\cli\render\commands.py: │ │ 115 in render │ │ │ │ 112 │ │ │ try: │ │ 113 │ │ │ │ with tempconfig({}): │ │ 114 │ │ │ │ │ scene = SceneClass() │ │ > 115 │ │ │ │ │ scene.render() │ │ 116 │ │ │ except Exception: │ │ 117 │ │ │ │ error_console.print_exception() │ │ 118 │ │ │ │ sys.exit(1) │ │ │ │ C:\Users\ale\anaconda3\envs\my-manim-environment\lib\site-packages\manim\scene\scene.py:233 in │ │ render │ │ │ │ 230 │ │ │ return True │ │ 231 │ │ self.tear_down() │ │ 232 │ │ # We have to reset these settings in case of multiple renders. │ │ > 233 │ │ self.renderer.scene_finished(self) │ │ 234 │ │ │ │ 235 │ │ # Show info only if animations are rendered or to get image │ │ 236 │ │ if ( │ │ │ │ C:\Users\ale\anaconda3\envs\my-manim-environment\lib\site-packages\manim\renderer\cairo_renderer │ │ .py:259 in scene_finished │ │ │ │ 256 │ def scene_finished(self, scene): │ │ 257 │ │ # If no animations in scene, render an image instead │ │ 258 │ │ if self.num_plays: │ │ > 259 │ │ │ self.file_writer.finish() │ │ 260 │ │ elif config.write_to_movie: │ │ 261 │ │ │ config.save_last_frame = True │ │ 262 │ │ │ config.write_to_movie = False │ │ │ │ C:\Users\ale\anaconda3\envs\my-manim-environment\lib\site-packages\manim\scene\scene_file_writer │ │ .py:457 in finish │ │ │ │ 454 │ │ if write_to_movie(): │ │ 455 │ │ │ if hasattr(self, "writing_process"): │ │ 456 │ │ │ │ self.writing_process.terminate() │ │ > 457 │ │ │ self.combine_to_movie() │ │ 458 │ │ │ if config.save_sections: │ │ 459 │ │ │ │ self.combine_to_section_videos() │ │ 460 │ │ │ if config["flush_cache"]: │ │ │ │ C:\Users\ale\anaconda3\envs\my-manim-environment\lib\site-packages\manim\scene\scene_file_writer │ │ .py:664 in combine_to_movie │ │ │ │ 661 │ │ │ │ str(temp_file_path), │ │ 662 │ │ │ ] │ │ 663 │ │ │ subprocess.call(commands) │ │ > 664 │ │ │ shutil.move(str(temp_file_path), str(movie_file_path)) │ │ 665 │ │ │ sound_file_path.unlink() │ │ 666 │ │ │ │ 667 │ │ self.print_file_ready_message(str(movie_file_path)) │ │ │ │ C:\Users\ale\anaconda3\envs\my-manim-environment\lib\shutil.py:836 in move │ │ │ │ 833 │ │ │ │ │ symlinks=True) │ │ 834 │ │ │ rmtree(src) │ │ 835 │ │ else: │ │ > 836 │ │ │ copy_function(src, real_dst) │ │ 837 │ │ │ os.unlink(src) │ │ 838 │ return real_dst │ │ 839 │ │ │ │ C:\Users\ale\anaconda3\envs\my-manim-environment\lib\shutil.py:434 in copy2 │ │ │ │ 431 │ """ │ │ 432 │ if os.path.isdir(dst): │ │ 433 │ │ dst = os.path.join(dst, os.path.basename(src)) │ │ > 434 │ copyfile(src, dst, follow_symlinks=follow_symlinks) │ │ 435 │ copystat(src, dst, follow_symlinks=follow_symlinks) │ │ 436 │ return dst │ │ 437 │ │ │ │ C:\Users\ale\anaconda3\envs\my-manim-environment\lib\shutil.py:254 in copyfile │ │ │ │ 251 │ if not follow_symlinks and _islink(src): │ │ 252 │ │ os.symlink(os.readlink(src), dst) │ │ 253 │ else: │ │ > 254 │ │ with open(src, 'rb') as fsrc: │ │ 255 │ │ │ try: │ │ 256 │ │ │ │ with open(dst, 'wb') as fdst: │ │ 257 │ │ │ │ │ # macOS │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘ FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\ale\\Python\\media\\videos\\gtts-example\\480p15\\GTTSExample_temp.mp4' ```

System specifications

System Details - OS (with version, e.g., Windows 10 v2004 or macOS 10.15 (Catalina)): Windows 10 Pro version 22H2 build 19045.2728 - RAM: 8 GB - Python version (`python/py/python3 --version`): Python 3.10.9 - Installed modules (provide output from `pip list`): ``` Package Version ------------------------------ ----------- alabaster 0.7.13 arrow 1.2.3 astroid 2.15.0 asttokens 2.2.1 atomicwrites 1.4.1 attrs 22.2.0 autopep8 1.6.0 azure-cognitiveservices-speech 1.26.0 Babel 2.12.1 backcall 0.2.0 backports.functools-lru-cache 1.6.4 bcrypt 3.2.2 beautifulsoup4 4.11.2 binaryornot 0.4.4 black 23.1.0 bleach 6.0.0 brotlipy 0.7.0 CacheControl 0.12.11 certifi 2022.12.7 cffi 1.15.1 chardet 5.1.0 charset-normalizer 2.1.1 cleo 2.0.1 click 8.1.3 click-default-group 1.2.2 cloudpickle 2.2.1 cloup 0.13.1 colorama 0.4.6 colour 0.1.5 comm 0.1.2 comtypes 1.1.14 cookiecutter 2.1.1 crashtest 0.4.1 cryptography 39.0.2 cycler 0.11.0 Cython 0.29.33 dataclasses 0.8 debugpy 1.6.6 decorator 5.1.1 deepl 1.14.0 defusedxml 0.7.1 diff-match-patch 20200713 dill 0.3.6 distlib 0.3.6 docstring-to-markdown 0.11 docutils 0.19 dulwich 0.20.50 entrypoints 0.4 executing 1.2.0 fastjsonschema 2.16.3 filelock 3.10.0 flake8 6.0.0 fonttools 4.39.2 future 0.18.3 glcontext 2.3.7 gTTS 2.3.1 html5lib 1.1 humanhash3 0.0.6 idna 3.4 imagesize 1.4.1 importlib-metadata 6.1.0 importlib-resources 5.12.0 inflection 0.5.1 intervaltree 3.0.2 ipykernel 6.21.3 ipython 8.11.0 ipython-genutils 0.2.0 isort 5.12.0 isosurfaces 0.1.0 jaraco.classes 3.2.3 jedi 0.18.2 jellyfish 0.9.0 Jinja2 3.1.2 jinja2-time 0.2.0 jsonschema 4.17.3 jupyter_client 7.4.9 jupyter_core 5.3.0 jupyterlab-pygments 0.2.2 keyring 23.13.1 kiwisolver 1.4.4 lazy-object-proxy 1.9.0 lockfile 0.12.2 manim 0.17.2 manim-voiceover 0.3.0 ManimPango 0.4.3 mapbox-earcut 1.0.0 markdown-it-py 2.2.0 MarkupSafe 2.1.2 matplotlib 3.5.3 matplotlib-inline 0.1.6 mccabe 0.7.0 mdurl 0.1.0 mistune 2.0.5 mkl-service 2.4.0 moderngl 5.8.1 moderngl-window 2.4.1 more-itertools 9.1.0 mpmath 1.3.0 msgpack 1.0.5 multipledispatch 0.6.0 munkres 1.1.4 mutagen 1.46.0 mypy-extensions 1.0.0 nbclient 0.7.2 nbconvert 7.2.9 nbformat 5.7.3 nest-asyncio 1.5.6 networkx 2.8.8 numpy 1.24.2 numpydoc 1.5.0 packaging 23.0 pandas 1.5.3 pandocfilters 1.5.0 paramiko 3.1.0 parso 0.8.3 pathspec 0.11.1 pexpect 4.8.0 pickleshare 0.7.5 Pillow 9.4.0 pip 23.0.1 pkginfo 1.9.6 pkgutil_resolve_name 1.3.10 platformdirs 2.6.2 playsound 1.3.0 pluggy 1.0.0 ply 3.11 poetry 1.3.1 poetry-core 1.4.0 poetry-plugin-export 1.3.0 pooch 1.7.0 prompt-toolkit 3.0.38 psutil 5.9.4 ptyprocess 0.7.0 pure-eval 0.2.2 PyAudio 0.2.13 pycairo 1.23.0 pycodestyle 2.10.0 pycparser 2.21 pydocstyle 6.2.3 pydub 0.25.1 pyflakes 3.0.1 pyglet 1.5.27 Pygments 2.14.0 pylint 2.17.0 pylint-venv 3.0.1 pyls-spyder 0.4.0 PyNaCl 1.5.0 pynput 1.7.6 pyOpenSSL 23.0.0 pyparsing 3.0.9 pypiwin32 223 PyQt5 5.15.7 PyQt5-sip 12.11.0 PyQtWebEngine 5.15.4 pyrr 0.10.3 pyrsistent 0.19.3 PySocks 1.7.1 python-dateutil 2.8.2 python-dotenv 0.21.1 python-lsp-black 1.2.1 python-lsp-jsonrpc 1.0.0 python-lsp-server 1.7.1 python-slugify 8.0.1 pytoolconfig 1.2.5 pyttsx3 2.90 pytz 2022.7.1 pywin32 304 pywin32-ctypes 0.2.0 PyYAML 6.0 pyzmq 25.0.1 QDarkStyle 3.0.3 qstylizer 0.2.2 QtAwesome 1.2.3 qtconsole 5.4.1 QtPy 2.3.0 rapidfuzz 2.13.7 requests 2.28.2 requests-toolbelt 0.10.1 rich 13.3.2 rope 1.7.0 Rtree 1.0.1 scipy 1.10.1 screeninfo 0.8.1 setuptools 67.6.0 shellingham 1.5.1 sip 6.7.7 six 1.16.0 skia-pathops 0.7.4 snowballstemmer 2.2.0 sortedcontainers 2.4.0 soupsieve 2.3.2.post1 sox 1.4.1 Sphinx 6.1.3 sphinxcontrib-applehelp 1.0.4 sphinxcontrib-devhelp 1.0.2 sphinxcontrib-htmlhelp 2.0.1 sphinxcontrib-jsmath 1.0.1 sphinxcontrib-qthelp 1.0.3 sphinxcontrib-serializinghtml 1.1.5 spyder 5.4.2 spyder-kernels 2.4.2 srt 3.5.2 stack-data 0.6.2 svgelements 1.9.1 sympy 1.11.1 text-unidecode 1.3 textdistance 4.5.0 three-merge 0.1.1 tinycss2 1.2.1 toml 0.10.2 tomli 2.0.1 tomlkit 0.11.6 torch 1.12.1 tornado 6.2 tqdm 4.65.0 traitlets 5.9.0 trove-classifiers 2023.3.9 typing_extensions 4.5.0 ujson 5.7.0 unicodedata2 15.0.0 Unidecode 1.3.6 urllib3 1.26.15 virtualenv 20.21.0 watchdog 2.3.1 wcwidth 0.2.6 webencodings 0.5.1 whatthepatch 1.0.4 wheel 0.40.0 win-inet-pton 1.1.0 wrapt 1.15.0 yapf 0.32.0 zipp 3.15.0 ```
LaTeX details + LaTeX distribution (e.g. TeX Live 2020): + Installed LaTeX packages:
FFMPEG Output of `ffmpeg -version`: ``` ffmpeg version 5.1.2 Copyright (c) 2000-2022 the FFmpeg developers built with clang version 15.0.7 configuration: --prefix=/d/bld/ffmpeg_1674566436592/_h_env/Library --cc=clang.exe --cxx=clang++.exe --nm=llvm-nm --ar=llvm-ar --disable-doc --disable-openssl --enable-demuxer=dash --enable-hardcoded-tables --enable-libfreetype --enable-libfontconfig --enable-libopenh264 --ld=lld-link --target-os=win64 --enable-cross-compile --toolchain=msvc --host-cc=clang.exe --extra-libs=ucrt.lib --extra-libs=vcruntime.lib --extra-libs=oldnames.lib --strip=llvm-strip --disable-stripping --host-extralibs= --enable-gpl --enable-libx264 --enable-libx265 --enable-libaom --enable-libsvtav1 --enable-libxml2 --enable-pic --enable-shared --disable-static --enable-version3 --enable-zlib --enable-libopus --pkg-config=/d/bld/ffmpeg_1674566436592/_build_env/Library/bin/pkg-config libavutil 57. 28.100 / 57. 28.100 libavcodec 59. 37.100 / 59. 37.100 libavformat 59. 27.100 / 59. 27.100 libavdevice 59. 7.100 / 59. 7.100 libavfilter 8. 44.100 / 8. 44.100 libswscale 6. 7.100 / 6. 7.100 libswresample 4. 7.100 / 4. 7.100 libpostproc 56. 6.100 / 56. 6.100 ```

Additional comments

azampa commented 1 year ago

As you can see in the log, file GTTSExample.wav has problems: I have attached it. It seems that the origin of the issue lies in this file...

GTTSExample.zip

OsamaElshimy1973 commented 1 year ago

Copy all file in the Script Folder under your Manimd Enviromint Directory (....\envs..\scripts ) and past it to the same directory of your gtts-example.py and it will be resolved till they find a solution to this bug

yvvijay121 commented 1 year ago

I also have this issue, even after trying the solution that @OsamaElshimy1973 provided. Is there any progress on this issue?

osolmaz commented 1 year ago

@azampa @yvvijay121 Like you said, the following lines are where the error begins:

[mp3 @ 0000022C2CC8FE00] Failed to read frame size: Could not seek to 1026.
C:\Users\ale\Python\media\videos\gtts-example\480p15\GTTSExample.wav: Invalid argument

The GTTSExample.wav you uploaded indeed does not contain any audio. That is probably a temporary file that is created before the audio is merged to the final video, since I don't see any .wav file after render is complete:

$ ls -alh media/videos/gtts-example/**/*

media/videos/gtts-example/480p15:
total 344
drwxr-xr-x  5 onur  staff   160B May 21 19:25 .
drwxr-xr-x  3 onur  staff    96B May 21 19:25 ..
-rw-r--r--@ 1 onur  staff   168K May 21 19:25 GTTSExample.mp4
-rw-r--r--  1 onur  staff   264B May 21 19:25 GTTSExample.srt
drwxr-xr-x  3 onur  staff    96B May 21 19:25 partial_movie_files

media/videos/gtts-example/480p15/partial_movie_files:
total 0
drwxr-xr-x  3 onur  staff    96B May 21 19:25 .
drwxr-xr-x  5 onur  staff   160B May 21 19:25 ..
drwxr-xr-x  9 onur  staff   288B May 21 19:25 GTTSExample

media/videos/gtts-example/480p15/partial_movie_files/GTTSExample:
total 112
drwxr-xr-x  9 onur  staff   288B May 21 19:25 .
drwxr-xr-x  3 onur  staff    96B May 21 19:25 ..
-rw-r--r--  1 onur  staff   822B May 21 19:25 partial_movie_file_list.txt
-rw-r--r--  1 onur  staff   6.2K May 21 19:25 uncached_00000.mp4
-rw-r--r--  1 onur  staff    11K May 21 19:25 uncached_00001.mp4
-rw-r--r--  1 onur  staff    17K May 21 19:25 uncached_00002.mp4
-rw-r--r--  1 onur  staff   2.8K May 21 19:25 uncached_00003.mp4
-rw-r--r--  1 onur  staff   2.0K May 21 19:25 uncached_00004.mp4
-rw-r--r--  1 onur  staff   2.2K May 21 19:25 uncached_00005.mp4

It is probably related to the logic here

https://github.com/ManimCommunity/manim/blob/cbf6726f89972580cbb64e117da56f643919857d/manim/scene/scene_file_writer.py#L626-L665

There might be something wrong with either

I can't replicate this locally, so can you maybe take a look at these two? You can also debug locally by inserting breakpoints with e.g. import ipdb; ipdb.set_trace() in relevant manim or manim-voiceover files.

devRegion1 commented 1 year ago

The problem maybe due to this part in manim -> scene -> scene_file_writer.py file self.audio_segment.export(sound_file_path, bitrate="312k") In the above block, the 2nd parameter is not passed to "export" function call so it uses default "mp3" format to encode the output audio file with ".wav" suffix. You can try to change it as below: self.audio_segment.export(sound_file_path, format="wav", "bitrate="312k") It depends on your own package installation or other situations, here just for a suggestion you can try.

melonux commented 9 months ago

@devRegion1 Yes. I have the same problem and solved by your method. Thank you very much.

I wonder if we can treat it as a bug and fix it in official package?

ChungLeeCN commented 1 month ago

On Windows, this bug is likely caused by the clang version of ffmpeg, which is the version installed in the conda environment. As for cases not using the conda virtual environment, I haven't tested them, but I suspect the issue would be similar to that in the conda virtual environment. If we do not use the ffmpeg from the conda environment (for example, by renaming ffmpeg.exe in the conda environment to ffmpeg_bak.exe) and instead use the ffmpeg.exe downloaded from the official website, then this bug will not occur.