Skip to content

Commit 7eac5dd

Browse files
authored
Avoid creating temp audio files
1 parent 7bb5a82 commit 7eac5dd

File tree

7 files changed

+199
-516
lines changed

7 files changed

+199
-516
lines changed

Diff for: auto_editor/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "27.0.0"
1+
__version__ = "27.0.1"

Diff for: auto_editor/edit.py

+20-44
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from auto_editor.ffwrapper import FileInfo, initFileInfo
1515
from auto_editor.lib.contracts import is_int, is_str
1616
from auto_editor.make_layers import clipify, make_av, make_timeline
17-
from auto_editor.output import Ensure, parse_bitrate
1817
from auto_editor.render.audio import make_new_audio
1918
from auto_editor.render.subtitle import make_new_subtitles
2019
from auto_editor.render.video import render_av
@@ -303,51 +302,30 @@ def make_media(tl: v3, output_path: str) -> None:
303302
output_stream, vframes = None, iter([])
304303

305304
# 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-
316-
if audio_paths:
317-
try:
318-
audio_encoder = bv.Codec(args.audio_codec, "w")
319-
except bv.FFmpegError as e:
320-
log.error(e)
321-
if audio_encoder.audio_formats is None:
322-
log.error(f"{args.audio_codec}: No known audio formats avail.")
323-
audio_format = audio_encoder.audio_formats[0]
324-
resampler = AudioResampler(format=audio_format, layout="stereo", rate=tl.sr)
305+
try:
306+
audio_encoder = bv.Codec(args.audio_codec, "w")
307+
except bv.FFmpegError as e:
308+
log.error(e)
309+
if audio_encoder.audio_formats is None:
310+
log.error(f"{args.audio_codec}: No known audio formats avail.")
311+
fmt = audio_encoder.audio_formats[0]
312+
resampler = AudioResampler(format=fmt, layout="stereo", rate=tl.sr)
325313

326314
audio_streams: list[bv.AudioStream] = []
327-
audio_inputs = []
328-
audio_gen_frames = []
329-
for i, audio_path in enumerate(audio_paths):
330-
audio_stream = output.add_stream(
331-
args.audio_codec,
332-
format=audio_format,
333-
rate=tl.sr,
334-
time_base=Fraction(1, tl.sr),
335-
)
336-
if not isinstance(audio_stream, bv.AudioStream):
337-
log.error(f"Not a known audio codec: {args.audio_codec}")
338315

339-
if args.audio_bitrate != "auto":
340-
audio_stream.bit_rate = parse_bitrate(args.audio_bitrate, log)
341-
log.debug(f"audio bitrate: {audio_stream.bit_rate}")
342-
else:
343-
log.debug(f"[auto] audio bitrate: {audio_stream.bit_rate}")
344-
if i < len(src.audios) and src.audios[i].lang is not None:
345-
audio_stream.metadata["language"] = src.audios[i].lang # type: ignore
316+
if ctr.default_aud == "none":
317+
while len(tl.a) > 0:
318+
tl.a.pop()
319+
elif len(tl.a) > 1 and ctr.max_audios == 1:
320+
log.warning("Dropping extra audio streams (container only allows one)")
346321

347-
audio_streams.append(audio_stream)
348-
audio_input = bv.open(audio_path)
349-
audio_inputs.append(audio_input)
350-
audio_gen_frames.append(audio_input.decode(audio=0))
322+
while len(tl.a) > 1:
323+
tl.a.pop()
324+
325+
if len(tl.a) > 0:
326+
audio_streams, audio_gen_frames = make_new_audio(output, fmt, tl, args, log)
327+
else:
328+
audio_streams, audio_gen_frames = [], [iter([])]
351329

352330
# Setup subtitles
353331
if ctr.default_sub != "none" and not args.sn:
@@ -511,8 +489,6 @@ def __eq__(self, other):
511489
bar.end()
512490

513491
# Close resources
514-
for audio_input in audio_inputs:
515-
audio_input.close()
516492
for subtitle_input in subtitle_inputs:
517493
subtitle_input.close()
518494
output.close()

Diff for: auto_editor/output.py

-86
This file was deleted.

0 commit comments

Comments
 (0)