Skip to content

Commit

Permalink
Fix audio normalizing for mute clips
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbrockschmidt committed Jan 5, 2021
1 parent 6ab3efb commit abde0d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion moviepy/audio/fx/audio_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ def audio_normalize(clip):
"""

max_volume = clip.max_volume()
return volumex(clip, 1 / max_volume)
if max_volume == 0:
return clip.copy()
else:
return volumex(clip, 1 / max_volume)
9 changes: 9 additions & 0 deletions tests/test_fx.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os

import numpy as np
import pytest

from moviepy.audio.AudioClip import AudioClip
from moviepy.audio.fx.audio_normalize import audio_normalize
from moviepy.audio.io.AudioFileClip import AudioFileClip
from moviepy.utils import close_all_clips
Expand Down Expand Up @@ -456,5 +458,12 @@ def test_normalize():
close_all_clips(locals())


def test_normalize_muted():
make_frame = lambda t: np.array([0.0])
clip = AudioClip(make_frame, duration=1, fps=44100)
clip = audio_normalize(clip)
close_all_clips(locals())


if __name__ == "__main__":
pytest.main()

0 comments on commit abde0d7

Please sign in to comment.