yta-video-opengl 0.0.23__py3-none-any.whl → 0.0.25__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_opengl/tests.py CHANGED
@@ -565,204 +565,208 @@ NUMPY_FORMAT = 'rgb24'
565
565
  # print(f'Saved as "{self.output_filename}".')
566
566
 
567
567
 
568
- # def video_modified_stored():
569
- # # This path below was trimmed in an online platform
570
- # # and seems to be bad codified and generates error
571
- # # when processing it, but it is readable in the
572
- # # file explorer...
573
- # #VIDEO_PATH = 'test_files/test_1_short_broken.mp4'
574
- # # This is short but is working well
575
- # VIDEO_PATH = "test_files/test_1_short_2.mp4"
576
- # # Long version below, comment to test faster
577
- # #VIDEO_PATH = "test_files/test_1.mp4"
578
- # OUTPUT_PATH = "test_files/output.mp4"
579
- # # TODO: This has to be dynamic, but
580
- # # according to what (?)
581
- # NUMPY_FORMAT = 'rgb24'
582
- # # TODO: Where do we obtain this from (?)
583
- # VIDEO_CODEC_NAME = 'libx264'
584
- # # TODO: Where do we obtain this from (?)
585
- # PIXEL_FORMAT = 'yuv420p'
586
-
587
- # from yta_video_opengl.classes import WavingFrame, BreathingFrame, HandheldFrame, OrbitingFrame, RotatingInCenterFrame, StrangeTvFrame, GlitchRgbFrame, WavingNode
588
- # from yta_video_opengl.utils import texture_to_frame, frame_to_texture
589
-
590
- # video = VideoReader(VIDEO_PATH)
591
- # video_writer = (
592
- # VideoWriter(OUTPUT_PATH)
593
- # #.set_video_stream(VIDEO_CODEC_NAME, video.fps, video.size, PIXEL_FORMAT)
594
- # .set_video_stream_from_template(video.video_stream)
595
- # .set_audio_stream_from_template(video.audio_stream)
596
- # )
568
+ def video_modified_stored():
569
+ # This path below was trimmed in an online platform
570
+ # and seems to be bad codified and generates error
571
+ # when processing it, but it is readable in the
572
+ # file explorer...
573
+ #VIDEO_PATH = 'test_files/test_1_short_broken.mp4'
574
+ # This is short but is working well
575
+ VIDEO_PATH = "test_files/test_1_short_2.mp4"
576
+ # Long version below, comment to test faster
577
+ #VIDEO_PATH = "test_files/test_1.mp4"
578
+ OUTPUT_PATH = "test_files/output.mp4"
579
+ # TODO: This has to be dynamic, but
580
+ # according to what (?)
581
+ NUMPY_FORMAT = 'rgb24'
582
+ # TODO: Where do we obtain this from (?)
583
+ VIDEO_CODEC_NAME = 'libx264'
584
+ # TODO: Where do we obtain this from (?)
585
+ PIXEL_FORMAT = 'yuv420p'
586
+
587
+ from yta_video_opengl.utils import texture_to_frame, frame_to_texture
588
+
589
+ #from yta_video_pyav.video import Video
590
+
591
+ #video = Video(VIDEO_PATH)
592
+
593
+ #effect = WavingFrame(size = video.size)
594
+ #effect = BreathingFrame(size = video.size)
595
+ #effect = HandheldFrame(size = video.size)
596
+ # effect = OrbitingFrame(
597
+ # size = video.size,
598
+ # first_frame = video.next_frame
599
+ # )
600
+ # effect = RotatingInCenterFrame(
601
+ # size = video.size,
602
+ # first_frame = video.next_frame
603
+ # )
604
+
605
+ # effect = GlitchRgbFrame(
606
+ # size = video.size,
607
+ # first_frame = video.next_frame
608
+ # )
609
+ from yta_video_opengl.effects import Effects
610
+
611
+ editor = Effects()
612
+ # waving_node_effect = editor.effects.video.waving_node(video.size, amplitude = 0.2, frequency = 9, speed = 3)
613
+ # chorus_effect = editor.effects.audio.chorus(audio.sample_rate)
614
+ # print(waving_node_effect)
597
615
 
