File size: 766 Bytes
e826484
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# utils/__init__.py
# ํŒจํ‚ค์ง€ ์ดˆ๊ธฐํ™” ํŒŒ์ผ

def extract_frames(video_path, max_frames=10, skip=10):
    """
    ๋™์˜์ƒ์—์„œ ํ”„๋ ˆ์ž„ ์ถ”์ถœ 
    
    Args:
        video_path: ๋™์˜์ƒ ํŒŒ์ผ ๊ฒฝ๋กœ
        max_frames: ์ถ”์ถœํ•  ์ตœ๋Œ€ ํ”„๋ ˆ์ž„ ์ˆ˜
        skip: ๊ฑด๋„ˆ๋›ธ ํ”„๋ ˆ์ž„ ์ˆ˜
        
    Returns:
        ์ถ”์ถœ๋œ ํ”„๋ ˆ์ž„ ๋ฆฌ์ŠคํŠธ
    """
    import cv2
    
    cap = cv2.VideoCapture(video_path)
    frames = []
    count = 0
    while cap.isOpened() and len(frames) < max_frames:
        ret, frame = cap.read()
        if not ret:
            break
        if count % skip == 0:
            frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
            frames.append(frame_rgb)
        count += 1
    cap.release()
    return frames