|
14 | 14 | from auto_editor.ffwrapper import FileInfo, initFileInfo
|
15 | 15 | from auto_editor.lib.contracts import is_int, is_str
|
16 | 16 | from auto_editor.make_layers import clipify, make_av, make_timeline
|
17 |
| -from auto_editor.output import Ensure, parse_bitrate |
18 | 17 | from auto_editor.render.audio import make_new_audio
|
19 | 18 | from auto_editor.render.subtitle import make_new_subtitles
|
20 | 19 | from auto_editor.render.video import render_av
|
@@ -303,51 +302,30 @@ def make_media(tl: v3, output_path: str) -> None:
|
303 | 302 | output_stream, vframes = None, iter([])
|
304 | 303 |
|
305 | 304 | # 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) |
325 | 313 |
|
326 | 314 | 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}") |
338 | 315 |
|
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)") |
346 | 321 |
|
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([])] |
351 | 329 |
|
352 | 330 | # Setup subtitles
|
353 | 331 | if ctr.default_sub != "none" and not args.sn:
|
@@ -511,8 +489,6 @@ def __eq__(self, other):
|
511 | 489 | bar.end()
|
512 | 490 |
|
513 | 491 | # Close resources
|
514 |
| - for audio_input in audio_inputs: |
515 |
| - audio_input.close() |
516 | 492 | for subtitle_input in subtitle_inputs:
|
517 | 493 | subtitle_input.close()
|
518 | 494 | output.close()
|
|
0 commit comments