diff --git a/web.py b/web.py index 73b7947..9b8db92 100644 --- a/web.py +++ b/web.py @@ -497,12 +497,19 @@ class _Handler(BaseHTTPRequestHandler): ext = path.suffix.lower() out_name = f'{path.stem}_cut_{int(start)}s-{int(end)}s{ext}' + # For lossless formats, re-encode (not copy) so the container header + # is rewritten with the correct duration/size. For lossy formats, + # copy is fine — the audio stops at the right frame regardless. + _lossless = {'.wav': ['-c:a', 'pcm_s16le'], '.flac': ['-c:a', 'flac']} + codec_args = _lossless.get(ext, ['-c', 'copy']) + fd, tmp_path = tempfile.mkstemp(suffix=ext) os.close(fd) try: - cmd = ['ffmpeg', '-y', '-i', str(path), + cmd = ['ffmpeg', '-y', + '-i', str(path), '-ss', str(start), '-to', str(end), - '-c', 'copy', tmp_path] + '-vn'] + codec_args + [tmp_path] result = subprocess.run(cmd, capture_output=True, timeout=120) if result.returncode != 0: err = result.stderr.decode('utf-8', errors='replace')[-400:] @@ -663,6 +670,7 @@ button.cut:hover:not(:disabled){background:#1e3a8a} +

ISR Archive

@@ -675,6 +683,10 @@ button.cut:hover:not(:disabled){background:#1e3a8a} RMS 0–1 · sections above this value are marked loud + + + seconds to rewind before section start