manim icon indicating copy to clipboard operation
manim copied to clipboard

Sound in Windows refuses to be rendered due to FFMPEG error

Open NeoPlato opened this issue 5 years ago • 25 comments

I tried to play the sound files as instructed by Theorem Of Beethoven yet a strange kind of error is produced specifically from FFMPEG that I don't completely understand but still is annoying.

Pardon my lack of good formatting.

File "C:\Manim\manim-18june\manimlib\extract_scene.py", line 155, in main scene = SceneClass(**scene_kwargs) File "C:\Manim\manim-18june\manimlib\scene\scene.py", line 79, in init self.file_writer.finish() File "C:\Manim\manim-18june\manimlib\scene\scene_file_writer.py", line 379, in finish self.combine_movie_files() File "C:\Manim\manim-18june\manimlib\scene\scene_file_writer.py", line 506, in combine_movie_files self.audio_segment.export( File "C:\Users\allan\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pydub\audio_segment.py", line 911, in export raise CouldntEncodeError( pydub.exceptions.CouldntEncodeError: Encoding failed. ffmpeg/avlib returned error code: 1

And then after that the program is generous enough to proceed with this:

Command:['ffmpeg', '-y', '-f', 'wav', '-i', 'C:\Users\ALLANM~1.000\AppData\Local\Temp\tmpz415eeyi', '-b:a', '312k', '-f', 'mp3', 'C:\Users\ALLANM~1.000\AppData\Local\Temp\tmpjzli2wu2']

Output from ffmpeg/avlib:

ffmpeg version git-2020-06-17-0b3bd00 Copyright (c) 2000-2020 the FFmpeg developers built with gcc 9.3.1 (GCC) 20200523 configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf libavutil 56. 55.100 / 56. 55.100 libavcodec 58. 92.100 / 58. 92.100 libavformat 58. 46.101 / 58. 46.101 libavdevice 58. 11.100 / 58. 11.100 libavfilter 7. 86.100 / 7. 86.100 libswscale 5. 8.100 / 5. 8.100 libswresample 3. 8.100 / 3. 8.100 libpostproc 55. 8.100 / 55. 8.100 Guessed Channel Layout for Input Stream #0.0 : stereo Input #0, wav, from 'C:\Users\ALLANM~1.000\AppData\Local\Temp\tmpz415eeyi': Duration: 00:00:02.23, bitrate: 2822 kb/s Stream #0:0: Audio: pcm_s32le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s32, 2822 kb/s Stream mapping: Stream #0:0 -> #0:0 (pcm_s32le (native) -> mp3 (mp3_mf)) Press [q] to stop, [?] for help [mp3_mf @ 06a9dec0] could not find any MFT for the given media type [mp3_mf @ 06a9dec0] could not create MFT Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height Conversion failed!

I really don't understand Manim and Python that well right now so this is just a good source for pure stress

I tried looking into the problem on my own but that aspect is from the FFMPEG side and I'm still not entirely sure what that program does. I also did intensive web searches for anyone with a similar problem but no dice.

By the way, I installed the latest version of Manim. Should I change and lose a good part of my current progress or is this fixable on the current version?

NeoPlato avatar Jun 30 '20 06:06 NeoPlato

FFMPEG is a converter application that converts from audio and video formats to other audio and video formats, it is what generates the output videos for this application (which just feeds it essentially series of pictures to use as frames). That error seems to imply that it's trying to read a file but the file is an invalid format or is empty, like maybe a background mp3 audio file?

OvermindDL1 avatar Jun 30 '20 14:06 OvermindDL1

But what do you think of the error at the pydub line? I know if the file destination was incorrect I would've just gotten that notification. This is something else entirely.

And I guarantee you, those other random files are not mp3 files.

NeoPlato avatar Jun 30 '20 18:06 NeoPlato

Can you condense the project with the issue into a minimal example that we can clone and try running to replicate the issue?

OvermindDL1 avatar Jun 30 '20 20:06 OvermindDL1

Sure. It's a simple Manim code that tests out a particular audio.

class AudioTest(Scene) def construct(self): group_dots=VGroup(*[Dot()for _ in range(3)]) group_dots.arrange_submobjects(RIGHT) for dot in group_dots: self.add_sound("click_this_and_nothing_else.wav",gain=-10) self.add(dot) self.wait() self.wait()

As you can tell by the name of the file I was quite frustrated.

The audio exists in the assets folder for Manin at sounds.

I renamed the audio file present there

Thank you so much for caring :)

NeoPlato avatar Jul 01 '20 07:07 NeoPlato

Thank you so much for caring :)

