Skip to content

Commit

Permalink
Move mix_audio_tracks out of output.py
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Oct 18, 2024
1 parent fb66961 commit f8caadb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
21 changes: 21 additions & 0 deletions auto_editor/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,27 @@ def make_media(tl: v3, output: str) -> None:
if ctr.default_aud != "none":
ensure = Ensure(bar, samplerate, log)
audio_output = make_new_audio(tl, ensure, args, ffmpeg, bar, log)
atracks = len(audio_output)
if (
not (args.keep_tracks_separate and ctr.max_audios is None)
and atracks > 1
):
# Merge all the audio a_tracks into one.
new_a_file = os.path.join(log.temp, "new_audio.wav")
new_cmd = []
for path in audio_output:
new_cmd.extend(["-i", path])
new_cmd.extend(
[
"-filter_complex",
f"amix=inputs={atracks}:duration=longest",
"-ac",
"2",
new_a_file,
]
)
ffmpeg.run(new_cmd)
audio_output = [new_a_file]

if ctr.default_vid != "none":
if tl.v:
Expand Down
31 changes: 4 additions & 27 deletions auto_editor/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def mux_quality_media(
a_tracks = len(audio_output)
s_tracks = 0 if args.sn else len(sub_output)

cmd = ["-hide_banner", "-y", "-i", f"{src.path}"]
cmd = ["-hide_banner", "-y"]

same_container = src.path.suffix == os.path.splitext(output_path)[1]

Expand All @@ -107,37 +107,14 @@ def mux_quality_media(
else:
v_tracks -= 1

if a_tracks > 0:
if args.keep_tracks_separate and ctr.max_audios is None:
for path in audio_output:
cmd.extend(["-i", path])
else:
# Merge all the audio a_tracks into one.
new_a_file = os.path.join(log.temp, "new_audio.wav")
if a_tracks > 1:
new_cmd = []
for path in audio_output:
new_cmd.extend(["-i", path])
new_cmd.extend(
[
"-filter_complex",
f"amix=inputs={a_tracks}:duration=longest",
"-ac",
"2",
new_a_file,
]
)
ffmpeg.run(new_cmd)
a_tracks = 1
else:
new_a_file = audio_output[0]
cmd.extend(["-i", new_a_file])
for audfile in audio_output:
cmd.extend(["-i", audfile])

for subfile in sub_output:
cmd.extend(["-i", subfile])

for i in range(v_tracks + s_tracks + a_tracks):
cmd.extend(["-map", f"{i+1}:0"])
cmd.extend(["-map", f"{i}:0"])

cmd.extend(["-map_metadata", "0"])

Expand Down
5 changes: 4 additions & 1 deletion auto_editor/subcommands/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,10 @@ def silent_threshold():
)

def track_tests():
return run.main(["resources/multi-track.mov"], ["--keep_tracks_seperate"])
out = run.main(["resources/multi-track.mov"], ["--keep_tracks_seperate"])
assert len(fileinfo(out).audios) == 2

return out

def export_json_tests():
out = run.main(["example.mp4"], ["--export_as_json"])
Expand Down

0 comments on commit f8caadb

Please sign in to comment.