File size: 654 Bytes
d336c38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import datetime
import uuid

import supervision as sv


MAX_VIDEO_LENGTH_SEC = 3


def generate_file_name(extension="mp4"):
    current_datetime = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
    unique_id = uuid.uuid4()
    return f"{current_datetime}_{unique_id}.{extension}"


def calculate_end_frame_index(source_video_path: str) -> int:
    video_info = sv.VideoInfo.from_video_path(source_video_path)
    return min(
        video_info.total_frames,
        video_info.fps * MAX_VIDEO_LENGTH_SEC
    )


def create_directory(directory_path: str) -> None:
    if not os.path.exists(directory_path):
        os.makedirs(directory_path)