A community-maintained Python framework for creating mathematical animations.
Changed what the gain argument of Scene.play means to instead actually apply gain to the passed in sound, not the background
Grant Sanderson7a5c4192975d
diff --git a/manimlib/scene/scene.py b/manimlib/scene/scene.pyindex d7977a5a9..1f7f9bc18 100644--- a/manimlib/scene/scene.py+++ b/manimlib/scene/scene.py@@ -572,9 +572,9 @@ class Scene(Container):for frame in frames:self.file_writer.write_frame(frame)- def add_sound(self, sound_file, time_offset=0, gain=0):+ def add_sound(self, sound_file, time_offset=0, gain=None, **kwargs):time = self.get_time() + time_offset- self.file_writer.add_sound(sound_file, time, gain)+ self.file_writer.add_sound(sound_file, time, gain, **kwargs)def show_frame(self):self.update_frame(ignore_skipping=True)diff --git a/manimlib/scene/scene_file_writer.py b/manimlib/scene/scene_file_writer.pyindex 9ca5664f8..cd098afcf 100644--- a/manimlib/scene/scene_file_writer.py+++ b/manimlib/scene/scene_file_writer.py@@ -119,7 +119,9 @@ class SceneFileWriter(object):def create_audio_segment(self):self.audio_segment = AudioSegment.silent()- def add_audio_segment(self, new_segment, time=None, gain=0):+ def add_audio_segment(self, new_segment,+ time=None,+ gain_to_background=None):if not self.includes_sound:self.includes_sound = Trueself.create_audio_segment()@@ -140,13 +142,15 @@ class SceneFileWriter(object):self.audio_segment = segment.overlay(new_segment,position=int(1000 * time),- gain_during_overlay=gain,+ gain_during_overlay=gain_to_background,)- def add_sound(self, sound_file, time, gain=0):+ def add_sound(self, sound_file, time=None, gain=None, **kwargs):file_path = get_full_sound_file_path(sound_file)new_segment = AudioSegment.from_file(file_path)- self.add_audio_segment(new_segment, time, gain)+ if gain:+ new_segment = new_segment.apply_gain(gain)+ self.add_audio_segment(new_segment, time, **kwargs)# Writersdef begin_animation(self, allow_write=False):@@ -307,17 +311,25 @@ class SceneFileWriter(object):)# Makes sure sound file length will match video fileself.add_audio_segment(AudioSegment.silent(0))- self.audio_segment.export(sound_file_path)+ self.audio_segment.export(+ sound_file_path,+ bitrate='312k',+ )temp_file_path = movie_file_path.replace(".", "_temp.")- commands = commands = [+ commands = ["ffmpeg","-i", movie_file_path,"-i", sound_file_path,'-y', # overwrite output file if it exists- "-c:v", "copy", "-c:a", "aac",+ "-c:v", "copy",+ "-c:a", "aac",+ "-b:a", "320k",+ # select video stream from first file+ "-map", "0:v:0",+ # select audio stream from second file+ "-map", "1:a:0",'-loglevel', 'error',- "-shortest",- "-strict", "experimental",+ # "-shortest",temp_file_path,]subprocess.call(commands)