File size: 678 Bytes
86756d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
This module contains methods for video processing
"""
import os
import cv2

def generate_frames(video_path, frames_path, rate, show_print = True):
    # Create a new temporary folder
    if not os.path.exists(frames_path):
        os.makedirs(frames_path)
    # Capture video
    src_vid = cv2.VideoCapture(video_path)
    index = 0
    while src_vid.isOpened():
        ret, frame = src_vid.read()
        if not ret:
            break
        name = frames_path + "/" + str(index) + ".png"
        if index % rate == 0:
            if show_print:
                print("Frame: " + name)
            cv2.imwrite(name, frame)
        index = index + 1
    src_vid.release()