598
- # #effect = WavingFrame(size = video.size)
599
- # #effect = BreathingFrame(size = video.size)
600
- # #effect = HandheldFrame(size = video.size)
601
- # # effect = OrbitingFrame(
602
- # # size = video.size,
603
- # # first_frame = video.next_frame
604
- # # )
605
- # # effect = RotatingInCenterFrame(
606
- # # size = video.size,
607
- # # first_frame = video.next_frame
608
- # # )
609
- # effect = GlitchRgbFrame(
610
- # size = video.size,
611
- # first_frame = video.next_frame
612
- # )
613
- # context = moderngl.create_context(standalone = True)
616
+ # New way, with nodes
617
+ # context = moderngl.create_context(standalone = True)
618
+ # node = WavingNode(context, video.size, amplitude = 0.2, frequency = 9, speed = 3)
619
+ # print(node.process(video.get_frame_from_t(0)))
620
+ # We need to reset it to being again pointing
621
+ # to the first frame...
622
+ # TODO: Improve this by, maybe, storing the first
623
+ # frame in memory so we can append it later, or
624
+ # using the '.seek(0)' even when it could be not
625
+ # accurate
626
+ #video.reset()
627
+
628
+ # # TODO: By now this is applying an effect
629
+ # # by default
630
+ # VideoProcessor(
631
+ # filename = VIDEO_PATH,
632
+ # output_filename = OUTPUT_PATH
633
+ # ).process()
634
+
635
+ # return
636
+
637
+ return
614
638
 
615
- # # New way, with nodes
616
- # node = WavingNode(context, video.size, amplitude = 0.2, frequency = 9, speed = 3)
617
- # # We need to reset it to being again pointing
618
- # # to the first frame...
619
- # # TODO: Improve this by, maybe, storing the first
620
- # # frame in memory so we can append it later, or
621
- # # using the '.seek(0)' even when it could be not
622
- # # accurate
623
- # video.reset()
624
-
625
- # # # TODO: By now this is applying an effect
626
- # # # by default
627
- # # VideoProcessor(
628
- # # filename = VIDEO_PATH,
629
- # # output_filename = OUTPUT_PATH
630
- # # ).process()
631
-
632
- # # return
633
-
634
-
635
- # AMP = 0.05
636
- # FREQ = 10.0
637
- # SPEED = 2.0
638
-
639
- # # Get the information about the video
640
- # video = VideoReader(VIDEO_PATH)
641
-
642
- # # ModernGL context without window
643
- # context = moderngl.create_standalone_context()
644
-
645
- # waving_frame_effect = WavingFrame(
646
- # context = context,
647
- # frame_size = video.size
648
- # )
649
-
650
- # vao = waving_frame_effect.vao
651
-
652
- # # TODO: This has to be dynamic, but
653
- # # according to what (?)
654
- # NUMPY_FORMAT = 'rgb24'
655
- # # TODO: Where do we obtain this from (?)
656
- # VIDEO_CODEC_NAME = 'libx264'
657
- # # TODO: Where do we obtain this from (?)
658
- # PIXEL_FORMAT = 'yuv420p'
659
-
660
- # # Framebuffer to render
661
- # fbo = waving_frame_effect.fbo
662
- # fbo.use()
663
-
664
- # # Decode first frame and use as texture
665
- # first_frame = video.next_frame
666
- # # We need to reset it to being again pointing
667
- # # to the first frame...
668
- # # TODO: Improve this by, maybe, storing the first
669
- # # frame in memory so we can append it later, or
670
- # # using the '.seek(0)' even when it could be not
671
- # # accurate
672
- # video = VideoReader(VIDEO_PATH)
673
-
674
- # # Most of OpenGL textures expect origin in lower
675
- # # left corner
676
- # # TODO: What if alpha (?)
677
- # # TODO: Move this to the OpenglFrameEffect maybe (?)
639
+ AMP = 0.05
640
+ FREQ = 10.0
641
+ SPEED = 2.0
642
+
643
+ # Get the information about the video
644
+ video = VideoReader(VIDEO_PATH)
645
+
646
+ # ModernGL context without window
647
+ context = moderngl.create_standalone_context()
648
+
649
+ waving_frame_effect = WavingFrame(
650
+ context = context,
651
+ frame_size = video.size
652
+ )
653
+
654
+ vao = waving_frame_effect.vao
655
+
656
+ # TODO: This has to be dynamic, but
657
+ # according to what (?)
658
+ NUMPY_FORMAT = 'rgb24'
659
+ # TODO: Where do we obtain this from (?)
660
+ VIDEO_CODEC_NAME = 'libx264'
661
+ # TODO: Where do we obtain this from (?)
662
+ PIXEL_FORMAT = 'yuv420p'
663
+
664
+ # Framebuffer to render
665
+ fbo = waving_frame_effect.fbo
666
+ fbo.use()
667
+
668
+ # Decode first frame and use as texture
669
+ first_frame = video.next_frame
670
+ # We need to reset it to being again pointing
671
+ # to the first frame...
672
+ # TODO: Improve this by, maybe, storing the first
673
+ # frame in memory so we can append it later, or
674
+ # using the '.seek(0)' even when it could be not
675
+ # accurate
676
+ video = VideoReader(VIDEO_PATH)
677
+
678
+ # Most of OpenGL textures expect origin in lower
679
+ # left corner
680
+ # TODO: What if alpha (?)
681
+ # TODO: Move this to the OpenglFrameEffect maybe (?)
678
682
 
