yta-video-frame-time 0.0.6__py3-none-any.whl → 0.0.8__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.
Potentially problematic release.
This version of yta-video-frame-time might be problematic. Click here for more details.
- yta_video_frame_time/t_fraction.py +199 -6
- {yta_video_frame_time-0.0.6.dist-info → yta_video_frame_time-0.0.8.dist-info}/METADATA +1 -1
- yta_video_frame_time-0.0.8.dist-info/RECORD +6 -0
- yta_video_frame_time-0.0.6.dist-info/RECORD +0 -6
- {yta_video_frame_time-0.0.6.dist-info → yta_video_frame_time-0.0.8.dist-info}/LICENSE +0 -0
- {yta_video_frame_time-0.0.6.dist-info → yta_video_frame_time-0.0.8.dist-info}/WHEEL +0 -0
|
@@ -238,6 +238,8 @@ def round_pts(
|
|
|
238
238
|
and 'time_base', but here is an easier
|
|
239
239
|
example using the time moments.
|
|
240
240
|
|
|
241
|
+
(!) This is valid only for video.
|
|
242
|
+
|
|
241
243
|
Examples below, with `time_base = 1/5`:
|
|
242
244
|
- `t = 0.25` => `0.2` (truncated or rounded)
|
|
243
245
|
- `t = 0.35` => `0.2` (truncated)
|
|
@@ -256,8 +258,6 @@ def round_pts(
|
|
|
256
258
|
|
|
257
259
|
return int(frame_index * ticks_per_frame)
|
|
258
260
|
|
|
259
|
-
# TODO: Create a 'round_pts'
|
|
260
|
-
|
|
261
261
|
"""
|
|
262
262
|
When we are working with the 't' time
|
|
263
263
|
moment we need to use the fps, and when
|
|
@@ -302,7 +302,22 @@ class _T:
|
|
|
302
302
|
None, we will not make any conversion
|
|
303
303
|
and the value received could be useless
|
|
304
304
|
because it is in the middle of a range.
|
|
305
|
+
|
|
306
|
+
The formula:
|
|
307
|
+
- `pts * time_base`
|
|
305
308
|
"""
|
|
309
|
+
t = Fraction(pts * self._t_handler.time_base)
|
|
310
|
+
|
|
311
|
+
return (
|
|
312
|
+
self._t_handler.t.truncated(t)
|
|
313
|
+
if do_truncate is True else
|
|
314
|
+
self._t_handler.t.rounded(t)
|
|
315
|
+
if do_truncate is False else
|
|
316
|
+
t # if None
|
|
317
|
+
)
|
|
318
|
+
|
|
319
|
+
# TODO: Remove this below in the next
|
|
320
|
+
# commit
|
|
306
321
|
pts = (
|
|
307
322
|
self._t_handler.pts.truncated(pts)
|
|
308
323
|
if do_truncate is True else
|
|
@@ -322,8 +337,47 @@ class _T:
|
|
|
322
337
|
Transform the given 't' to a 'pts' value
|
|
323
338
|
truncating, rounding or applying no
|
|
324
339
|
variation.
|
|
340
|
+
|
|
341
|
+
The formula:
|
|
342
|
+
- `int(t / time_base)`
|
|
325
343
|
"""
|
|
326
344
|
return self._t_handler.pts.from_t(t, do_truncate)
|
|
345
|
+
|
|
346
|
+
def to_index(
|
|
347
|
+
self,
|
|
348
|
+
t: Union[int, float, Fraction],
|
|
349
|
+
do_truncate: Union[bool, None] = True
|
|
350
|
+
) -> int:
|
|
351
|
+
"""
|
|
352
|
+
Transform the given 't' to a index value
|
|
353
|
+
truncating, rounding or applying no
|
|
354
|
+
variation.
|
|
355
|
+
|
|
356
|
+
The formula:
|
|
357
|
+
- `int(t * fps)`
|
|
358
|
+
"""
|
|
359
|
+
t = (
|
|
360
|
+
self.truncated(t)
|
|
361
|
+
if do_truncate is True else
|
|
362
|
+
self.rounded(t)
|
|
363
|
+
if do_truncate is False else
|
|
364
|
+
t
|
|
365
|
+
)
|
|
366
|
+
|
|
367
|
+
return frame_t_to_index(t, self.fps)
|
|
368
|
+
|
|
369
|
+
def from_index(
|
|
370
|
+
self,
|
|
371
|
+
index: int
|
|
372
|
+
) -> Fraction:
|
|
373
|
+
"""
|
|
374
|
+
Transform the given index to a 't' time
|
|
375
|
+
moment value.
|
|
376
|
+
|
|
377
|
+
The formula:
|
|
378
|
+
- `frame_index * (1 / fps)`
|
|
379
|
+
"""
|
|
380
|
+
return frame_index_to_t(index, self.fps)
|
|
327
381
|
|
|
328
382
|
def truncated(
|
|
329
383
|
self,
|
|
@@ -367,6 +421,9 @@ class _T:
|
|
|
367
421
|
|
|
368
422
|
Useful when you need the next value for a
|
|
369
423
|
range in an iteration or similar.
|
|
424
|
+
|
|
425
|
+
The formula:
|
|
426
|
+
- `t + n * (1 / fps)`
|
|
370
427
|
"""
|
|
371
428
|
t = (
|
|
372
429
|
self.truncated(t)
|
|
@@ -374,7 +431,7 @@ class _T:
|
|
|
374
431
|
self.rounded(t)
|
|
375
432
|
)
|
|
376
433
|
|
|
377
|
-
return t + n * self._t_handler.
|
|
434
|
+
return t + n * (1 / self._t_handler.fps)
|
|
378
435
|
|
|
379
436
|
def previous(
|
|
380
437
|
self,
|
|
@@ -395,6 +452,9 @@ class _T:
|
|
|
395
452
|
Be careful, if the 'truncated' value is 0
|
|
396
453
|
this will give you an unexpected negative
|
|
397
454
|
value.
|
|
455
|
+
|
|
456
|
+
The formula:
|
|
457
|
+
- `t - n * (1 / fps)`
|
|
398
458
|
"""
|
|
399
459
|
t = (
|
|
400
460
|
self.truncated(t)
|
|
@@ -402,7 +462,7 @@ class _T:
|
|
|
402
462
|
self.rounded(t)
|
|
403
463
|
)
|
|
404
464
|
|
|
405
|
-
return t - n * self._t_handler.
|
|
465
|
+
return t - n * (1 / self._t_handler.fps)
|
|
406
466
|
|
|
407
467
|
class _Pts:
|
|
408
468
|
"""
|
|
@@ -442,6 +502,9 @@ class _Pts:
|
|
|
442
502
|
None, we will not make any conversion
|
|
443
503
|
and the value received could be useless
|
|
444
504
|
because it is in the middle of a range.
|
|
505
|
+
|
|
506
|
+
The formula:
|
|
507
|
+
- `int(t / time_base)`
|
|
445
508
|
"""
|
|
446
509
|
t = (
|
|
447
510
|
self._t_handler.t.truncated(t)
|
|
@@ -462,8 +525,55 @@ class _Pts:
|
|
|
462
525
|
Transform the given 'pts' to a 't' value
|
|
463
526
|
truncating, rounding or applying no
|
|
464
527
|
variation.
|
|
528
|
+
|
|
529
|
+
The formula:
|
|
530
|
+
- `pts * time_base`
|
|
465
531
|
"""
|
|
466
532
|
return self._t_handler.t.from_pts(pts, do_truncate)
|
|
533
|
+
|
|
534
|
+
def to_index(
|
|
535
|
+
self,
|
|
536
|
+
pts: int,
|
|
537
|
+
do_truncate: Union[bool, None] = True
|
|
538
|
+
) -> int:
|
|
539
|
+
"""
|
|
540
|
+
Transform the given 'pts' to a index value
|
|
541
|
+
truncating, rounding or applying no
|
|
542
|
+
variation.
|
|
543
|
+
|
|
544
|
+
The formula:
|
|
545
|
+
- `int((pts * time_base) * fps)`
|
|
546
|
+
"""
|
|
547
|
+
return self._t_handler.t.to_index(
|
|
548
|
+
self.to_t(pts, do_truncate = None),
|
|
549
|
+
do_truncate = do_truncate
|
|
550
|
+
)
|
|
551
|
+
|
|
552
|
+
def from_index(
|
|
553
|
+
self,
|
|
554
|
+
index: int
|
|
555
|
+
) -> Fraction:
|
|
556
|
+
"""
|
|
557
|
+
Transform the given index to a 't' time
|
|
558
|
+
moment value.
|
|
559
|
+
|
|
560
|
+
The formula:
|
|
561
|
+
- `int((frame_index * (1 / fps)) * time_base)`
|
|
562
|
+
"""
|
|
563
|
+
return self.from_t(
|
|
564
|
+
t = self._t_handler.t.from_index(index),
|
|
565
|
+
do_truncate = True
|
|
566
|
+
)
|
|
567
|
+
|
|
568
|
+
"""
|
|
569
|
+
This about the pts is not 100% sure as it
|
|
570
|
+
is only a value to display the frames but
|
|
571
|
+
not accurate and depends on the encoder.
|
|
572
|
+
|
|
573
|
+
Maybe we don't want all this functionality
|
|
574
|
+
but only the one that is 100% sure its
|
|
575
|
+
working properly.
|
|
576
|
+
"""
|
|
467
577
|
|
|
468
578
|
def truncated(
|
|
469
579
|
self,
|
|
@@ -475,6 +585,8 @@ class _Pts:
|
|
|
475
585
|
This means that if 't' is in a
|
|
476
586
|
[start, end) range, we will obtain the
|
|
477
587
|
'start' value always.
|
|
588
|
+
|
|
589
|
+
(!) This is valid only for video
|
|
478
590
|
"""
|
|
479
591
|
return round_pts(
|
|
480
592
|
pts = pts,
|
|
@@ -495,6 +607,8 @@ class _Pts:
|
|
|
495
607
|
the 'start' or the 'end' value according
|
|
496
608
|
to which one is closer to the that 't'
|
|
497
609
|
value provided.
|
|
610
|
+
|
|
611
|
+
(!) This is valid only for video.
|
|
498
612
|
"""
|
|
499
613
|
return round_pts(
|
|
500
614
|
pts = pts,
|
|
@@ -503,7 +617,7 @@ class _Pts:
|
|
|
503
617
|
do_truncate = False
|
|
504
618
|
)
|
|
505
619
|
|
|
506
|
-
def
|
|
620
|
+
def next_video(
|
|
507
621
|
self,
|
|
508
622
|
pts: int,
|
|
509
623
|
n: int = 1,
|
|
@@ -517,6 +631,11 @@ class _Pts:
|
|
|
517
631
|
|
|
518
632
|
Useful when you need the next value for a
|
|
519
633
|
range in an iteration or similar.
|
|
634
|
+
|
|
635
|
+
(!) This is valid only for video.
|
|
636
|
+
|
|
637
|
+
The formula:
|
|
638
|
+
- `pts + n * ticks_per_frame`
|
|
520
639
|
"""
|
|
521
640
|
pts = (
|
|
522
641
|
self.truncated(pts)
|
|
@@ -526,7 +645,32 @@ class _Pts:
|
|
|
526
645
|
|
|
527
646
|
return pts + n * get_ticks_per_frame(self._t_handler.fps, self._t_handler.time_base)
|
|
528
647
|
|
|
529
|
-
def
|
|
648
|
+
def next_audio(
|
|
649
|
+
self,
|
|
650
|
+
pts: int,
|
|
651
|
+
samples_per_frame: int,
|
|
652
|
+
n: int = 1
|
|
653
|
+
) -> int:
|
|
654
|
+
"""
|
|
655
|
+
Get the value that is 'n' times ahead of
|
|
656
|
+
the 'pts' value provided according to the
|
|
657
|
+
number of 'samples_per_frame' each frame
|
|
658
|
+
has.
|
|
659
|
+
|
|
660
|
+
TODO: Are we sure that the number of
|
|
661
|
+
samples per frame is always the same (?)
|
|
662
|
+
|
|
663
|
+
Useful when you need the next value for a
|
|
664
|
+
range in an iteration or similar.
|
|
665
|
+
|
|
666
|
+
(!) This is valid only for audio.
|
|
667
|
+
|
|
668
|
+
The formula:
|
|
669
|
+
- `pts + (n * samples_per_frame)`
|
|
670
|
+
"""
|
|
671
|
+
return pts + (n * samples_per_frame)
|
|
672
|
+
|
|
673
|
+
def previous_video(
|
|
530
674
|
self,
|
|
531
675
|
pts: int,
|
|
532
676
|
n: int = 1,
|
|
@@ -545,6 +689,11 @@ class _Pts:
|
|
|
545
689
|
Be careful, if the 'truncated' value is 0
|
|
546
690
|
this will give you an unexpected negative
|
|
547
691
|
value.
|
|
692
|
+
|
|
693
|
+
(!) This is valid only for video.
|
|
694
|
+
|
|
695
|
+
The formula:
|
|
696
|
+
- `pts - n * ticks_per_frame`
|
|
548
697
|
"""
|
|
549
698
|
pts = (
|
|
550
699
|
self.truncated(pts)
|
|
@@ -553,6 +702,31 @@ class _Pts:
|
|
|
553
702
|
)
|
|
554
703
|
|
|
555
704
|
return pts - n * get_ticks_per_frame(self._t_handler.fps, self._t_handler.time_base)
|
|
705
|
+
|
|
706
|
+
def previous_audio(
|
|
707
|
+
self,
|
|
708
|
+
pts: int,
|
|
709
|
+
samples_per_frame: int,
|
|
710
|
+
n: int = 1
|
|
711
|
+
) -> int:
|
|
712
|
+
"""
|
|
713
|
+
Get the value that is 'n' times before
|
|
714
|
+
the 'pts' value provided according to the
|
|
715
|
+
number of 'samples_per_frame' each frame
|
|
716
|
+
has.
|
|
717
|
+
|
|
718
|
+
TODO: Are we sure that the number of
|
|
719
|
+
samples per frame is always the same (?)
|
|
720
|
+
|
|
721
|
+
Useful when you need the next value for a
|
|
722
|
+
range in an iteration or similar.
|
|
723
|
+
|
|
724
|
+
(!) This is valid only for audio.
|
|
725
|
+
|
|
726
|
+
The formula:
|
|
727
|
+
- `pts - (n * samples_per_frame)`
|
|
728
|
+
"""
|
|
729
|
+
return pts - (n * samples_per_frame)
|
|
556
730
|
|
|
557
731
|
class THandler:
|
|
558
732
|
"""
|
|
@@ -651,6 +825,8 @@ def frame_t_to_pts(
|
|
|
651
825
|
moment provided, based on the also provided
|
|
652
826
|
'fps' and 'time_base'.
|
|
653
827
|
|
|
828
|
+
(!) This is valid only for videos.
|
|
829
|
+
|
|
654
830
|
The formula:
|
|
655
831
|
- `frame_index * ticks_per_frame`
|
|
656
832
|
"""
|
|
@@ -670,6 +846,20 @@ def frame_pts_to_t(
|
|
|
670
846
|
- `pts * time_base`
|
|
671
847
|
"""
|
|
672
848
|
return parse_fraction(pts * time_base)
|
|
849
|
+
|
|
850
|
+
def get_audio_frame_duration(
|
|
851
|
+
samples: int,
|
|
852
|
+
fps: Fraction
|
|
853
|
+
) -> Fraction:
|
|
854
|
+
"""
|
|
855
|
+
Get the audio frame duration by giving the
|
|
856
|
+
number of '.samples' and also the rate (that
|
|
857
|
+
we call 'fps').
|
|
858
|
+
|
|
859
|
+
This is useful when trying to guess the next
|
|
860
|
+
pts or t.
|
|
861
|
+
"""
|
|
862
|
+
return Fraction(samples / fps)
|
|
673
863
|
|
|
674
864
|
def get_ticks_per_frame(
|
|
675
865
|
fps: Union[float, int, Fraction],
|
|
@@ -680,6 +870,9 @@ def get_ticks_per_frame(
|
|
|
680
870
|
tick is the minimum amount of time we
|
|
681
871
|
spend from one frame to the next.
|
|
682
872
|
|
|
873
|
+
(!) This is only valid for video
|
|
874
|
+
apparently.
|
|
875
|
+
|
|
683
876
|
The formula:
|
|
684
877
|
- `1 / (fps * time_base)`
|
|
685
878
|
"""
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
yta_video_frame_time/__init__.py,sha256=-YOa7lOKdiA3FwDEHHU1tHobnmhjFpTaVLfJQLZqoMI,22252
|
|
2
|
+
yta_video_frame_time/t_fraction.py,sha256=RQwZ2-ko0m4HIbf35bV107I9k2n-C0qWv-pJGmvNUOI,24799
|
|
3
|
+
yta_video_frame_time-0.0.8.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
|
4
|
+
yta_video_frame_time-0.0.8.dist-info/METADATA,sha256=VpvV6zRnEK5B0y37UYdH7U94iLtATHwsEAhYARkqVnw,515
|
|
5
|
+
yta_video_frame_time-0.0.8.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
|
6
|
+
yta_video_frame_time-0.0.8.dist-info/RECORD,,
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
yta_video_frame_time/__init__.py,sha256=-YOa7lOKdiA3FwDEHHU1tHobnmhjFpTaVLfJQLZqoMI,22252
|
|
2
|
-
yta_video_frame_time/t_fraction.py,sha256=c0sz-ncVV_Qt--rM2k1xKyjZpPF_pH5bFKPFx6WmxQc,20027
|
|
3
|
-
yta_video_frame_time-0.0.6.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
|
4
|
-
yta_video_frame_time-0.0.6.dist-info/METADATA,sha256=is6UfhRMg48ToFwXBgwHOuPT2K6aqGTSt05KedCnAiw,515
|
|
5
|
-
yta_video_frame_time-0.0.6.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
|
6
|
-
yta_video_frame_time-0.0.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|