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

Patch #564

Merged
merged 2 commits into from
Oct 18, 2024
Merged

Patch #564

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion auto_editor/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def download_video(my_input: str, args: Args, ffmpeg: FFmpeg, log: Log) -> str:
log.conwrite("Downloading video...")

def get_domain(url: str) -> str:
t = __import__("urllib").parse.urlparse(url).netloc
t = __import__("urllib.parse", fromlist=["parse"]).urlparse(url).netloc
return ".".join(t.split(".")[-2:])

download_format = args.download_format
Expand Down
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