feat: extract honors format picker + fade/normalize/gain edits

This commit is contained in:
2026-07-02 14:47:49 +02:00
parent c9a4ac584f
commit 8e03b97742
2 changed files with 85 additions and 5 deletions
+21 -5
View File
@@ -37,7 +37,7 @@ from core.paths import _bin, _log, build_export_path, build_sequence_dir, format
from core.ffmpeg import (
_RATIOS, resolve_keyframe, apply_keyframes_to_jobs,
build_ffmpeg_command, build_audio_extract_command, build_audio_clip_command,
probe_duration, detect_hw_encoders,
audio_edit_filters, probe_duration, detect_hw_encoders,
)
from core.db import ProcessedDB
from core.annotations import remove_clip_annotation, upsert_clip_annotation
@@ -6471,23 +6471,39 @@ class MainWindow(QMainWindow):
return
start = self._cursor
dur = self._spn_audio_len.value()
ext = self._cmb_audio_fmt.currentData() or ".wav"
fmt_label = self._cmb_audio_fmt.currentText()
# No clamping: pass the requested length straight to ffmpeg. It stops
# cleanly at end-of-file if the source is shorter, and we report the
# actual length afterwards so any truncation is visible, not silent.
stem = os.path.splitext(os.path.basename(self._file_path))[0]
default_name = f"{stem}_{start:.2f}-{start + dur:.2f}s.wav"
default_name = f"{stem}_{start:.2f}-{start + dur:.2f}s{ext}"
default_dir = (self._settings.value("audio_extract_dir", "")
or self._tab_export_folder()
or os.path.dirname(self._file_path))
# Build the save filter from the combo so it stays in sync and the
# chosen format leads (stable sort keeps the rest in combo order).
_fmts = [(self._cmb_audio_fmt.itemText(i), self._cmb_audio_fmt.itemData(i))
for i in range(self._cmb_audio_fmt.count())]
_fmts.sort(key=lambda it: it[1] != ext)
save_filter = ";;".join([f"{lbl} (*{e})" for lbl, e in _fmts]
+ ["All files (*)"])
path, _sel = QFileDialog.getSaveFileName(
self, "Save audio clip", os.path.join(default_dir, default_name),
"WAV (*.wav);;MP3 (*.mp3);;FLAC (*.flac);;All files (*)")
save_filter)
if not path:
return
if not os.path.splitext(path)[1]:
path += ".wav"
path += ext
os.makedirs(os.path.dirname(path) or ".", exist_ok=True)
cmd = build_audio_clip_command(self._file_path, start, dur, path)
edit_filters = audio_edit_filters(
duration=dur,
fade_in=self._spn_fade_in.value(),
fade_out=self._spn_fade_out.value(),
normalize=self._chk_normalize.isChecked(),
gain_db=self._spn_gain.value())
cmd = build_audio_clip_command(self._file_path, start, dur, path,
filters=edit_filters or None)
self._btn_extract_audio.setEnabled(False)
QApplication.setOverrideCursor(Qt.CursorShape.WaitCursor)
self._show_status(f"Extracting {dur:.2f}s of audio…")