yta-video-opengl 0.0.25__py3-none-any.whl → 0.0.27__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.
@@ -1,7 +1,9 @@
1
1
  from yta_video_opengl.nodes.video.opengl import WavingNode
2
2
  from yta_video_opengl.nodes.audio import ChorusNode
3
3
  from yta_video_opengl.nodes import TimedNode
4
+ from yta_video_opengl.utils import texture_to_frame
4
5
  from yta_validation.parameter import ParameterValidator
6
+ from yta_validation import PythonValidator
5
7
  from yta_programming.decorators import singleton_old
6
8
  from typing import Union
7
9
 
@@ -379,4 +381,46 @@ class EffectsStack:
379
381
 
380
382
  return self
381
383
 
384
+ def apply_video_effects(
385
+ self,
386
+ frame: 'np.ndarray',
387
+ t: Union[int, float, 'Fraction']
388
+ ) -> 'np.ndarray':
389
+ """
390
+ Apply all the video effects that must be
391
+ applied for the given 't' time moment to
392
+ the provided 'frame' (that must be the
393
+ video frame of that time moment).
394
+ """
395
+ for effect in self.get_video_effects_for_t(t):
396
+ frame = effect.process(frame, t)
397
+
398
+ # TODO: Check when the frame comes as a
399
+ # Texture and when as a numpy array. I
400
+ # think when we apply an opengl node it
401
+ # is a texture, but we need to return it
402
+ # as a numpy, always
403
+ return (
404
+ texture_to_frame(frame)
405
+ if PythonValidator.is_instance_of(frame, moderngl.Texture) else
406
+ frame
407
+ )
408
+
409
+ def apply_audio_effects(
410
+ self,
411
+ frame: 'np.ndarray',
412
+ t: Union[int, float, 'Fraction']
413
+ ) -> 'np.ndarray':
414
+ """
415
+ Apply all the video effects that must be
416
+ applied for the given 't' time moment to
417
+ the provided 'frame' (that must be the
418
+ audio frame of that time moment).
419
+ """
420
+ for effect in self.get_audio_effects_for_t(t):
421
+ frame = effect.process(frame, t)
422
+
423
+ # Frame can only by a numpy array here
424
+ return frame
425
+
382
426
  # TODO: Create 'remove_effect'
@@ -131,11 +131,11 @@ class TimedNode:
131
131
 
132
132
  def process(
133
133
  self,
134
- frame: Union['VideoFrame', 'AudioFrame', moderngl.Texture],
134
+ frame: Union[moderngl.Texture, 'np.ndarray'],
135
135
  t: float
136
136
  # TODO: Maybe we need 'fps' and 'number_of_frames'
137
137
  # to calculate progressions or similar...
138
- ) -> Union['VideoFrame', 'AudioFrame', 'Texture']:
138
+ ) -> Union[moderngl.Texture, 'np.ndarray']:
139
139
  """
140
140
  Process the frame if the provided 't' time
141
141
  moment is in the range of this TimedNode
@@ -32,9 +32,9 @@ class _AudioNode:
32
32
  @abstractmethod
33
33
  def process(
34
34
  self,
35
- input: Union['AudioFrame', 'np.ndarray'],
35
+ input: np.ndarray,
36
36
  t: float
37
- ) -> Union['AudioFrame', 'np.ndarray']:
37
+ ) -> np.ndarray:
38
38
  """
39
39
  Process the provided audio 'input' that
40
40
  is played on the given 't' time moment.
@@ -59,20 +59,13 @@ class VolumeNode(_AudioNode):
59
59
 
60
60
  def process(
61
61
  self,
62
- input: Union['AudioFrame', 'np.ndarray'],
62
+ input: np.ndarray,
63
63
  t: float
64
- ) -> Union['AudioFrame', 'np.ndarray']:
64
+ ) -> np.ndarray:
65
65
  """
66
66
  Process the provided audio 'input' that
67
67
  is played on the given 't' time moment.
68
68
  """
69
- # if PythonValidator.is_instance_of(input, 'AudioFrame'):
70
- # input = input.to_ndarray().astype(np.float32)
71
-
72
- # TODO: I think we should receive only
73
- # numpy arrays and the AudioFrame should
74
- # be handled outside, but I'm not sure
75
-
76
69
  factor = self.factor_fn(t, 0)
