import cv2
import os
import shutil

video_file = r"C:\Users\Certes\Desktop\guitar_score\output\サカナクション／新宝島(エレキギターTAB) 難易度★★★ sakanaction shintakarajima.mp4"
debug_dir = r"C:\Users\Certes\Desktop\guitar_score\output\debug_video1"

if os.path.exists(debug_dir):
    shutil.rmtree(debug_dir)
os.makedirs(debug_dir)

cap = cv2.VideoCapture(video_file)
fps_orig = cap.get(cv2.CAP_PROP_FPS)
target_fps = 1
frame_skip = int(fps_orig / target_fps)

count = 0
saved = 0
last_frame = None

while True:
    ret, frame = cap.read()
    if not ret: break
    
    if count % (fps_orig * 10) == 0:
        frame = cv2.resize(frame, (1280, 720))
        cv2.imwrite(os.path.join(debug_dir, f"frame_{count:05d}.jpg"), frame)
        saved += 1
        if saved > 30:
            break
                
    count += 1

cap.release()
print(f"Extraction complete. {saved} frames saved.")
