Skip to content

Commit 94f22be

Browse files
committed
Deprecate --keep-tracks-separate
1 parent 6fe79a8 commit 94f22be

File tree

4 files changed

+32
-29
lines changed

4 files changed

+32
-29
lines changed

auto_editor/__main__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class Args:
7676
# Audio Rendering
7777
audio_codec: str = "auto"
7878
audio_bitrate: str = "auto"
79+
mix_audio_streams: bool = False
7980
keep_tracks_separate: bool = False
8081
audio_normalize: str = "#f"
8182

@@ -341,10 +342,13 @@ def speed_range(val: str) -> tuple[float, str, str]:
341342
metavar="BITRATE",
342343
help="Set the number of bits per second for audio",
343344
)
345+
parser.add_argument(
346+
"--mix-audio-streams", flag=True, help="Mix all audio streams together into one"
347+
)
344348
parser.add_argument(
345349
"--keep-tracks-separate",
346350
flag=True,
347-
help="Don't mix all audio tracks into one when exporting",
351+
help="Don't mix all audio streams into one when exporting (default)",
348352
)
349353
parser.add_argument(
350354
"--audio-normalize",

auto_editor/cmds/test.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def test_silent_threshold(self):
277277
assert container.duration / av.time_base == 6.552
278278

279279
def test_track(self):
280-
out = self.main(["resources/multi-track.mov"], ["--keep_tracks_seperate"], "te")
280+
out = self.main(["resources/multi-track.mov"], []) + ".mov"
281281
assert len(fileinfo(out).audios) == 2
282282

283283
def test_export_json(self):
@@ -361,30 +361,24 @@ def test_multi_track_edit(self):
361361
["--edit", "audio:stream=1"],
362362
"multi-track_ALTERED.mov",
363363
)
364-
assert len(fileinfo(out).audios) == 1
364+
assert len(fileinfo(out).audios) == 2
365365

366366
def test_concat(self):
367367
out = self.main(["example.mp4"], ["--cut-out", "0,171"], "hmm.mp4")
368368
self.main(["example.mp4", out], ["--debug"])
369369

370370
def test_concat_mux_tracks(self):
371-
out = self.main(
372-
["example.mp4", "resources/multi-track.mov"], [], "concat_mux.mov"
373-
)
371+
inputs = ["example.mp4", "resources/multi-track.mov"]
372+
out = self.main(inputs, ["--mix-audio-streams"], "concat_mux.mov")
374373
assert len(fileinfo(out).audios) == 1
375374

376375
def test_concat_multi_tracks(self):
377376
out = self.main(
378-
["resources/multi-track.mov", "resources/multi-track.mov"],
379-
["--keep-tracks-separate"],
380-
"out.mov",
377+
["resources/multi-track.mov", "resources/multi-track.mov"], [], "out.mov"
381378
)
382379
assert len(fileinfo(out).audios) == 2
383-
out = self.main(
384-
["example.mp4", "resources/multi-track.mov"],
385-
["--keep-tracks-separate"],
386-
"out.mov",
387-
)
380+
inputs = ["example.mp4", "resources/multi-track.mov"]
381+
out = self.main(inputs, [], "out.mov")
388382
assert len(fileinfo(out).audios) == 2
389383

390384
def test_frame_rate(self):

auto_editor/edit.py

+19-14
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ def edit_media(paths: list[str], args: Args, log: Log) -> None:
162162
bar = initBar(args.progress)
163163
tl = None
164164

165+
if args.keep_tracks_separate:
166+
log.deprecated("--keep-tracks-separate is deprecated.")
167+
args.keep_tracks_separate = False
168+
165169
if paths:
166170
path_ext = splitext(paths[0])[1].lower()
167171
if path_ext == ".xml":
@@ -273,9 +277,6 @@ def edit_media(paths: list[str], args: Args, log: Log) -> None:
273277
args.video_codec = set_video_codec(args.video_codec, src, out_ext, ctr, log)
274278
args.audio_codec = set_audio_codec(args.audio_codec, src, out_ext, ctr, log)
275279

276-
if args.keep_tracks_separate and ctr.max_audios == 1:
277-
log.warning(f"'{out_ext}' container doesn't support multiple audio tracks.")
278-
279280
def make_media(tl: v3, output_path: str) -> None:
280281
assert src is not None
281282

@@ -293,17 +294,6 @@ def make_media(tl: v3, output_path: str) -> None:
293294

294295
output = av.open(output_path, "w", container_options=options)
295296

296-
if ctr.default_sub != "none" and not args.sn:
297-
sub_paths = make_new_subtitles(tl, log)
298-
else:
299-
sub_paths = []
300-
301-
if ctr.default_aud != "none":
302-
ensure = Ensure(bar, samplerate, log)
303-
audio_paths = make_new_audio(tl, ctr, ensure, args, bar, log)
304-
else:
305-
audio_paths = []
306-
307297
# Setup video
308298
if ctr.default_vid != "none" and tl.v:
309299
vframes = render_av(output, tl, args, log)
@@ -313,6 +303,16 @@ def make_media(tl: v3, output_path: str) -> None:
313303
output_stream, vframes = None, iter([])
314304

315305
# Setup audio
306+
if ctr.default_aud != "none":
307+
ensure = Ensure(bar, samplerate, log)
308+
audio_paths = make_new_audio(tl, ctr, ensure, args, bar, log)
309+
else:
310+
audio_paths = []
311+
312+
if len(audio_paths) > 1 and ctr.max_audios == 1:
313+
log.warning("Dropping extra audio streams (container only allows one)")
314+
audio_paths = audio_paths[0:1]
315+
316316
if audio_paths:
317317
try:
318318
audio_encoder = av.Codec(args.audio_codec, "w")
@@ -350,6 +350,11 @@ def make_media(tl: v3, output_path: str) -> None:
350350
audio_gen_frames.append(audio_input.decode(audio=0))
351351

352352
# Setup subtitles
353+
if ctr.default_sub != "none" and not args.sn:
354+
sub_paths = make_new_subtitles(tl, log)
355+
else:
356+
sub_paths = []
357+
353358
subtitle_streams = []
354359
subtitle_inputs = []
355360
sub_gen_frames = []

auto_editor/render/audio.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def make_new_audio(
372372
except PermissionError:
373373
pass
374374

375-
if not (args.keep_tracks_separate and ctr.max_audios is None) and len(output) > 1:
375+
if args.mix_audio_streams and len(output) > 1:
376376
new_a_file = f"{Path(temp, 'new_audio.wav')}"
377377
mix_audio_files(sr, output, new_a_file)
378378
return [new_a_file]

0 commit comments

Comments
 (0)