Update main.py
Browse files
main.py
CHANGED
|
@@ -25,6 +25,54 @@ import multiprocessing
|
|
| 25 |
from shapely.geometry import Polygon
|
| 26 |
import time
|
| 27 |
from tqdm import tqdm
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
|
| 30 |
class SubtitleDetect:
|
|
|
|
| 25 |
from shapely.geometry import Polygon
|
| 26 |
import time
|
| 27 |
from tqdm import tqdm
|
| 28 |
+
import os
|
| 29 |
+
import cv2
|
| 30 |
+
import numpy as np
|
| 31 |
+
import urllib.request
|
| 32 |
+
|
| 33 |
+
# 模型路径配置
|
| 34 |
+
LAMA_MODEL_PATH = "./models/big-lama"
|
| 35 |
+
MODEL_FILE = os.path.join(LAMA_MODEL_PATH, "big-lama.pt")
|
| 36 |
+
|
| 37 |
+
# 自动下载模型(如果缺失)
|
| 38 |
+
os.makedirs(LAMA_MODEL_PATH, exist_ok=True)
|
| 39 |
+
if not os.path.exists(MODEL_FILE):
|
| 40 |
+
print("🔄 正在下载 big-lama 模型...")
|
| 41 |
+
urllib.request.urlretrieve(
|
| 42 |
+
"https://huggingface.co/your-username/your-model-repo/resolve/main/big-lama.pt",
|
| 43 |
+
MODEL_FILE
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
def process_video(input_video_path, output_video_path):
|
| 47 |
+
cap = cv2.VideoCapture(input_video_path)
|
| 48 |
+
fps = cap.get(cv2.CAP_PROP_FPS)
|
| 49 |
+
w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
| 50 |
+
h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
| 51 |
+
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
|
| 52 |
+
out = cv2.VideoWriter(output_video_path, fourcc, fps, (w, h))
|
| 53 |
+
|
| 54 |
+
while True:
|
| 55 |
+
ret, frame = cap.read()
|
| 56 |
+
if not ret:
|
| 57 |
+
break
|
| 58 |
+
# 简化处理:直接模糊底部区域模拟去字幕
|
| 59 |
+
y1 = int(h * 0.85)
|
| 60 |
+
y2 = h
|
| 61 |
+
frame[y1:y2, :] = cv2.GaussianBlur(frame[y1:y2, :], (21, 21), 0)
|
| 62 |
+
out.write(frame)
|
| 63 |
+
|
| 64 |
+
cap.release()
|
| 65 |
+
out.release()
|
| 66 |
+
print("✅ 视频处理完成")
|
| 67 |
+
|
| 68 |
+
if __name__ == "__main__":
|
| 69 |
+
import argparse
|
| 70 |
+
parser = argparse.ArgumentParser()
|
| 71 |
+
parser.add_argument("--input_video", type=str, required=True)
|
| 72 |
+
parser.add_argument("--output_video", type=str, required=True)
|
| 73 |
+
args = parser.parse_args()
|
| 74 |
+
process_video(args.input_video, args.output_video)
|
| 75 |
+
|
| 76 |
|
| 77 |
|
| 78 |
class SubtitleDetect:
|