Tolerate fps difference of 5 for usage of original fps. This is because YouTube videos are commonly with 25 FPS and we're trying to work with 30 FPS
Browse files- app.py +2 -1
- video_utils.py +3 -2
app.py
CHANGED
@@ -57,9 +57,10 @@ def parse_video_to_clips(video_file):
|
|
57 |
"""A utility to parse the input videos """
|
58 |
new_resolution = (320, 256)
|
59 |
new_fps = 30
|
|
|
60 |
with tempfile.NamedTemporaryFile() as new_video:
|
61 |
print(new_video.name)
|
62 |
-
change_video_resolution_and_fps(video_file, new_video.name, new_resolution, new_fps)
|
63 |
video_path_handler = VideoPathHandler()
|
64 |
video: EncodedVideoPyAV = video_path_handler.video_from_path(video_file)
|
65 |
|
|
|
57 |
"""A utility to parse the input videos """
|
58 |
new_resolution = (320, 256)
|
59 |
new_fps = 30
|
60 |
+
acceptable_fps_violation = 5
|
61 |
with tempfile.NamedTemporaryFile() as new_video:
|
62 |
print(new_video.name)
|
63 |
+
change_video_resolution_and_fps(video_file, new_video.name, new_resolution, new_fps, acceptable_fps_violation)
|
64 |
video_path_handler = VideoPathHandler()
|
65 |
video: EncodedVideoPyAV = video_path_handler.video_from_path(video_file)
|
66 |
|
video_utils.py
CHANGED
@@ -6,7 +6,8 @@ import cv2
|
|
6 |
|
7 |
def change_video_resolution_and_fps(video_path: str, output_path: str,
|
8 |
new_resolution: Optional[Tuple[int, int]] = None,
|
9 |
-
new_fps: Optional[int] = None
|
|
|
10 |
cap = cv2.VideoCapture(video_path)
|
11 |
|
12 |
try:
|
@@ -16,7 +17,7 @@ def change_video_resolution_and_fps(video_path: str, output_path: str,
|
|
16 |
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
17 |
# Specify the new_resolution and new_fps for the cut video
|
18 |
new_resolution = new_resolution if new_resolution else resolution
|
19 |
-
new_fps =
|
20 |
fps_decrease_factor = fps / new_fps
|
21 |
if not fps_decrease_factor.is_integer():
|
22 |
raise ValueError(f"New fps ({new_fps}) must be a divisor of the current fps ({fps})")
|
|
|
6 |
|
7 |
def change_video_resolution_and_fps(video_path: str, output_path: str,
|
8 |
new_resolution: Optional[Tuple[int, int]] = None,
|
9 |
+
new_fps: Optional[int] = None,
|
10 |
+
acceptable_fps_violation: int = 0) -> bool:
|
11 |
cap = cv2.VideoCapture(video_path)
|
12 |
|
13 |
try:
|
|
|
17 |
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
18 |
# Specify the new_resolution and new_fps for the cut video
|
19 |
new_resolution = new_resolution if new_resolution else resolution
|
20 |
+
new_fps = fps if ((not new_fps) or (abs(new_fps - fps) <= acceptable_fps_violation)) else new_fps
|
21 |
fps_decrease_factor = fps / new_fps
|
22 |
if not fps_decrease_factor.is_integer():
|
23 |
raise ValueError(f"New fps ({new_fps}) must be a divisor of the current fps ({fps})")
|