679
- # texture: moderngl.Texture = frame_to_texture(first_frame, waving_frame_effect.context)
680
- # texture.build_mipmaps()
681
-
682
- # # These properties can be set before
683
- # # iterating the frames or maybe for
684
- # # each iteration... depending on the
685
- # # effect.
686
- # # Uniforms (properties)
687
- # (
688
- # waving_frame_effect
689
- # .set_value('amp', AMP)
690
- # .set_value('freq', FREQ)
691
- # .set_value('speed', SPEED)
692
- # )
693
-
694
- # # Writer with H.264 codec
695
- # video_writer = (
696
- # VideoWriter(OUTPUT_PATH)
697
- # .set_video_stream(VIDEO_CODEC_NAME, video.fps, video.size, PIXEL_FORMAT)
698
- # .set_audio_stream_from_template(video.audio_stream)
699
- # )
700
-
701
- # frame_index = 0
702
- # for frame_or_packet in video.iterate_with_audio(
703
- # do_decode_video = True,
704
- # do_decode_audio = False
705
- # ):
706
- # # This below is because of the parameters we
707
- # # passed to the method
708
- # is_video_frame = PythonValidator.is_instance_of(frame_or_packet, 'VideoReaderFrame')
709
- # is_audio_packet = PythonValidator.is_instance_of(frame_or_packet, 'VideoReaderPacket')
710
-
711
- # # To simplify the process
712
- # if frame_or_packet is not None:
713
- # frame_or_packet = frame_or_packet.data
714
-
715
- # if is_audio_packet:
716
- # video_writer.mux(frame_or_packet)
717
- # elif is_video_frame:
718
- # with Timer(is_silent_as_context = True) as timer:
719
-
720
- # def process_frame(
721
- # frame: 'VideoFrame'
722
- # ):
723
- # # Add some variables if we need, for the
724
- # # opengl change we are applying (check the
725
- # # program code)
726
- # waving_frame_effect.set_value('time', T.video_frame_index_to_video_frame_time(frame_index, float(video.fps)))
683
+ texture: moderngl.Texture = frame_to_texture(first_frame, waving_frame_effect.context)
684
+ texture.build_mipmaps()
685
+
686
+ # These properties can be set before
687
+ # iterating the frames or maybe for
688
+ # each iteration... depending on the
689
+ # effect.
690
+ # Uniforms (properties)
691
+ (
692
+ waving_frame_effect
693
+ .set_value('amp', AMP)
694
+ .set_value('freq', FREQ)
695
+ .set_value('speed', SPEED)
696
+ )
697
+
698
+ # Writer with H.264 codec
699
+ video_writer = (
700
+ VideoWriter(OUTPUT_PATH)
701
+ .set_video_stream(VIDEO_CODEC_NAME, video.fps, video.size, PIXEL_FORMAT)
702
+ .set_audio_stream_from_template(video.audio_stream)
703
+ )
704
+
705
+ frame_index = 0
706
+ for frame_or_packet in video.iterate_with_audio(
707
+ do_decode_video = True,
708
+ do_decode_audio = False
709
+ ):
710
+ # This below is because of the parameters we
711
+ # passed to the method
712
+ is_video_frame = PythonValidator.is_instance_of(frame_or_packet, 'VideoReaderFrame')
713
+ is_audio_packet = PythonValidator.is_instance_of(frame_or_packet, 'VideoReaderPacket')
714
+
715
+ # To simplify the process
716
+ if frame_or_packet is not None:
717
+ frame_or_packet = frame_or_packet.data
718
+
719
+ if is_audio_packet:
720
+ video_writer.mux(frame_or_packet)
721
+ elif is_video_frame:
722
+ with Timer(is_silent_as_context = True) as timer:
723
+
724
+ def process_frame(
725
+ frame: 'VideoFrame'
726
+ ):
727
+ # Add some variables if we need, for the
728
+ # opengl change we are applying (check the
729
+ # program code)
730
+ waving_frame_effect.set_value('time', T.video_frame_index_to_video_frame_time(frame_index, float(video.fps)))
727
731
 
