omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Screen recording in scene

    Pythonista
    7
    8
    4342
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DarthXander
      DarthXander last edited by

      It is possible to record a scene, or a Node and its descendants? I know you can access a Texture object of a Node, but this object appears to be uneditable, and un-transferable to either pixel data or to write to a file.

      1 Reply Last reply Reply Quote 0
      • zipit
        zipit last edited by zipit

        This post is deleted!
        1 Reply Last reply Reply Quote 0
        • ccc
          ccc last edited by

          Record as a still image or as a video?

          https://forum.omz-software.com/search/draw_snapshot?in=titlesposts

          1 Reply Last reply Reply Quote 0
          • DarthXander
            DarthXander last edited by

            Ah thank you, this could work! As long as it's fast enough to work every frame... I could of course just slow it down.

            1 Reply Last reply Reply Quote 0
            • omz
              omz last edited by

              The draw_snapshot method is fine for static screenshots, but not nearly fast enough to record video.

              You can use objc_util to bridge the native ReplayKit framework. Here's a demo of that. It includes a very simple scene with some rotating space ships, just to have something to record... In this example, the recording is started in the scene's setup method, and stopped in its stop method (which is called automatically when the scene is about to be closed).

              from objc_util import *
              from scene import *
              import random
              
              load_framework('ReplayKit')
              RPScreenRecorder = ObjCClass('RPScreenRecorder')
              
              def previewControllerDidFinish_(_self, _cmd, _vc):
              	ObjCInstance(_vc).dismissViewControllerAnimated_completion_(True, None)
              
              PreviewDelegate = create_objc_class('PreviewDelegate', methods=[previewControllerDidFinish_])
              
              def stop_callback(_cmd, _vc):
              	vc = ObjCInstance(_vc)
              	delegate = PreviewDelegate.new().autorelease()
              	vc.setPreviewControllerDelegate_(delegate)
              	rootvc = UIApplication.sharedApplication().keyWindow().rootViewController()
              	vc.popoverPresentationController().setSourceView_(rootvc.view())
              	rootvc.presentViewController_animated_completion_(vc, True, None)
              	
              stop_handler = ObjCBlock(stop_callback, restype=None, argtypes=[c_void_p, c_void_p])
              recorder = RPScreenRecorder.sharedRecorder()
              
              @on_main_thread
              def start_recording():
              	recorder.startRecordingWithMicrophoneEnabled_handler_(False, None)
              
              @on_main_thread
              def stop_recording():
              	recorder.stopRecordingWithHandler_(stop_handler)
              
              
              class MyScene (Scene):
              	def setup(self):
              		start_recording()
              		for i in range(25):
              			s = SpriteNode('spc:PlayerShip2Orange', position=(random.uniform(0, self.size.w), random.uniform(0, self.size.h)), parent=self)
              			s.run_action(Action.repeat(Action.rotate_by(1, random.uniform(0.2, 0.8)), 0))
              			
              	def stop(self):
              		stop_recording()
              
              run(MyScene())
              
              
              1 Reply Last reply Reply Quote 1
              • jmv38
                jmv38 last edited by

                awsome! thanks for this example.

                1 Reply Last reply Reply Quote 0
                • Yilia
                  Yilia last edited by

                  This post is deleted!
                  1 Reply Last reply Reply Quote 0
                  • ciderpunk
                    ciderpunk last edited by

                    This post is deleted!
                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post
                    Powered by NodeBB Forums | Contributors