7def crop_clip(input_video_path, output_video_path, crop_area, time_interval=[0, -1], interver_type='time'):
9 동영상에서 특정 영역및 시간 범위를 잘라서 저장하는 기능
11 input_video_path (str): 입력 동영상 경로
12 output_video_path (str): 동영상을 저장할 경로
13 crop_area (list[int] or tuple) : 동영상에서 잘라낼 영역의 좌상단과 우하단 좌표 (x1, y1, x2, y2)
14 time_interval (list or tuple): 동영상에서 잘라낼 시작 구간과 종료 구간 (시작 구간, 종료 구간)
15 interver_type : time_interval 단위
16 'time' : 초단위, 소수점 입력 가능
17 'frame' : 프레임 단위, 정수로 입력
21 clip = VideoFileClip(input_video_path)
24 start_time, end_time = time_interval
25 if interver_type ==
'frame':
27 start_time = start_time / fps
28 end_time = end_time / fps
31 subclip = clip.subclip(start_time, end_time)
34 cropped_clip = subclip.crop(y1=crop_area[1], y2=crop_area[3], x1=crop_area[0], x2=crop_area[2])
37 cropped_clip.write_videofile(output_video_path, codec=
"libx264")
43def make_video(folder_or_paths, save_path, fps=30, half=True):
45 이미지를 기반으로 동영상을 생성하는 기능
47 folder_or_paths (str or list[str]): 동영상을 만들 이미지가 저장된 폴더 또는 이미지 경로 리스트
48 save_path (str): 동영상을 저장할 경로
49 fps (int): 생성할 동영상의 프레임 속도
50 half (bool): 이미지의 크기를 절반으로 줄여서 저장할지 여부
54 if isinstance(folder_or_paths, str):
55 _, path_list = search_file(folder_or_paths,
'.jpg')
57 path_list = folder_or_paths
60 clip = ImageSequenceClip(path_list, fps=fps)
64 clip = clip.resize(height=int(clip.h/2), width=int(clip.w/2))
67 clip.write_videofile(save_path, codec=
'libx264', bitrate=
'4000k')