yta-video-opengl 0.0.1__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.
@@ -0,0 +1,12 @@
1
+ """
2
+ Module to include video handling with OpenGL.
3
+ """
4
+ def main():
5
+ from yta_video_opengl.tests import video_modified_displayed_on_window, video_modified_stored
6
+
7
+ #video_modified_displayed_on_window()
8
+ video_modified_stored()
9
+
10
+
11
+ if __name__ == '__main__':
12
+ main()
@@ -0,0 +1,224 @@
1
+ """
2
+ Manual tests that are working and are interesting
3
+ to learn about the code, refactor and build
4
+ classes.
5
+ """
6
+ import av
7
+ import glfw
8
+ import moderngl
9
+ import numpy as np
10
+ from PIL import Image
11
+ import time
12
+
13
+
14
+ def video_modified_displayed_on_window():
15
+ # -------- CONFIG --------
16
+ VIDEO_PATH = "test_files/test_1.mp4" # Cambia por tu vídeo
17
+ AMP = 0.05
18
+ FREQ = 10.0
19
+ SPEED = 2.0
20
+ # ------------------------
21
+
22
+ # Inicializar ventana GLFW
23
+ if not glfw.init():
24
+ raise RuntimeError("No se pudo inicializar GLFW")
25
+
26
+ window = glfw.create_window(1280, 720, "Wave Shader Python", None, None)
27
+ if not window:
28
+ glfw.terminate()
29
+ raise RuntimeError("No se pudo crear ventana GLFW")
30
+
31
+ glfw.make_context_current(window)
32
+ ctx = moderngl.create_context()
33
+
34
+ # Shader GLSL
35
+ prog = ctx.program(
36
+ vertex_shader='''
37
+ #version 330
38
+ in vec2 in_pos;
39
+ in vec2 in_uv;
40
+ out vec2 v_uv;
41
+ void main() {
42
+ v_uv = in_uv;
43
+ gl_Position = vec4(in_pos, 0.0, 1.0);
44
+ }
45
+ ''',
46
+ fragment_shader='''
47
+ #version 330
48
+ uniform sampler2D tex;
49
+ uniform float time;
50
+ uniform float amp;
51
+ uniform float freq;
52
+ uniform float speed;
53
+ in vec2 v_uv;
54
+ out vec4 f_color;
55
+ void main() {
56
+ float wave = sin(v_uv.x * freq + time * speed) * amp;
57
+ vec2 uv = vec2(v_uv.x, v_uv.y + wave);
58
+ f_color = texture(tex, uv);
59
+ }
60
+ '''
61
+ )
62
+
63
+ # Cuadrado a pantalla completa
64
+ vertices = np.array([
65
+ -1, -1, 0.0, 0.0,
66
+ 1, -1, 1.0, 0.0,
67
+ -1, 1, 0.0, 1.0,
68
+ 1, 1, 1.0, 1.0,
69
+ ], dtype='f4')
70
+
71
+ vbo = ctx.buffer(vertices.tobytes())
72
+ vao = ctx.simple_vertex_array(prog, vbo, 'in_pos', 'in_uv')
73
+
74
+ # Abrir vídeo con PyAV
75
+ container = av.open(VIDEO_PATH)
76
+ stream = container.streams.video[0]
77
+ stream.thread_type = "AUTO"
78
+
79
+ # Decodificar primer frame para crear textura
80
+ first_frame = next(container.decode(stream))
81
+ img = first_frame.to_image().transpose(Image.FLIP_TOP_BOTTOM).convert("RGB")
82
+ tex = ctx.texture(img.size, 3, img.tobytes())
83
+ tex.build_mipmaps()
84
+
85
+ # Uniforms fijos
86
+ prog['amp'].value = AMP
87
+ prog['freq'].value = FREQ
88
+ prog['speed'].value = SPEED
89
+
90
+ start_time = time.time()
91
+
92
+ # Render loop
93
+ frame_iter = container.decode(stream)
94
+ for frame in frame_iter:
95
+ if glfw.window_should_close(window):
96
+ break
97
+
98
+ # Tiempo
99
+ t = time.time() - start_time
100
+ prog['time'].value = t
101
+
102
+ # Convertir frame a textura
103
+ img = frame.to_image().transpose(Image.FLIP_TOP_BOTTOM).convert("RGB")
104
+ tex.write(img.tobytes())
105
+
106
+ # Dibujar
107
+ ctx.clear(0.1, 0.1, 0.1)
108
+ tex.use()
109
+ vao.render(moderngl.TRIANGLE_STRIP)
110
+ glfw.swap_buffers(window)
111
+ glfw.poll_events()
112
+
113
+ glfw.terminate()
114
+
115
+ def video_modified_stored():
116
+ VIDEO_PATH = "test_files/test_1.mp4"
117
+ OUTPUT_PATH = "test_files/output.mp4"
118
+ AMP = 0.05
119
+ FREQ = 10.0
120
+ SPEED = 2.0
121
+
122
+ # Crear contexto ModernGL sin ventana
123
+ ctx = moderngl.create_standalone_context()
124
+
125
+ # Shader de onda
126
+ prog = ctx.program(
127
+ vertex_shader='''
128
+ #version 330
129
+ in vec2 in_pos;
130
+ in vec2 in_uv;
131
+ out vec2 v_uv;
132
+ void main() {
133
+ v_uv = in_uv;
134
+ gl_Position = vec4(in_pos, 0.0, 1.0);
135
+ }
136
+ ''',
137
+ fragment_shader='''
138
+ #version 330
139
+ uniform sampler2D tex;
140
+ uniform float time;
141
+ uniform float amp;
142
+ uniform float freq;
143
+ uniform float speed;
144
+ in vec2 v_uv;
145
+ out vec4 f_color;
146
+ void main() {
147
+ float wave = sin(v_uv.x * freq + time * speed) * amp;
148
+ vec2 uv = vec2(v_uv.x, v_uv.y + wave);
149
+ f_color = texture(tex, uv);
150
+ }
151
+ '''
152
+ )
153
+
154
+ # Quad
155
+ vertices = np.array([
156
+ -1, -1, 0.0, 0.0,
157
+ 1, -1, 1.0, 0.0,
158
+ -1, 1, 0.0, 1.0,
159
+ 1, 1, 1.0, 1.0,
160
+ ], dtype='f4')
161
+ vbo = ctx.buffer(vertices.tobytes())
162
+ vao = ctx.simple_vertex_array(prog, vbo, 'in_pos', 'in_uv')
163
+
164
+ # Abrir vídeo de entrada
165
+ container = av.open(VIDEO_PATH)
166
+ stream = container.streams.video[0]
167
+ fps = stream.average_rate
168
+ width = stream.width
169
+ height = stream.height
170
+
171
+ # Framebuffer para renderizar
172
+ fbo = ctx.simple_framebuffer((width, height))
173
+ fbo.use()
174
+
175
+ # Decodificar primer frame y crear textura
176
+ first_frame = next(container.decode(stream))
177
+ img = first_frame.to_image().transpose(Image.FLIP_TOP_BOTTOM).convert("RGB")
178
+ tex = ctx.texture(img.size, 3, img.tobytes())
179
+ tex.build_mipmaps()
180
+
181
+ # Uniforms
182
+ prog['amp'].value = AMP
183
+ prog['freq'].value = FREQ
184
+ prog['speed'].value = SPEED
185
+
186
+ # Abrir salida con PyAV (codificador H.264)
187
+ output = av.open(OUTPUT_PATH, mode='w')
188
+ out_stream = output.add_stream("libx264", rate=fps)
189
+ out_stream.width = width
190
+ out_stream.height = height
191
+ out_stream.pix_fmt = "yuv420p"
192
+
193
+ start_time = time.time()
194
+
195
+ for frame in container.decode(stream):
196
+ t = time.time() - start_time
197
+ prog['time'].value = t
198
+
199
+ # Subir frame a textura
200
+ img = frame.to_image().transpose(Image.FLIP_TOP_BOTTOM).convert("RGB")
201
+ tex.write(img.tobytes())
202
+
203
+ # Renderizar con shader al framebuffer
204
+ fbo.clear(0.0, 0.0, 0.0)
205
+ tex.use()
206
+ vao.render(moderngl.TRIANGLE_STRIP)
207
+
208
+ # Leer píxeles del framebuffer
209
+ data = fbo.read(components=3, alignment=1)
210
+ img_out = Image.frombytes("RGB", (width, height), data).transpose(Image.FLIP_TOP_BOTTOM)
211
+
212
+ # Convertir a frame de PyAV y escribir
213
+ video_frame = av.VideoFrame.from_image(img_out)
214
+ packet = out_stream.encode(video_frame)
215
+ if packet:
216
+ output.mux(packet)
217
+
218
+ # Vaciar buffers de codificación
219
+ packet = out_stream.encode(None)
220
+ if packet:
221
+ output.mux(packet)
222
+
223
+ output.close()
224
+ print(f"Vídeo guardado en {OUTPUT_PATH}")
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2018 The Python Packaging Authority
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.3
2
+ Name: yta-video-opengl
3
+ Version: 0.0.1
4
+ Summary: Youtube Autonomous Video OpenGL Module
5
+ Author: danialcala94
6
+ Author-email: danielalcalavalera@gmail.com
7
+ Requires-Python: ==3.9
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.9
10
+ Requires-Dist: av (>=0.0.1,<19.0.0)
11
+ Requires-Dist: glfw (>=0.0.1,<9.0.0)
12
+ Requires-Dist: moderngl (>=0.0.1,<9.0.0)
13
+ Requires-Dist: numpy (>=0.0.1,<9.0.0)
14
+ Requires-Dist: pillow (>=0.0.1,<19.0.0)
15
+ Requires-Dist: yta_validation (>=0.0.1,<1.0.0)
16
+ Description-Content-Type: text/markdown
17
+
18
+ # Youtube Autonomous Video OpenGL Module
19
+
20
+ The way to handle videos with OpenGL.
@@ -0,0 +1,6 @@
1
+ yta_video_opengl/__init__.py,sha256=Xb1dwLlYPh_sttMNyKsuP81ie5RXhuQf6AM_XvsUuWE,284
2
+ yta_video_opengl/tests.py,sha256=INSGzF7EcYqtUdN4SN39KOmXsAME4Sg7eJFbMmfmXx4,6292
3
+ yta_video_opengl-0.0.1.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
4
+ yta_video_opengl-0.0.1.dist-info/METADATA,sha256=W4DX2yB9bfprIBGH-wgd2B0CM8N6dZlupkkkkKtIirY,653
5
+ yta_video_opengl-0.0.1.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
6
+ yta_video_opengl-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.1.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any