2026-05-18-19-41-29 修复样例视频浏览器显示

This commit is contained in:
2026-05-18 19:43:25 +08:00
parent 72d0e9a168
commit f89ce5f5f6
7 changed files with 133 additions and 1 deletions

View File

@@ -1,6 +1,8 @@
from __future__ import annotations
from pathlib import Path
import shutil
import subprocess
import cv2
import numpy as np
@@ -44,15 +46,45 @@ def make_frame(index: int, width: int = 640, height: int = 420) -> np.ndarray:
def main() -> None:
SAMPLE_DIR.mkdir(parents=True, exist_ok=True)
video_path = SAMPLE_DIR / "synthetic_guidewire.mp4"
raw_video_path = SAMPLE_DIR / "synthetic_guidewire.raw.mp4"
image_path = SAMPLE_DIR / "synthetic_guidewire.png"
width, height = 640, 420
writer = cv2.VideoWriter(str(video_path), cv2.VideoWriter_fourcc(*"mp4v"), 12.0, (width, height))
writer = cv2.VideoWriter(str(raw_video_path), cv2.VideoWriter_fourcc(*"mp4v"), 12.0, (width, height))
for index in range(72):
frame = make_frame(index, width, height)
if index == 12:
cv2.imwrite(str(image_path), frame)
writer.write(frame)
writer.release()
ffmpeg = shutil.which("ffmpeg")
if ffmpeg:
subprocess.run(
[
ffmpeg,
"-y",
"-i",
str(raw_video_path),
"-c:v",
"libx264",
"-pix_fmt",
"yuv420p",
"-movflags",
"+faststart",
"-preset",
"veryfast",
"-crf",
"20",
str(video_path),
],
check=True,
capture_output=True,
text=True,
)
raw_video_path.unlink(missing_ok=True)
else:
raw_video_path.replace(video_path)
print(video_path)
print(image_path)