perf: run waveform ffmpeg at low priority so it yields to mpv on load

The first load of a file decodes the whole audio track in a background
thread; nice'ing it (os.nice(15)) reduces disk/CPU contention with mpv
during the initial open. Result is cached, so subsequent loads are fast.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-06 12:14:04 +02:00
parent 109bc658c3
commit 1d49ce7cee
+6 -1
View File
@@ -1757,7 +1757,12 @@ class WaveformWorker(QThread):
"-vn", "-ac", "1", "-ar", "8000",
"-f", "f32le", "-loglevel", "error", "pipe:1",
]
proc = subprocess.run(cmd, capture_output=True, timeout=60)
# Run at low priority so it yields disk/CPU to mpv during the
# initial load instead of competing for the same file.
kwargs = {}
if sys.platform != "win32":
kwargs["preexec_fn"] = lambda: os.nice(15)
proc = subprocess.run(cmd, capture_output=True, timeout=60, **kwargs)
if proc.returncode != 0:
return
samples = np.frombuffer(proc.stdout, dtype=np.float32)