forked from keplerlab/katna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_video_smart_resize.py
80 lines (57 loc) · 2.26 KB
/
example_video_smart_resize.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import os
import os.path
import cv2
from Katna.video import Video
import multiprocessing
import Katna.config as app_config
# change these paths
# usually autoflip build is located here : /mediapipe/repo/bazel-build/mediapipe/examples/desktop/autoflip
# usually mediapipe model is located here : /mediapipe/repo/mediapipe/models
autoflip_build_path = "/path/to/autoflip/build"
autoflip_model_path = "/path/to/mediapipe/models"
# output aspect ratio
aspect_ratio = "9:16"
# get the current configuration
conf = app_config.MediaPipe.AutoFlip.get_conf()
# set True for features which are required in output
conf["ENFORCE_FEATURES"] = {
"FACE_CORE_LANDMARKS": False,
"FACE_ALL_LANDMARKS": False,
"FACE_FULL": False,
"HUMAN": False,
"PET": False,
"CAR": False,
"OBJECT": False
}
# % stabalization threshold
conf["STABALIZATION_THRESHOLD"] = 0.5
# opacity of blur area
conf["BLUR_AREA_OPACITY"] = 0.6
def main_folder():
dir_path = file_path = os.path.join(".", "tests", "data")
# will create a resize_result dir inside data folder and dump videos there
abs_dir_path_output = os.path.join(".", "tests", "data", "resize_results")
vd = Video(autoflip_build_path, autoflip_model_path)
# update configuration
app_config.MediaPipe.AutoFlip.set_conf(conf)
try:
vd.resize_video_from_dir(dir_path = dir_path, abs_dir_path_output = abs_dir_path_output, aspect_ratio = aspect_ratio)
except Exception as e:
raise e
print(f"output resized video dir path = {abs_dir_path_output}")
def main_single_video():
# resize the pos_video.mp4 in same directory with na,e pos_video_resize.mp4
abs_file_path_output = os.path.join(".", "tests", "data", "pos_video_resize.mp4")
file_path = os.path.join(".", "tests", "data", "pos_video.mp4")
vd = Video(autoflip_build_path, autoflip_model_path)
# update configuration
app_config.MediaPipe.AutoFlip.set_conf(conf)
try:
vd.resize_video(file_path = file_path, abs_file_path_output = abs_file_path_output, aspect_ratio = aspect_ratio)
except Exception as e:
raise e
print(f"output resized video file path = {abs_file_path_output}")
if __name__ == "__main__":
main_single_video()
# uncomment this to run on a folder
# main_folder()