pip install tqdm pip install opencv_python import os import cv2 import shutil from tqdm import tqdm from tkinter import Tk, filedialog, simpledialog def is_black_region(frame, x, y, width, height, threshold=10): region = frame[y:y+height, x:x+width] retur

pip install tqdm

pip install opencv_python

import os
import cv2
import shutil
from tqdm import tqdm
from tkinter import Tk, filedialog, simpledialog

def is_black_region(frame, x, y, width, height, threshold=10):
    region = frame[y:y+height, x:x+width]
    return cv2.countNonZero(cv2.cvtColor(region, cv2.COLOR_BGR2GRAY)) <= threshold

def move_black_videos(input_directory, output_directory, x, y, width, height, threshold=10):
    os.makedirs(output_directory, exist_ok=True)

    video_files = [f for f in os.listdir(input_directory) if f.endswith(('.mp4', '.avi', '.mkv', '.mov', '.flv'))]

    for filename in tqdm(video_files, desc="Processing videos", unit="video"):
        file_path = os.path.join(input_directory, filename)

        cap = cv2.VideoCapture(file_path)
        ret, frame = cap.read()
        cap.release()

        if ret and is_black_region(frame, x, y, width, height, threshold):
            shutil.move(file_path, os.path.join(output_directory, filename))

if __name__ == "__main__":
    # 弹窗获取输入目录
    root = Tk()
    root.withdraw()  # 隐藏Tk窗口
    source_directory = filedialog.askdirectory(title="Select Source Directory")

    # 弹窗获取输出目录
    output_directory = filedialog.askdirectory(title="Select Output Directory")

    # 弹窗获取坐标和尺寸
    region_x = simpledialog.askinteger("Input", "Enter X coordinate", initialvalue=50)
    region_y = simpledialog.askinteger("Input", "Enter Y coordinate", initialvalue=50)
    region_width = simpledialog.askinteger("Input", "Enter Width", initialvalue=100)
    region_height = simpledialog.askinteger("Input", "Enter Height", initialvalue=100)

    move_black_videos(source_directory, output_directory, region_x, region_y, region_width, region_height)