def vid_downsampling(args): encoded_fps = args.fps base_dir = args.base_dir out_dir = args.out_dir make_dirs(out_dir) vid_size = (args.vid_w, args.vid_h) for folder in sorted(listdir(base_dir)): f_dir = join(base_dir, folder) make_dirs(join(out_dir, folder)) for vid_file in sorted(listdir(f_dir)): if 'mp4' in vid_file: vid_out_f_dir = join(out_dir, folder) vid_base_dir = join(f_dir, vid_file) vid = VideoFileClip(vid_base_dir) vid.write_videofile(join(vid_out_f_dir, vid_file), fps=encoded_fps)
def face_landmarks(vid_frame, now_frame): # PIL draw pil_img = Image.fromarray(vid_frame) d = ImageDraw.Draw(pil_img) face_landmarks_list = face_recognition.face_landmarks(vid_frame) img_h = vid_frame.shape[0] img_w = vid_frame.shape[1] # rendering face landmark rec_arr = [] for face_landmarks in face_landmarks_list: min_c = (99999, 99999) max_c = (0, 0) for facial_feature in face_landmarks.keys(): # find coord for bbox min_c, max_c = find_minmax_coord(face_landmarks[facial_feature], min_c, max_c) # draw line d.line(face_landmarks[facial_feature], width=3) shape = [min_c, max_c] rec_arr.append(shape) d.rectangle(shape, outline='green') # choose center rectangle if face_landmarks_list: rec = find_center(rec_arr, img_h, img_w) d.rectangle(rec, outline='blue') # save img dir = make_dirs('/ssd1/Stage_Mix/imgs/scene_effect_change') img_name = join(dir, 'frame_' + str(now_frame) + '.png') pil_img.save(img_name) if face_landmarks_list: return rec else: return None
type=int, help='output video height size') parser.add_argument('--width', default=1920, type=int, help='output video width size') parser.add_argument('--vid_folder', default='보이그룹-안무중', type=str, help='prerpocessed video name') # geneatre Ground Truth video parser.add_argument('--exp_name', default='GT', type=str) parser.add_argument('--label_dir', default='/ssd1/Stage_Mix/Dataset/60fps', type=str) args = parser.parse_args() args.in_dir = join(args.base_dir, args.out_fps + 'fps', args.vid_folder) args.out_dir = join(args.base_dir, args.out_fps + 'fps', args.out_dir, args.exp_name, args.vid_folder) args.label_dir = join(args.label_dir, args.vid_folder, args.vid_folder + '.csv') make_dirs(args.out_dir) print('input directory : ', args.in_dir) print('output directory : ', args.out_dir) vid_preprocess(args)