Skip to content
Closed
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
16 changes: 5 additions & 11 deletions src/ffmpeg_normalize/_media_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,14 @@ def run_normalization(self, batch_reference: float | None = None) -> None:
f"Batch mode: Skipping first pass (already completed), using batch reference = {batch_reference:.2f}"
)

# for second pass, create a temp file
temp_dir = mkdtemp()
self.temp_file = os.path.join(temp_dir, f"out.{self.output_ext}")
temp_dir = None

if self.ffmpeg_normalize.replaygain:
_logger.debug(
"ReplayGain mode: Second pass will run with temporary file to get stats."
)
temp_dir = mkdtemp()
self.temp_file = os.path.join(temp_dir, f"out.{self.output_ext}")
self.output_file = self.temp_file

# run the second pass as a whole.
Expand All @@ -322,7 +322,7 @@ def run_normalization(self, batch_reference: float | None = None) -> None:
pass

# remove temp dir; this will remove the temp file as well if it has not been renamed (e.g. for replaygain)
if os.path.exists(temp_dir):
if temp_dir and os.path.exists(temp_dir):
rmtree(temp_dir, ignore_errors=True)

# This will use stats from ebu_pass2 if available (from the main second pass),
Expand Down Expand Up @@ -840,13 +840,7 @@ def _second_pass(self) -> Iterator[float]:
temp_dir = None
temp_file = None

# special case: if output is a null device, write directly to it
if self.output_file == os.devnull:
cmd.append(self.output_file)
else:
temp_dir = mkdtemp()
temp_file = os.path.join(temp_dir, f"out.{self.output_ext}")
cmd.append(temp_file)
cmd.append(self.output_file)

cmd_runner = CommandRunner()
try:
Expand Down