yta-video-frame-time 0.0.2__py3-none-any.whl → 0.0.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- yta_video_frame_time/__init__.py +83 -8
- {yta_video_frame_time-0.0.2.dist-info → yta_video_frame_time-0.0.4.dist-info}/METADATA +1 -1
- yta_video_frame_time-0.0.4.dist-info/RECORD +5 -0
- yta_video_frame_time-0.0.2.dist-info/RECORD +0 -5
- {yta_video_frame_time-0.0.2.dist-info → yta_video_frame_time-0.0.4.dist-info}/LICENSE +0 -0
- {yta_video_frame_time-0.0.2.dist-info → yta_video_frame_time-0.0.4.dist-info}/WHEEL +0 -0
yta_video_frame_time/__init__.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Module to handle frame indexes and times.
|
|
3
3
|
"""
|
|
4
4
|
from yta_validation.parameter import ParameterValidator
|
|
5
|
+
from typing import Union
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
SMALL_AMOUNT_TO_FIX = 0.0000000001
|
|
@@ -36,11 +37,13 @@ class T:
|
|
|
36
37
|
ParameterValidator.validate_mandatory_positive_number('t', t, do_include_zero = True)
|
|
37
38
|
ParameterValidator.validate_mandatory_positive_number('fps', fps, do_include_zero = False)
|
|
38
39
|
|
|
39
|
-
return T.
|
|
40
|
-
|
|
40
|
+
return T.video_frame_time_to_video_frame_index(t, fps) / fps + SMALL_AMOUNT_TO_FIX
|
|
41
|
+
|
|
41
42
|
def get_frame_indexes(
|
|
42
43
|
duration: float,
|
|
43
44
|
fps: float,
|
|
45
|
+
start: Union[float, None] = None,
|
|
46
|
+
end: Union[float, None] = None,
|
|
44
47
|
do_invert_order: bool = False
|
|
45
48
|
):
|
|
46
49
|
"""
|
|
@@ -59,6 +62,28 @@ class T:
|
|
|
59
62
|
# If you remove 'list' you get a generator instead
|
|
60
63
|
frame_indexes = list(range(get_number_of_frames(duration, fps)))
|
|
61
64
|
|
|
65
|
+
# TODO: Maybe move this to a helper (?)
|
|
66
|
+
# Limit to ['start', 'end'] range
|
|
67
|
+
if (
|
|
68
|
+
start is not None or
|
|
69
|
+
end is not None
|
|
70
|
+
):
|
|
71
|
+
start = (
|
|
72
|
+
T.video_frame_time_to_video_frame_index(start, fps)
|
|
73
|
+
if start is not None else
|
|
74
|
+
0.0
|
|
75
|
+
)
|
|
76
|
+
end = (
|
|
77
|
+
T.video_frame_time_to_video_frame_index(end, fps)
|
|
78
|
+
if end is not None else
|
|
79
|
+
9999999999
|
|
80
|
+
)
|
|
81
|
+
frame_indexes = [
|
|
82
|
+
frame_index
|
|
83
|
+
for frame_index in frame_indexes
|
|
84
|
+
if start <= frame_index < end
|
|
85
|
+
]
|
|
86
|
+
|
|
62
87
|
return (
|
|
63
88
|
frame_indexes[::-1]
|
|
64
89
|
if do_invert_order else
|
|
@@ -286,6 +311,8 @@ class T:
|
|
|
286
311
|
def get_frame_time_moments(
|
|
287
312
|
duration: float,
|
|
288
313
|
fps: float,
|
|
314
|
+
start: Union[float, None] = None,
|
|
315
|
+
end: Union[float, None] = None,
|
|
289
316
|
do_invert_order: bool = False
|
|
290
317
|
):
|
|
291
318
|
"""
|
|
@@ -313,6 +340,28 @@ class T:
|
|
|
313
340
|
for i in range(get_number_of_frames(duration, fps) + 1)
|
|
314
341
|
][:-1]
|
|
315
342
|
|
|
343
|
+
# TODO: Maybe move this to a helper (?)
|
|
344
|
+
# Limit to ['start', 'end'] range
|
|
345
|
+
if (
|
|
346
|
+
start is not None or
|
|
347
|
+
end is not None
|
|
348
|
+
):
|
|
349
|
+
start = (
|
|
350
|
+
start
|
|
351
|
+
if start is not None else
|
|
352
|
+
0.0
|
|
353
|
+
)
|
|
354
|
+
end = (
|
|
355
|
+
end
|
|
356
|
+
if end is not None else
|
|
357
|
+
9999999999
|
|
358
|
+
)
|
|
359
|
+
frame_time_moments = [
|
|
360
|
+
frame_time_moment
|
|
361
|
+
for frame_time_moment in frame_time_moments
|
|
362
|
+
if start <= frame_time_moment < end
|
|
363
|
+
]
|
|
364
|
+
|
|
316
365
|
return (
|
|
317
366
|
frame_time_moments[::-1]
|
|
318
367
|
if do_invert_order else
|
|
@@ -409,19 +458,20 @@ class T:
|
|
|
409
458
|
ParameterValidator.validate_mandatory_positive_number('audio_fps', audio_fps, do_include_zero = False)
|
|
410
459
|
ParameterValidator.validate_mandatory_bool('do_invert_order', do_invert_order)
|
|
411
460
|
|
|
412
|
-
from yta_general_utils.math.progression import Progression
|
|
413
|
-
|
|
414
461
|
audio_frames_per_video_frame = int(audio_fps / video_fps)
|
|
415
462
|
audio_frame_duration = 1 / audio_fps
|
|
416
463
|
video_frame_duration = 1 / video_fps
|
|
417
464
|
|
|
418
465
|
t = T.get_frame_time_base(video_t, video_fps)
|
|
419
466
|
|
|
420
|
-
|
|
421
|
-
|
|
467
|
+
# This is replacing a 'Progression' from
|
|
468
|
+
# the 'yta_general_utils' library because
|
|
469
|
+
# it has many imports we don't want here...
|
|
470
|
+
audio_time_moments = _linspace(
|
|
471
|
+
start = t,
|
|
422
472
|
end = t + video_frame_duration - audio_frame_duration,
|
|
423
473
|
n = audio_frames_per_video_frame
|
|
424
|
-
)
|
|
474
|
+
)
|
|
425
475
|
|
|
426
476
|
return (
|
|
427
477
|
audio_time_moments[::-1]
|
|
@@ -540,4 +590,29 @@ def get_number_of_frames(
|
|
|
540
590
|
The formula is:
|
|
541
591
|
- `int(duration * fps + SMALL_AMOUNT)`
|
|
542
592
|
"""
|
|
543
|
-
return int(duration * fps + SMALL_AMOUNT_TO_FIX)
|
|
593
|
+
return int(duration * fps + SMALL_AMOUNT_TO_FIX)
|
|
594
|
+
|
|
595
|
+
def _linspace(
|
|
596
|
+
start: float,
|
|
597
|
+
end: float,
|
|
598
|
+
n: int,
|
|
599
|
+
):
|
|
600
|
+
"""
|
|
601
|
+
*For internal use only*
|
|
602
|
+
|
|
603
|
+
A simplified version of the 'Progression'
|
|
604
|
+
class we have in 'yta_general_utils', to
|
|
605
|
+
avoid importing that library that has other
|
|
606
|
+
dependencies I don't need here.
|
|
607
|
+
|
|
608
|
+
This method should be removed when the
|
|
609
|
+
Progression class is refactored and all
|
|
610
|
+
those dependencies are removed.
|
|
611
|
+
"""
|
|
612
|
+
if n < 2:
|
|
613
|
+
raise Exception('The "n" parameter must be greater or equal than 2.')
|
|
614
|
+
|
|
615
|
+
return [
|
|
616
|
+
start + i * ((end - start) / (n - 1))
|
|
617
|
+
for i in range(n)
|
|
618
|
+
]
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
yta_video_frame_time/__init__.py,sha256=xgdMlHkHFw__0q9FdFFcjcFQIIeIw_xTzw6YS-9SyI4,22254
|
|
2
|
+
yta_video_frame_time-0.0.4.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
|
3
|
+
yta_video_frame_time-0.0.4.dist-info/METADATA,sha256=C9Qqb5ai6V4mvvIUNwknag5c0quMy8Tmf4u-rH-vBWE,472
|
|
4
|
+
yta_video_frame_time-0.0.4.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
|
5
|
+
yta_video_frame_time-0.0.4.dist-info/RECORD,,
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
yta_video_frame_time/__init__.py,sha256=iN9nRtV3Rjpp6vCcz1fckjVDijHLHzLdTfGN9l4cG6w,20019
|
|
2
|
-
yta_video_frame_time-0.0.2.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
|
3
|
-
yta_video_frame_time-0.0.2.dist-info/METADATA,sha256=xIrDdhK3vE0PSDC3xoTTSJz7UOe6PTsvVeSwlDDSz9c,472
|
|
4
|
-
yta_video_frame_time-0.0.2.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
|
5
|
-
yta_video_frame_time-0.0.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|