I'm new to manim but it's pretty interesting, so a good way for me to learn some less-code-related parts of it is to look at some issues and see what I can figure out. ^.^

I'm curious how the blocks are in the code? Is this correct?

class AudioTest(Scene):
    def construct(self):
        group_dots=VGroup(*[Dot()for _ in range(3)])
        group_dots.arrange_submobjects(RIGHT)
        for dot in group_dots:
            self.add_sound("click_this_and_nothing_else.wav",gain=-10)
            self.add(dot)
            self.wait()
        self.wait()

It was first autoformatted to this but this didn't seem like what was intended I'd think?

class AudioTest(Scene):
    def construct(self):
        group_dots=VGroup(*[Dot()for _ in range(3)])
        group_dots.arrange_submobjects(RIGHT)
        for dot in group_dots:
            self.add_sound("click_this_and_nothing_else.wav",gain=-10)
            self.add(dot)
            self.wait()
            self.wait()

For note, if you use code fences in github it will keep formatting, like this:

```
Some formatted
    text
```

Which will render like:

Some formatted
    text

:-)

OvermindDL1 avatar Jul 01 '20 14:07 OvermindDL1

I ran the first version of the code above and it generated this file successfully: https://overminddl1.com/tmp/AudioTest.mp4

All I did was copy it into a file named manim_1152_test.py, downloaded the click.wav and renamed it to click_this_and_nothing_else.wav, and then ran python -m manim ./manim_1152_test.py, chose AudioTest as option 1, waited about a minute and it finished by saying:

File ready at /home/overminddl1/Tools/manim/videos/manim_1152_test/1440p60/AudioTest.mp4

Played 4 animations

So I then uploaded that file at the above link. :-)


So this seems to imply something wrong with your setup. Googling your error messages...

It looks like that's an issue on windows when missing the media foundation windows libraries on windows 10 or windows server 2016, I'm guessing you have one of those?

Open an admin powershell window and run Install-WindowsFeature Server-Media-Foundation to install them it looks like (I don't use windows so I can't confirm any of this...). Does that work? Make sure that after running that command then make sure these files exist (among others but these are the entry points):

C:\Windows\System32\mfplat.dll
C:\Windows\System32\CompPkgSup.dll

C:\Windows\SysWOW64\mfplat.dll
C:\Windows\SysWOW64\CompPkgSup.dll

Please report back on all this, but it definitely seems like something windows specific and I haven't ran windows in well over a decade so I personally may not be more help beyond this point any more than google... ^.^;

But at least your code seems good and it works here. :-)

OvermindDL1 avatar Jul 01 '20 15:07 OvermindDL1

Thank you so much for caring :)

I'm new to manim but it's pretty interesting, so a good way for me to learn some less-code-related parts of it is to look at some issues and see what I can figure out. ^.^

I'm curious how the blocks are in the code? Is this correct?

class AudioTest(Scene):
    def construct(self):
        group_dots=VGroup(*[Dot()for _ in range(3)])
        group_dots.arrange_submobjects(RIGHT)
        for dot in group_dots:
            self.add_sound("click_this_and_nothing_else.wav",gain=-10)
            self.add(dot)
            self.wait()
        self.wait()

It was first autoformatted to this but this didn't seem like what was intended I'd think?

class AudioTest(Scene):
    def construct(self):
        group_dots=VGroup(*[Dot()for _ in range(3)])
        group_dots.arrange_submobjects(RIGHT)
        for dot in group_dots:
            self.add_sound("click_this_and_nothing_else.wav",gain=-10)
            self.add(dot)
            self.wait()
            self.wait()

For note, if you use code fences in github it will keep formatting, like this:

Some formatted text

Which will render like:

Some formatted
    text

:-)

Thank you for the formatting information kind sir

NeoPlato avatar Jul 01 '20 17:07 NeoPlato

Installing that Windows feature I haven't yet succeeded at. Is that the only command I should run or should I acquire something extra from the Internet?

In addition all I'm lacking is this file: C:\Windows\System32\CompPkgSup.dll

I am a Windows 7 user, sadly.

Thanks for the assist. I think if I can work my way around that installation I'll have this problem in the bag.

The autocorrected formatting you got should work, but the original code was shown to work in the video.

NeoPlato avatar Jul 01 '20 17:07 NeoPlato

Ah yeah that command doesn't work on Win7 from what I read, only Win10 and Win2016, I didn't see anything about Win7 when I was googling it. Hmm... As a test, are you able to convert the wav to an mp3 using ffmpeg? Just trying ffmpeg -i click.wav click.mp3 should be enough to test as it will pick up the mp3 encoder from the .mp3 new output file extension.

