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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
From 92f1894e6f4c6ef0490d04192efe73d854fbc55f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?K=C4=B1van=C3=A7=20Y=C3=BCksel?=
<83173240+emkademy@users.noreply.github.com>
Date: Wed, 5 Oct 2022 10:30:53 +0200
Subject: [PATCH 1/3] added github workflows for ci (#18)
---
jumpcutter/clip.py | 43 +++++++++++++++++++++++++------------------
1 file changed, 25 insertions(+), 18 deletions(-)
diff --git a/jumpcutter/clip.py b/jumpcutter/clip.py
index 5bfa3b3..bbcc7f3 100644
--- a/jumpcutter/clip.py
+++ b/jumpcutter/clip.py
@@ -1,12 +1,18 @@
+from typing import Dict, List, Tuple
+
import numpy as np
+from moviepy.audio.io.AudioFileClip import AudioFileClip
from moviepy.editor import VideoFileClip, concatenate_videoclips
from moviepy.video.fx.all import speedx
+from moviepy.video.io.VideoFileClip import VideoFileClip
from tqdm import tqdm
class Clip:
- def __init__(self, clip_path, min_loud_part_duration, silence_part_speed):
+ def __init__(
+ self, clip_path: str, min_loud_part_duration: int, silence_part_speed: int
+ ) -> None:
self.clip = VideoFileClip(clip_path)
self.audio = Audio(self.clip.audio)
self.cut_to_method = {
@@ -16,17 +22,14 @@ def __init__(self, clip_path, min_loud_part_duration, silence_part_speed):
self.min_loud_part_duration = min_loud_part_duration
self.silence_part_speed = silence_part_speed
- def get_duration(self):
- return self.clip.duration
-
def jumpcut(
self,
- cuts,
- magnitude_threshold_ratio,
- duration_threshold_in_seconds,
- failure_tolerance_ratio,
- space_on_edges,
- ):
+ cuts: List[str],
+ magnitude_threshold_ratio: float,
+ duration_threshold_in_seconds: float,
+ failure_tolerance_ratio: float,
+ space_on_edges: float,
+ ) -> Dict[str, VideoFileClip]:
intervals_to_cut = self.audio.get_intervals_to_cut(
magnitude_threshold_ratio,
@@ -41,7 +44,9 @@ def jumpcut(
return outputs
- def jumpcut_silent_parts(self, intervals_to_cut):
+ def jumpcut_silent_parts(
+ self, intervals_to_cut: List[Tuple[float, float]]
+ ) -> List[VideoFileClip]:
jumpcutted_clips = []
previous_stop = 0
for start, stop in tqdm(intervals_to_cut, desc="Cutting silent intervals"):
@@ -64,7 +69,9 @@ def jumpcut_silent_parts(self, intervals_to_cut):
jumpcutted_clips.append(last_clip)
return jumpcutted_clips
- def jumpcut_voiced_parts(self, intervals_to_cut):
+ def jumpcut_voiced_parts(
+ self, intervals_to_cut: List[Tuple[float, float]]
+ ) -> List[VideoFileClip]:
jumpcutted_clips = []
for start, stop in tqdm(intervals_to_cut, desc="Cutting voiced intervals"):
if start < stop:
@@ -74,7 +81,7 @@ def jumpcut_voiced_parts(self, intervals_to_cut):
class Audio:
- def __init__(self, audio):
+ def __init__(self, audio: AudioFileClip) -> None:
self.audio = audio
self.fps = audio.fps
@@ -84,11 +91,11 @@ def __init__(self, audio):
def get_intervals_to_cut(
self,
- magnitude_threshold_ratio,
- duration_threshold_in_seconds,
- failure_tolerance_ratio,
- space_on_edges,
- ):
+ magnitude_threshold_ratio: float,
+ duration_threshold_in_seconds: float,
+ failure_tolerance_ratio: float,
+ space_on_edges: float,
+ ) -> List[Tuple[float, float]]:
min_magnitude = min(abs(np.min(self.signal)), np.max(self.signal))
magnitude_threshold = min_magnitude * magnitude_threshold_ratio
failure_tolerance = self.fps * failure_tolerance_ratio
--
2.50.0
|