77
70
 
78
71
  samples = input
@@ -86,15 +79,6 @@ class VolumeNode(_AudioNode):
86
79
  # samples.astype(np.float32)
87
80
  # )
88
81
 
89
- # new_frame = AudioFrame.from_ndarray(
90
- # samples,
91
- # format = input.format.name,
92
- # layout = input.layout.name
93
- # )
94
- # new_frame.sample_rate = input.sample_rate
95
- # new_frame.pts = input.pts
96
- # new_frame.time_base = input.time_base
97
-
98
82
  return samples
99
83
 
100
84
  class ChorusNode(_AudioNode):
@@ -121,17 +105,13 @@ class ChorusNode(_AudioNode):
121
105
 
122
106
  def process(
123
107
  self,
124
- input: Union['AudioFrame', 'np.ndarray'],
108
+ input: Union[np.ndarray],
125
109
  t: float
126
- ) -> Union['AudioFrame', 'np.ndarray']:
110
+ ) -> np.ndarray:
127
111
  """
128
112
  Process the provided audio 'input' that
129
113
  is played on the given 't' time moment.
130
114
  """
131
- # TODO: I think we should receive only
132
- # numpy arrays and the AudioFrame should
133
- # be handled outside, but I'm not sure
134
-
135
115
  n_samples = input.shape[0]
136
116
  t = np.arange(n_samples) / self.rate
137
117
 
@@ -143,81 +123,11 @@ class ChorusNode(_AudioNode):
143
123
 
144
124
  for i in range(n_samples):
145
125
  d = delay[i]
146
- if i - d >= 0:
147
- output[i] = 0.7 * input[i] + 0.7 * input[i - d]
148
- else:
149
- output[i] = input[i]
150
126
 
151
- return output
127
+ output[i]= (
128
+ 0.7 * input[i] + 0.7 * input[i - d]
129
+ if (i - d) >= 0 else
130
+ input[i]
131
+ )
152
132
 
153
- # TODO: Remove this below
154
- """
155
- Here you have an example. The 'private'
156
- node class is the modifier, that we don't
157
- want to expose, and the 'public' class is
158
- the one that inherits from TimedNode and
159
- wraps the 'private' class to build the
160
- functionality.
161
- """
162
- # class VolumeAudioNode(TimedNode):
163
- # """
164
- # TimedNode to set the audio volume of a video
165
- # in a specific frame.
166
- # """
167
-
168
- # def __init__(
169
- # self,
170
- # factor_fn,
171
- # start: float = 0.0,
172
- # end: Union[float, None] = None
173
- # ):
174
- # super().__init__(
175
- # node = _SetVolumeAudioNode(factor_fn),
176
- # start = start,
177
- # end = end
178
- # )
179
-
180
- # class _SetVolumeAudioNode(AudioNode):
181
- # """
182
- # Audio node to change the volume of an
183
- # audio frame.
184
- # """
185
-
186
- # def __init__(
187
- # self,
188
- # factor_fn
189
- # ):
190
- # """
191
- # factor_fn: function (t, index) -> factor volumen
192
- # """
193
- # self.factor_fn = factor_fn
194
-
195
- # def process(
196
- # self,
197
- # frame: av.AudioFrame,
198
- # t: float,
199
- # ) -> av.AudioFrame:
200
- # # TODO: Why index (?) Maybe 'total_frames'
201
- # factor = self.factor_fn(t, 0)
202
-
203
- # samples = frame.to_ndarray().astype(np.float32)
204
- # samples *= factor
205
-
206
- # # Determine dtype according to format
207
- # samples = (
208
- # samples.astype(np.int16)
209
- # # 'fltp', 's16', 's16p'
210
- # if 's16' in frame.format.name else
211
- # samples.astype(np.float32)
212
- # )
213
-
214
- # new_frame = av.AudioFrame.from_ndarray(
215
- # samples,
216
- # format = frame.format.name,
217
- # layout = frame.layout.name
218
- # )
219
- # new_frame.sample_rate = frame.sample_rate
220
- # new_frame.pts = frame.pts
221
- # new_frame.time_base = frame.time_base
222
-
223
- # return new_frame
133
+ return output
@@ -199,7 +199,7 @@ class OpenglNodeBase(_VideoNode):
199
199
 