Where did you get ffmpeg? I can try grabbing it as well and run it in wine to see if I can replicate the issue.

OvermindDL1 avatar Jul 01 '20 18:07 OvermindDL1

FFMPEG I got from as I usually do, the free and completely safe web.

Here she is. I acquired my Windows version there but for the general case head here to get the one that works for you.

Do I need to specify that file location for the FFMPEG conversion? Ah well, I'll try them both ways

Thanks a lot for your help.

NeoPlato avatar Jul 02 '20 07:07 NeoPlato

Ah yeah that command doesn't work on Win7 from what I read, only Win10 and Win2016, I didn't see anything about Win7 when I was googling it. Hmm... As a test, are you able to convert the wav to an mp3 using ffmpeg? Just trying ffmpeg -i click.wav click.mp3 should be enough to test as it will pick up the mp3 encoder from the .mp3 new output file extension.

Where did you get ffmpeg? I can try grabbing it as well and run it in wine to see if I can replicate the issue.

And...nope!

C:\Manim\manim-18june>ffmpeg -i assets\sounds\click_this_and_nothing_else.wav click_this_and_nothing_else.mp3 ffmpeg version git-2020-06-17-0b3bd00 Copyright (c) 2000-2020 the FFmpeg developers built with gcc 9.3.1 (GCC) 20200523 configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf libavutil 56. 55.100 / 56. 55.100 libavcodec 58. 92.100 / 58. 92.100 libavformat 58. 46.101 / 58. 46.101 libavdevice 58. 11.100 / 58. 11.100 libavfilter 7. 86.100 / 7. 86.100 libswscale 5. 8.100 / 5. 8.100 libswresample 3. 8.100 / 3. 8.100 libpostproc 55. 8.100 / 55. 8.100 Guessed Channel Layout for Input Stream #0.0 : stereo Input #0, wav, from 'assets\sounds\click_this_and_nothing_else.wav': Metadata: encoder : FL Studio 9 Duration: 00:00:00.23, bitrate: 2121 kb/s Stream #0:0: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s32 (24 bit), 2116 kb/s Stream mapping: Stream #0:0 -> #0:0 (pcm_s24le (native) -> mp3 (mp3_mf)) Press [q] to stop, [?] for help [mp3_mf @ 00836e80] could not find any MFT for the given media type [mp3_mf @ 00836e80] could not create MFT Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height Conversion failed!

NeoPlato avatar Jul 02 '20 07:07 NeoPlato

Yeah you definitely found the issue, that's a broken ffmpeg, but that might be because it can't find the mp3 compressor on your system rather than any issue within itself. I can't really test any possible fixes to see if they help but googling for things like mp3_mf could not find any MFT for the given media type and mp3_mf could not create MFT along with "Windows 7" to try fixes would be the way to go now.

OvermindDL1 avatar Jul 02 '20 14:07 OvermindDL1

I'm curious, what version of Windows 7? It's not the home edition I hope? I've heard lots of issues about that one missing various functionality.

OvermindDL1 avatar Jul 02 '20 14:07 OvermindDL1

I'm curious, what version of Windows 7? It's not the home edition I hope? I've heard lots of issues about that one missing various functionality.

I think it's the 64 bit version. My little knowledge of computers in general limits me to that answer

NeoPlato avatar Jul 02 '20 14:07 NeoPlato

Yeah you definitely found the issue, that's a broken ffmpeg, but that might be because it can't find the mp3 compressor on your system rather than any issue within itself. I can't really test any possible fixes to see if they help but googling for things like mp3_mf could not find any MFT for the given media type and mp3_mf could not create MFT along with "Windows 7" to try fixes would be the way to go now.

I'm working on it myself as well. I know I've oversaid this but thank you

NeoPlato avatar Jul 02 '20 14:07 NeoPlato

Keep us updated! If someone else runs into the same issue then such a fix that you find would be very useful! :-)

OvermindDL1 avatar Jul 02 '20 14:07 OvermindDL1

Two weeks later. I chose life and postponed this problem. But the idea of having given up guilt-trip-ed me. So I'm back to this.

I took the advice of the error message and tried ffmpeg on other kinds of videos and audios. It can convert all the videos I've produced so far in Manim with whatever quality and a few audio files. I think that my best bet is if I can modify scenes in the manimlib folder to accomodate the frame rate and stuff.

Also, it appears not to accept the short audio file from before but smoothly converts a whole Breaking Benjamin song without breaking a sweat. Maybe that's the core problem.

It may just be hating on .wav files. As shown:

