Beispiel #1
0
    def make_video(self, video_function, **kwargs):
        """
        Let's users use a custom function to create the video.
        The custom function must:
            - have a 'scene' keyword argument to accept a Scene() instance
            - have a 'videomaker' keyword argument to accept the CustomVideoMaker (self) instance
            - have a 'video' keyword that takes the Video argument
            - return the instance of Video

        The custom function can manipulate actors and camera in the scene and 
        add frames to the video with 'video.addFrame()'. 
        Once all frames are ready it has to return the video object 
        so that the video can be closed and saved.     

        :param video_function: custom function used to generate the video's frames

        see: examples/advanced/custom_videomaker.py

        """
        self.parse_kwargs(**kwargs)

        curdir = os.getcwd(
        )  # we need to cd to the folder where the video is saved and then back here
        os.chdir(self.save_fld)

        # Create video
        video = Video(name=self.save_name,
                      duration=self.duration,
                      fps=self.fps)

        # run custom function
        video = video_function(scene=self.scene, video=video, videomaker=self)

        # Check output
        if video is None or not isinstance(video, Video):
            raise ValueError(
                "The custom video function didn't return anything " +
                "or it returned something other than the instance of Video " +
                "It must return the video object so that it can be closed properly."
            )
        if not isinstance(video, Video):
            raise ValueError(
                f"The custom video function returned invalid objects: {video} instead of video object"
            )

        # close video
        video.close()
Beispiel #2
0
    def make_video_custom(self, videofunc):
        """
        Let's users use a custom function to create the video. This function can do any manipulation of
        video frames it wants, but it MUST have 'scene' and 'video' keyword arguments. The function must also return video object.

        :param videofunc: function
        """
        self._setup_videos()

        # open a video file and force it to last 3 seconds in total
        video = Video(name=self.savefile, duration=self.duration, fps=self.fps)

        # run custom function
        video = videofunc(scene=self, video=video)

        if video is None: raise ValueError("The custom video function didn't return anything. It must return the video object so that it can be closed properly.")

        # close video
        video.close()  
Beispiel #3
0
    def make_video(self, video_function, **kwargs):
        """
        Let's users use a custom function to create the video.
        The custom function must:
            - have a 'scene' keyword argument to accept a Scene() instance
            - have a 'video' keyword argument to accept a Video() instance
            - return the instance of Video

        The custom function can manipulate actors and camera in the scene and 
        add frames to the video with 'video.addFrame()'. 
        Once all frames are ready it has to return the video object 
        so that the video can be closed and saved.     

        """
        self.parse_kwargs(**kwargs)

        curdir = os.getcwd(
        )  # we need to cd to the folder where the video is saved and then back here
        os.chdir(self.save_fld)

        # Create video
        video = Video(name=self.save_name + self.video_format,
                      duration=self.duration,
                      fps=self.fps)

        # run custom function
        video = videofunc(scene=self.scene, video=video)

        # Check output
        if video is None:
            raise ValueError(
                "The custom video function didn't return anything." +
                "It must return the video object so that it can be closed properly."
            )
        if not isinstance(video, Video):
            raise ValueError(
                f"The custom video function returned invalid objects: {video} instead of video object"
            )

        # close video
        video.close()
Beispiel #4
0
    def make_video(self, azimuth=0, elevation=0, roll=0):
        """
        Creates a video using user defined parameters
    
        :param azimuth: integer, specify the rotation in degrees per frame on the relative axis. (Default value = 0)
        :param elevation: integer, specify the rotation in degrees per frame on the relative axis. (Default value = 0)
        :param roll: integer, specify the rotation in degrees per frame on the relative axis. (Default value = 0)

        """
        self._setup_videos()

        # open a video file and force it to last 3 seconds in total
        # folder = os.path.dirname(self.savefile)
        # name = os.path.basename(self.savefile)
        # curdir = os.getcwd()
        # os.chdir(folder)
        video = Video(name=self.savefile, duration=self.duration, fps=self.fps)

        for i in range(self.niters):
            self.scene.plotter.show()  # render the scene first
            self.scene.plotter.camera.Elevation(elevation)
            self.scene.plotter.camera.Azimuth(azimuth)
            self.scene.plotter.camera.Roll(roll)
            video.addFrame()
        video.close()  # merge all the recorded frames
        os.chdir(curdir)
Beispiel #5
0
    def make_video(self, azimuth=0, elevation=0, roll=0, **kwargs):
        """
        Creates a video using user defined parameters

        :param azimuth: integer, specify the rotation in degrees per frame on the relative axis. (Default value = 0)
        :param elevation: integer, specify the rotation in degrees per frame on the relative axis. (Default value = 0)
        :param roll: integer, specify the rotation in degrees per frame on the relative axis. (Default value = 0)
        :param kwargs: use to change destination folder, video name, fps, duration ... check 'self.parse_kwargs' for details. 
        """
        self.parse_kwargs(**kwargs)

        curdir = os.getcwd(
        )  # we need to cd to the folder where the video is saved and then back here
        os.chdir(self.save_fld)
        print(f"Saving video in {self.save_fld}")

        # Create video
        video = Video(name=self.save_name,
                      duration=self.duration,
                      fps=self.fps)

        # Render the scene first
        self.scene.render(interactive=False)

        # Make frames
        for i in range(self.niters):
            self.scene.plotter.show(
            )  # render(interactive=False, video=True)  # render the scene first
            self.scene.plotter.camera.Elevation(elevation)
            self.scene.plotter.camera.Azimuth(azimuth)
            self.scene.plotter.camera.Roll(roll)
            video.addFrame()
        video.close()  # merge all the recorded frames

        # Cd bake to original dir
        os.chdir(curdir)
Beispiel #6
0
"""
Make a video (needs ffmpeg)
 Set offscreen=True to only produce the video 
 without any graphical window showing
"""
print(__doc__)
from vtkplotter import Plotter, Video, datadir

# declare the class instance
vp = Plotter(axes=0, interactive=0, offscreen=False)

vp.load(datadir + "shapes/spider.ply", texture="leather2", alpha=1)

# open a video file and force it to last 3 seconds in total
video = Video(name="spider.mp4", duration=3)

for i in range(100):
    vp.show()  # render the scene first
    vp.camera.Azimuth(2)  # rotate by 5 deg at each iteration
    video.addFrame()

video.close()  # merge all the recorded frames

vp.show(interactive=1)