mirror of
https://github.com/3b1b/manim.git
synced 2025-09-19 04:41:56 +00:00
Changed what the gain argument of Scene.play means to instead actually apply gain to the passed in sound, not the background
This commit is contained in:
parent
40273bab1d
commit
7a5c419297
2 changed files with 23 additions and 11 deletions
|
@ -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)
|
||||
|
|
|
@ -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 = True
|
||||
self.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)
|
||||
|
||||
# Writers
|
||||
def begin_animation(self, allow_write=False):
|
||||
|
@ -307,17 +311,25 @@ class SceneFileWriter(object):
|
|||
)
|
||||
# Makes sure sound file length will match video file
|
||||
self.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)
|
||||
|
|
Loading…
Add table
Reference in a new issue