C:\Manim\manim-18june>ffmpeg -i assets\sounds\Tourniquet.mp3 assets\sounds\Tourniquet.wav
ffmpeg version git-2020-06-17-0b3bd00 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.3.1 (GCC) 20200523
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
--enable-amf
  libavutil      56. 55.100 / 56. 55.100
  libavcodec     58. 92.100 / 58. 92.100
  libavformat    58. 46.101 / 58. 46.101
  libavdevice    58. 11.100 / 58. 11.100
  libavfilter     7. 86.100 /  7. 86.100
  libswscale      5.  8.100 /  5.  8.100
  libswresample   3.  8.100 /  3.  8.100
  libpostproc    55.  8.100 / 55.  8.100
[mp3 @ 0465f340] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from 'assets\sounds\Tourniquet.mp3':
  Duration: 00:04:35.25, start: 0.000000, bitrate: 127 kb/s
    Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 128 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (mp3 (mp3float) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, wav, to 'assets\sounds\Tourniquet.wav':
  Metadata:
    ISFT            : Lavf58.46.101
    Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s
    Metadata:
      encoder         : Lavc58.92.100 pcm_s16le
size=   47417kB time=00:04:35.25 bitrate=1411.2kbits/s speed= 176x
video:0kB audio:47416kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000161%

Basically success!

Now see what the other way around looks like:

C:\Manim\manim-18june>ffmpeg -i assets\sounds\Tourniquet.wav assets\sounds\Tourniquet.mp3
ffmpeg version git-2020-06-17-0b3bd00 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.3.1 (GCC) 20200523
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
--enable-amf
  libavutil      56. 55.100 / 56. 55.100
  libavcodec     58. 92.100 / 58. 92.100
  libavformat    58. 46.101 / 58. 46.101
  libavdevice    58. 11.100 / 58. 11.100
  libavfilter     7. 86.100 /  7. 86.100
  libswscale      5.  8.100 /  5.  8.100
  libswresample   3.  8.100 /  3.  8.100
  libpostproc    55.  8.100 / 55.  8.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, wav, from 'assets\sounds\Tourniquet.wav':
  Metadata:
    encoder         : Lavf58.46.101
  Duration: 00:04:35.25, bitrate: 1411 kb/s
    Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (pcm_s16le (native) -> mp3 (mp3_mf))
Press [q] to stop, [?] for help
[mp3_mf @ 060aab00] could not find any MFT for the given media type
[mp3_mf @ 060aab00] could not create MFT
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!

Interesting.

Still working on it though, hope I succeed

NeoPlato avatar Jul 16 '20 12:07 NeoPlato

Hah, love the followup! ^.^

Also, it appears not to accept the short audio file from before but smoothly converts a whole Breaking Benjamin song without breaking a sweat. Maybe that's the core problem.

Hmm, so just processing that short little audio clip is failing for you with ffmpeg straight?! What's the error or what do it do?

OvermindDL1 avatar Jul 16 '20 19:07 OvermindDL1

Hmm, so just processing that short little audio clip is failing for you with ffmpeg straight?! What's the error or what do it do?

I still don't know exactly how to deal with this. The nature of audio files is still foreign to me. What I do think is I could perhaps change the scene_file_writer.py file to accomodate these files with specific bit rates and widths and heights.

And now I feel compelled to ask: remember this part in my error code:

Command:['ffmpeg', '-y', '-f', 'wav', '-i', 'C:\Users\ALLANM1.000\AppData\Local\Temp\tmpz415eeyi', '-b:a', '312k', '-f', 'mp3', 'C:\Users\ALLANM1.000\AppData\Local\Temp\tmpjzli2wu2']

When you ran the program from Manim did the command look like this or better? I think there's something about that .py file that directs FFMPEG to that odd file location. Maybe I could also check on that.

NeoPlato avatar Jul 17 '20 05:07 NeoPlato

The command is similar to that yeah, it processes in a temp location.

OvermindDL1 avatar Jul 17 '20 14:07 OvermindDL1

Interesting. I thought that was a problem with how it was running.

NeoPlato avatar Jul 18 '20 07:07 NeoPlato

I took a bit of advice you kind of alluded to from the start.

Out of necessity I have to migrate to another laptop for a week.

Installed Manim on this laptop (Windows 10, 32 bit etc) and here the audio works like a charm.

I could almost cry.

Almost.

ALMOST!

So in a week I may shift to previous laptop and keep up the good work of generating error messages but as of now my problem is 30% solved!

I should've done this ages ago :(

NeoPlato avatar Jul 20 '20 08:07 NeoPlato

same error. mp3 can convert to wav, wav cannot convert to mp3

ishowshao avatar Aug 13 '20 10:08 ishowshao

windows7

ishowshao avatar Aug 13 '20 10:08 ishowshao