feat: destructive audio op command builders (delete/silence/reverse region)

This commit is contained in:
2026-07-02 17:54:11 +02:00
parent 68368b4ff6
commit 1553d7faf0
2 changed files with 79 additions and 1 deletions
+40 -1
View File
@@ -1,6 +1,6 @@
import tempfile, os, json
from main import build_export_path, format_time, build_ffmpeg_command, build_sequence_dir, build_audio_extract_command, resolve_keyframe, apply_keyframes_to_jobs
from core.ffmpeg import build_audio_clip_command, build_crossfade_merge_command
from core.ffmpeg import build_audio_clip_command, build_crossfade_merge_command, build_audio_delete_command, build_audio_silence_command, build_audio_reverse_command
from core.annotations import build_annotation_json_path, upsert_clip_annotation
from main import ProcessedDB
@@ -192,6 +192,45 @@ def test_merge_three_clips_zero_concat_chain():
assert "acrossfade" not in fc
# --- destructive audio region ops (delete/silence/reverse) ---
def test_audio_delete_command():
cmd = build_audio_delete_command("/in.wav", 1.0, 3.0, "/o/o.wav")
assert cmd[0] == "ffmpeg"
assert cmd.count("-i") == 1
fc = cmd[cmd.index("-filter_complex") + 1]
assert "atrim=end=1.0" in fc # keep [0,1]
assert "atrim=start=3.0" in fc # keep [3,end]
assert "concat=n=2:v=0:a=1[out]" in fc
assert cmd[cmd.index("-map") + 1] == "[out]"
assert "pcm_s16le" in cmd # codec by ext
assert cmd[-1] == "/o/o.wav"
def test_audio_silence_command():
cmd = build_audio_silence_command("/in.wav", 1.0, 3.0, "/o/o.mp3")
af = cmd[cmd.index("-af") + 1]
# volume=0 gated to the region; commas inside between() are escaped for the filtergraph
assert af == "volume=0:enable='between(t\\,1.0\\,3.0)'"
assert "libmp3lame" in cmd
assert cmd[-1] == "/o/o.mp3"
def test_audio_reverse_command():
cmd = build_audio_reverse_command("/in.wav", 1.0, 3.0, "/o/o.wav")
fc = cmd[cmd.index("-filter_complex") + 1]
assert "atrim=end=1.0" in fc # head [0,1]
assert "atrim=start=1.0:end=3.0" in fc # middle [1,3]
assert "areverse" in fc # reversed middle
assert "atrim=start=3.0" in fc # tail [3,end]
assert "concat=n=3:v=0:a=1[out]" in fc
assert cmd[cmd.index("-map") + 1] == "[out]"
def test_audio_delete_empty_head():
# deleting from 0 still produces a valid 2-branch concat (head is empty but harmless)
cmd = build_audio_delete_command("/in.wav", 0.0, 2.0, "/o/o.wav")
fc = cmd[cmd.index("-filter_complex") + 1]
assert "atrim=end=0.0" in fc and "atrim=start=2.0" in fc
# --- ProcessedDB ---
def test_db_add_and_get_markers():