200
200
  def process(
201
201
  self,
202
- input: Union[moderngl.Texture, 'VideoFrame', 'np.ndarray']
202
+ input: Union[moderngl.Texture, np.ndarray]
203
203
  ) -> moderngl.Texture:
204
204
  """
205
205
  Apply the shader to the 'input', that
@@ -209,7 +209,7 @@ class OpenglNodeBase(_VideoNode):
209
209
  We use and return textures to maintain
210
210
  the process in GPU and optimize it.
211
211
  """
212
- if PythonValidator.is_instance_of(input, ['VideoFrame', 'ndarray']):
212
+ if PythonValidator.is_instance_of(input, np.ndarray):
213
213
  # TODO: What about the numpy format (?)
214
214
  input = frame_to_texture(input, self.context)
215
215
 
@@ -293,7 +293,7 @@ class WavingNode(OpenglNodeBase):
293
293
  # processed by the code
294
294
  def process(
295
295
  self,
296
- input: Union[moderngl.Texture, 'VideoFrame', 'np.ndarray'],
296
+ input: Union[moderngl.Texture, 'np.ndarray'],
297
297
  t: float = 0.0,
298
298
  ) -> moderngl.Texture:
299
299
  """
@@ -65,7 +65,7 @@ class BreathingFrame(OpenglNodeBase):
65
65
 
66
66
  def process(
67
67
  self,
68
- input: Union[moderngl.Texture, 'VideoFrame', 'np.ndarray'],
68
+ input: Union[moderngl.Texture, 'np.ndarray'],
69
69
  t: float = 0.0,
70
70
  ) -> moderngl.Texture:
71
71
  """
@@ -165,7 +165,7 @@ class HandheldFrame(OpenglNodeBase):
165
165
 
166
166
  def process(
167
167
  self,
168
- input: Union[moderngl.Texture, 'VideoFrame', 'np.ndarray'],
168
+ input: Union[moderngl.Texture, np.ndarray],
169
169
  t: float = 0.0,
170
170
  ) -> moderngl.Texture:
171
171
  """
@@ -351,7 +351,7 @@ class OrbitingFrame(OpenglNodeBase):
351
351
 
352
352
  def process(
353
353
  self,
354
- input: Union[moderngl.Texture, 'VideoFrame', 'np.ndarray'],
354
+ input: Union[moderngl.Texture, np.ndarray],
355
355
  t: float = 0.0,
356
356
  ) -> moderngl.Texture:
357
357
  """
@@ -446,7 +446,7 @@ class RotatingInCenterFrame(OpenglNodeBase):
446
446
 
447
447
  def process(
448
448
  self,
449
- input: Union[moderngl.Texture, 'VideoFrame', 'np.ndarray'],
449
+ input: Union[moderngl.Texture, np.ndarray],
450
450
  t: float = 0.0,
451
451
  ) -> moderngl.Texture:
452
452
  """
@@ -636,7 +636,7 @@ class StrangeTvFrame(OpenglNodeBase):
636
636
 
637
637
  def process(
638
638
  self,
639
- input: Union[moderngl.Texture, 'VideoFrame', 'np.ndarray'],
639
+ input: Union[moderngl.Texture, np.ndarray],
640
640
  t: float = 0.0,
641
641
  ) -> moderngl.Texture:
642
642
  """
@@ -744,7 +744,7 @@ class GlitchRgbFrame(OpenglNodeBase):
744
744
 
745
745
  def process(
746
746
  self,
747
- input: Union[moderngl.Texture, 'VideoFrame', 'np.ndarray'],
747
+ input: Union[moderngl.Texture, np.ndarray],
748
748
  t: float = 0.0,
749
749
  ) -> moderngl.Texture:
750
750
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: yta-video-opengl
3
- Version: 0.0.25
3
+ Version: 0.0.27
4
4
  Summary: Youtube Autonomous Video OpenGL Module