728
- # # Create texture
729
- # texture = frame_to_texture(frame, waving_frame_effect.context)
730
- # texture.use()
731
-
732
- # # Render with shader to frame buffer
733
- # fbo.use()
734
- # vao.render(moderngl.TRIANGLE_STRIP)
735
-
736
- # # Processed GPU result to numpy
737
- # processed_data = np.frombuffer(
738
- # fbo.read(components = 3, alignment = 1), dtype = np.uint8
739
- # )
740
-
741
- # # Invert numpy to normal frame
742
- # # TODO: Can I use the texture.size to fill
743
- # # these 'img_array.shape[0]' (?)
744
- # processed_data = np.flipud(
745
- # processed_data.reshape((texture.size[1], texture.size[0], 3))
746
- # )
747
-
748
- # # To VideoFrame and to buffer
749
- # frame = av.VideoFrame.from_ndarray(processed_data, format = NUMPY_FORMAT)
750
- # # TODO: What is this for (?)
751
- # #out_frame.pict_type = 'NONE'
752
- # return frame
753
-
754
- # video_writer.mux_video_frame(process_frame(frame_or_packet))
755
-
756
- # print(f'Frame {str(frame_index)}: {timer.time_elapsed_str}s')
757
- # frame_index += 1
758
-
759
- # # While this code can be finished, the work in
760
- # # the muxer could be not finished and have some
761
- # # packets waiting to be written. Here we tell
762
- # # the muxer to process all those packets.
763
- # video_writer.mux_video_frame(None)
764
-
765
- # # TODO: Maybe move this to the '__del__' (?)
766
- # video_writer.output.close()
767
- # video.container.close()
768
- # print(f'Saved as "{OUTPUT_PATH}".')
732
+ # Create texture
733
+ texture = frame_to_texture(frame, waving_frame_effect.context)
734
+ texture.use()
735
+
736
+ # Render with shader to frame buffer
737
+ fbo.use()
738
+ vao.render(moderngl.TRIANGLE_STRIP)
739
+
740
+ # Processed GPU result to numpy
741
+ processed_data = np.frombuffer(
742
+ fbo.read(components = 3, alignment = 1), dtype = np.uint8
743
+ )
744
+
745
+ # Invert numpy to normal frame
746
+ # TODO: Can I use the texture.size to fill
747
+ # these 'img_array.shape[0]' (?)
748
+ processed_data = np.flipud(
749
+ processed_data.reshape((texture.size[1], texture.size[0], 3))
750
+ )
751
+
752
+ # To VideoFrame and to buffer
753
+ frame = av.VideoFrame.from_ndarray(processed_data, format = NUMPY_FORMAT)
754
+ # TODO: What is this for (?)
755
+ #out_frame.pict_type = 'NONE'
756
+ return frame
757
+
758
+ video_writer.mux_video_frame(process_frame(frame_or_packet))
759
+
760
+ print(f'Frame {str(frame_index)}: {timer.time_elapsed_str}s')
761
+ frame_index += 1
762
+
763
+ # While this code can be finished, the work in
764
+ # the muxer could be not finished and have some
765
+ # packets waiting to be written. Here we tell
766
+ # the muxer to process all those packets.
767
+ video_writer.mux_video_frame(None)
768
+
769
+ # TODO: Maybe move this to the '__del__' (?)
770
+ video_writer.output.close()
771
+ video.container.close()
772
+ print(f'Saved as "{OUTPUT_PATH}".')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: yta-video-opengl
3
- Version: 0.0.23
3
+ Version: 0.0.25
4
4
  Summary: Youtube Autonomous Video OpenGL Module
5
5
  Author: danialcala94
6
6
  Author-email: danielalcalavalera@gmail.com
@@ -9,6 +9,7 @@ Classifier: Programming Language :: Python :: 3
9
9
  Classifier: Programming Language :: Python :: 3.9
10
10
  Requires-Dist: moderngl (>=0.0.1,<9.0.0)
11
11
  Requires-Dist: numpy (>=0.0.1,<9.0.0)
12
+ Requires-Dist: yta_programming (>=0.0.1,<1.0.0)
12
13
  Requires-Dist: yta_validation (>=0.0.1,<1.0.0)
13
14
  Description-Content-Type: text/markdown
14
15
 
@@ -0,0 +1,13 @@
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,,