🧹 Remove WiLoR technical chunk artifacts

This commit is contained in:
eust-w 2026-08-28 12:14:54 +08:00
parent ca4ccf850d
commit 807419fcd6
3 changed files with 68 additions and 36 deletions

View File

@ -468,24 +468,27 @@ def _concat_annotated_videos(paths: list[pathlib.Path], destination: pathlib.Pat
"copy",
str(destination),
]
completed = subprocess.run(copy_command, capture_output=True, text=True, check=False)
if completed.returncode == 0 and destination.is_file() and destination.stat().st_size > 0:
return
reencode_command = copy_command[:-3] + [
"-c:v",
"libx264",
"-preset",
"veryfast",
"-crf",
"23",
"-pix_fmt",
"yuv420p",
str(destination),
]
completed = subprocess.run(reencode_command, capture_output=True, text=True, check=False)
if completed.returncode != 0 or not destination.is_file() or destination.stat().st_size <= 0:
detail = completed.stderr.strip() or completed.stdout.strip()
raise RuntimeError(f"failed to merge WiLoR annotated video chunks: {detail[:800]}")
try:
completed = subprocess.run(copy_command, capture_output=True, text=True, check=False)
if completed.returncode == 0 and destination.is_file() and destination.stat().st_size > 0:
return
reencode_command = copy_command[:-3] + [
"-c:v",
"libx264",
"-preset",
"veryfast",
"-crf",
"23",
"-pix_fmt",
"yuv420p",
str(destination),
]
completed = subprocess.run(reencode_command, capture_output=True, text=True, check=False)
if completed.returncode != 0 or not destination.is_file() or destination.stat().st_size <= 0:
detail = completed.stderr.strip() or completed.stdout.strip()
raise RuntimeError(f"failed to merge WiLoR annotated video chunks: {detail[:800]}")
finally:
concat_list.unlink(missing_ok=True)
def _run_video_chunks(
@ -593,6 +596,7 @@ def _run_video_chunks(
downloaded.append(
{"path": str(annotated_path), "name": annotated_path.name, "sizeBytes": annotated_path.stat().st_size}
)
shutil.rmtree(chunk_root)
return aggregate, downloaded
@ -794,4 +798,5 @@ def run(
output=binding,
)
)
shutil.rmtree(input_dir)
return artifacts

View File

@ -468,24 +468,27 @@ def _concat_annotated_videos(paths: list[pathlib.Path], destination: pathlib.Pat
"copy",
str(destination),
]
completed = subprocess.run(copy_command, capture_output=True, text=True, check=False)
if completed.returncode == 0 and destination.is_file() and destination.stat().st_size > 0:
return
reencode_command = copy_command[:-3] + [
"-c:v",
"libx264",
"-preset",
"veryfast",
"-crf",
"23",
"-pix_fmt",
"yuv420p",
str(destination),
]
completed = subprocess.run(reencode_command, capture_output=True, text=True, check=False)
if completed.returncode != 0 or not destination.is_file() or destination.stat().st_size <= 0:
detail = completed.stderr.strip() or completed.stdout.strip()
raise RuntimeError(f"failed to merge WiLoR annotated video chunks: {detail[:800]}")
try:
completed = subprocess.run(copy_command, capture_output=True, text=True, check=False)
if completed.returncode == 0 and destination.is_file() and destination.stat().st_size > 0:
return
reencode_command = copy_command[:-3] + [
"-c:v",
"libx264",
"-preset",
"veryfast",
"-crf",
"23",
"-pix_fmt",
"yuv420p",
str(destination),
]
completed = subprocess.run(reencode_command, capture_output=True, text=True, check=False)
if completed.returncode != 0 or not destination.is_file() or destination.stat().st_size <= 0:
detail = completed.stderr.strip() or completed.stdout.strip()
raise RuntimeError(f"failed to merge WiLoR annotated video chunks: {detail[:800]}")
finally:
concat_list.unlink(missing_ok=True)
def _run_video_chunks(
@ -593,6 +596,7 @@ def _run_video_chunks(
downloaded.append(
{"path": str(annotated_path), "name": annotated_path.name, "sizeBytes": annotated_path.stat().st_size}
)
shutil.rmtree(chunk_root)
return aggregate, downloaded
@ -794,4 +798,5 @@ def run(
output=binding,
)
)
shutil.rmtree(input_dir)
return artifacts

View File

@ -2,6 +2,7 @@ import hashlib
import json
import pathlib
import shutil
from types import SimpleNamespace
import pytest
@ -167,6 +168,27 @@ def test_wilor_materializes_bos_video_before_service_upload(tmp_path):
assert result == str(local_video)
def test_wilor_concat_list_is_technical_and_removed_after_success(tmp_path, monkeypatch):
source = tmp_path / "annotated-chunk.mp4"
source.write_bytes(b"chunk")
destination = tmp_path / "outputs" / "wilor-annotated-video.mp4"
def fake_run(command, **kwargs):
pathlib.Path(command[-1]).write_bytes(b"merged-video")
return SimpleNamespace(returncode=0, stdout="", stderr="")
monkeypatch.setattr(wilor.subprocess, "run", fake_run)
wilor._concat_annotated_videos([source], destination)
assert destination.read_bytes() == b"merged-video"
assert not (destination.parent / "_annotated-chunks.txt").exists()
def test_wilor_full_video_success_path_removes_private_input_and_chunk_directories():
source = pathlib.Path("backend/operators/builtin/wilor_hand_pose/operator.py").read_text(encoding="utf-8")
assert "shutil.rmtree(chunk_root)" in source
assert "shutil.rmtree(input_dir)" in source
def test_headpose_service_skips_empty_sampled_frames_but_keeps_video_fail_closed():
source = pathlib.Path("services/headpose/app.py").read_text(encoding="utf-8")
assert 'if str(error) != "no face detected in sampled frame"' in source