5
5
  Author: danialcala94
6
6
  Author-email: danielalcalavalera@gmail.com
@@ -0,0 +1,13 @@
1
+ yta_video_opengl/__init__.py,sha256=ycAx_XYMVDfkuObSvtW6irQ0Wo-fgxEz3fjIRMe8PpY,205
2
+ yta_video_opengl/effects.py,sha256=292IfC1eGDXILkXlo5yUjFFyW7eYevM96V0Ncgnmk2o,11980
3
+ yta_video_opengl/nodes/__init__.py,sha256=X5vmJChn9LJa-u5n6Ch1xS9lVL5mgn7Yw2Qm0x3rO_s,4443
4
+ yta_video_opengl/nodes/audio/__init__.py,sha256=LnGes6u1K0pa4CXP0LrHftLwv0zi-JYvHmYEkJqw_J8,3302
5
+ yta_video_opengl/nodes/video/__init__.py,sha256=I6F4JRNFKsj1jjy-nXoD9hj7rA47DtAIhAk6-m6vgjY,948
6
+ yta_video_opengl/nodes/video/opengl/__init__.py,sha256=nqe803cLoxE0NVMadYU8fgdEXrocDjoD-NEZvs1lERw,8542
7
+ yta_video_opengl/nodes/video/opengl/experimental.py,sha256=9MPudKhl_mDjOyVj89GGLJUVW2esc0PK15EsRpijtzI,22064
8
+ yta_video_opengl/tests.py,sha256=OPD1Caxt-VYHOtgjIhSfG8pqu8YMREgNsEUBZ22kd3o,24256
9
+ yta_video_opengl/utils.py,sha256=w6jYnZcBYPNAsTolkAlA6dxph0u_8-mcUzKvADlIlW8,3098
10
+ yta_video_opengl-0.0.27.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
11
+ yta_video_opengl-0.0.27.dist-info/METADATA,sha256=MBxK-ZXJ1lbD0ot0SUGOvhVmmjmA4kQgnhDv5xcMVQo,589
12
+ yta_video_opengl-0.0.27.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
13
+ yta_video_opengl-0.0.27.dist-info/RECORD,,
@@ -1,13 +0,0 @@
1
- yta_video_opengl/__init__.py,sha256=ycAx_XYMVDfkuObSvtW6irQ0Wo-fgxEz3fjIRMe8PpY,205
2
- yta_video_opengl/effects.py,sha256=ySXlkUzFIAbnM8_j3ckqao4s0lvUib1e07e_p9HTjOs,10489
3
- yta_video_opengl/nodes/__init__.py,sha256=mDqQBfOjDKqPqp_CNY38ROM_5lhyzQ9AgT0pRswpYUY,4464
4
- yta_video_opengl/nodes/audio/__init__.py,sha256=7YQgWjX4sYy26mI03W1BEQZ7COKHSKZzcelPKvD7oJI,6097
5
- yta_video_opengl/nodes/video/__init__.py,sha256=I6F4JRNFKsj1jjy-nXoD9hj7rA47DtAIhAk6-m6vgjY,948
6
- yta_video_opengl/nodes/video/opengl/__init__.py,sha256=bVPdS_wpz4HNurmLRDEHUmNZU7Qz8LptKfJ9yN_2PJM,8587
7
- yta_video_opengl/nodes/video/opengl/experimental.py,sha256=XuriXcOuJU5P0FruKffudCpMuO-ht8weJud88Qn8GKk,22158
8
- yta_video_opengl/tests.py,sha256=OPD1Caxt-VYHOtgjIhSfG8pqu8YMREgNsEUBZ22kd3o,24256
9
- yta_video_opengl/utils.py,sha256=w6jYnZcBYPNAsTolkAlA6dxph0u_8-mcUzKvADlIlW8,3098
10
- yta_video_opengl-0.0.25.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
11
- yta_video_opengl-0.0.25.dist-info/METADATA,sha256=B-rc8f1xDeLaJLsfFmQ6UOcerV3l5k3p-LtzCY4Dmss,589
12
- yta_video_opengl-0.0.25.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
13
- yta_video_opengl-0.0.25.dist-info/RECORD,,