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

[Bug]: Error when encoding mp4 result - av.codec.codec.UnknownCodecError: libx264 #377

Closed
2 tasks done
vicktorhu opened this issue Dec 23, 2023 · 6 comments
Closed
2 tasks done

Comments

@vicktorhu
Copy link

vicktorhu commented Dec 23, 2023

Is there an existing issue for this?

  • I have searched the existing issues and checked the recent builds/commits of both this extension and the webui

Have you read FAQ on README?

  • I have updated WebUI and this extension to the latest version

What happened?

Specs if necessary

I always get this error when I select mp4 as a result from the AnimateDiff submenu:

2023-12-23 12:30:45,077 - AnimateDiff - INFO - Saving D:\sdoutputs\txt2img-images\AnimateDiff\2023-12-23\00005-1505117023.mp4
*** Error running postprocess: F:\stable-diffusion-webui\extensions\sd-webui-animatediff\scripts\animatediff.py
    Traceback (most recent call last):
      File "F:\stable-diffusion-webui\modules\scripts.py", line 750, in postprocess
        script.postprocess(p, processed, *script_args)
      File "F:\stable-diffusion-webui\extensions\sd-webui-animatediff\scripts\animatediff.py", line 96, in postprocess
        AnimateDiffOutput().output(p, res, params)
      File "F:\stable-diffusion-webui\extensions\sd-webui-animatediff\scripts\animatediff_output.py", line 39, in output
        video_paths += self._save(params, frame_list, video_path_prefix, res, i)
      File "F:\stable-diffusion-webui\extensions\sd-webui-animatediff\scripts\animatediff_output.py", line 236, in _save
        stream = output.add_stream('libx264', params.fps, options=options)
      File "av\\container\\output.pyx", line 62, in av.container.output.OutputContainer.add_stream
      File "av\\codec\\codec.pyx", line 179, in av.codec.codec.Codec.__cinit__
      File "av\\codec\\codec.pyx", line 187, in av.codec.codec.Codec._init
    av.codec.codec.UnknownCodecError: libx264

I have imageio_ffmpeg installed on venv\Lib\site-packages and I also installed the regular ffmpeg-full via chocolatey

Steps to reproduce the problem

  1. Open webui and fill the generation prompts
  2. Open animatediff section
  3. check enable animatediff, choose model, set number of frames to 16
  4. check the mp4 option on the save format submenu
  5. click generate
  6. images will be generated normally but it will fail when merging to the mp4 file. other formats (gif, webm, etc) work fine.

What should have happened?

the mp4 file generated successfully

Commit where the problem happens

webui: cf2772fab0af5573da775e7437e6acdca424f26e
extension: 55ecff3

What browsers do you use to access the UI ?

Mozilla Firefox

Command Line Arguments

--disable-safe-unpickle

Console logs

2023-12-23 12:30:45,077 - AnimateDiff - INFO - Saving D:\sdoutputs\txt2img-images\AnimateDiff\2023-12-23\00005-1505117023.mp4
*** Error running postprocess: F:\stable-diffusion-webui\extensions\sd-webui-animatediff\scripts\animatediff.py
    Traceback (most recent call last):
      File "F:\stable-diffusion-webui\modules\scripts.py", line 750, in postprocess
        script.postprocess(p, processed, *script_args)
      File "F:\stable-diffusion-webui\extensions\sd-webui-animatediff\scripts\animatediff.py", line 96, in postprocess
        AnimateDiffOutput().output(p, res, params)
      File "F:\stable-diffusion-webui\extensions\sd-webui-animatediff\scripts\animatediff_output.py", line 39, in output
        video_paths += self._save(params, frame_list, video_path_prefix, res, i)
      File "F:\stable-diffusion-webui\extensions\sd-webui-animatediff\scripts\animatediff_output.py", line 236, in _save
        stream = output.add_stream('libx264', params.fps, options=options)
      File "av\\container\\output.pyx", line 62, in av.container.output.OutputContainer.add_stream
      File "av\\codec\\codec.pyx", line 179, in av.codec.codec.Codec.__cinit__
      File "av\\codec\\codec.pyx", line 187, in av.codec.codec.Codec._init
    av.codec.codec.UnknownCodecError: libx264

Additional information

No response

@yanxiaodi
Copy link

I got the same error.

@nilnoun
Copy link

nilnoun commented Dec 24, 2023

I also encountered the same issue as you. After investigating the problem, I found that it was related to the version of PyAV. The recently downloaded version via "pip install pyav" has become 12.0.0. To resolve the above issue, you can execute pip install pyav==11.4.1.

I hope this can help you.

@continue-revolution
Copy link
Owner

@zappityzap

@zappityzap
Copy link
Collaborator

You seem to have a version of ffmpeg that was compiled without libx264. Unfortunately I don't have a Windows computer to try reproducing the problem.

The official python module for PyAV is called "av", and "pyav" is a fork. I suggest looking at the list of modules in your venv and removing pyav if it is installed. You can then either pip install av, or let the extension install it for you.

@continue-revolution
Copy link
Owner

I would consider this issue as resolved. If problem still exists, tag zappityzap.

@vicktorhu
Copy link
Author

I also encountered the same issue as you. After investigating the problem, I found that it was related to the version of PyAV. The recently downloaded version via "pip install pyav" has become 12.0.0. To resolve the above issue, you can execute pip install pyav==11.4.1.

I hope this can help you.

It works wonderfully. Thanks @nilnoun @zappityzap @continue-revolution.

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

5 participants