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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user