marcomusy / vedo

A python module for scientific analysis of 3D data based on VTK and Numpy
https://vedo.embl.es
MIT License
2.05k stars 266 forks source link

makeVideo.py not working... #986

Open jsanchez679 opened 11 months ago

jsanchez679 commented 11 months ago

Hi @marcomusy , I was trying the makeVideo.py example file and I am getting an error. The code I am using is:

"""Make a video file with or without graphic window"""
from vedo import dataurl, Plotter, Mesh, Video

# settings.screeshot_scale = 2  # to get higher resolution

msh = Mesh(dataurl+"spider.ply").rotate_x(-90)
msh.texture(dataurl+"textures/leather.jpg")

plt = Plotter(bg="beige", bg2="lb", axes=10, offscreen=False)
plt += [msh, __doc__]

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

##############################################################
# Any rendering loop goes here, e.g.:
for i in range(80):
    plt.show(elevation=1, azimuth=2)  # render the scene
    video.add_frame()                 # add individual frame

video.close()  # merge all the recorded frames and write to disk

plt.interactive().close()

and the error I am getting is:

AttributeError                            Traceback (most recent call last)
Untitled-1 in line 19
     [16](untitled:Untitled-1?line=15) ##############################################################
     [17](untitled:Untitled-1?line=16) # Any rendering loop goes here, e.g.:
     [18](untitled:Untitled-1?line=17) for i in range(80):
---> [19](untitled:Untitled-1?line=18)     plt.show(elevation=1, azimuth=2)  # render the scene
     [20](untitled:Untitled-1?line=19)     video.add_frame()                 # add individual frame
     [22](untitled:Untitled-1?line=21) video.close()  # merge all the recorded frames and write to disk

File [d:\Applications\Miniconda\envs\mH_gui2\lib\site-packages\vedo\plotter.py:2913](file:///D:/Applications/Miniconda/envs/mH_gui2/lib/site-packages/vedo/plotter.py:2913), in Plotter.show(self, at, axes, resetcam, zoom, interactive, viewup, azimuth, elevation, roll, camera, mode, rate, bg, bg2, size, title, q, *actors)
   [2909](file:///d%3A/Applications/Miniconda/envs/mH_gui2/lib/site-packages/vedo/plotter.py?line=2908)         return backends.get_notebook_backend(self.actors)
   [2910](file:///d%3A/Applications/Miniconda/envs/mH_gui2/lib/site-packages/vedo/plotter.py?line=2909) #########################################################################
   [2911](file:///d%3A/Applications/Miniconda/envs/mH_gui2/lib/site-packages/vedo/plotter.py?line=2910) 
   [2912](file:///d%3A/Applications/Miniconda/envs/mH_gui2/lib/site-packages/vedo/plotter.py?line=2911) # remove all old shadows from the scene
-> [2913](file:///d%3A/Applications/Miniconda/envs/mH_gui2/lib/site-packages/vedo/plotter.py?line=2912) shad_acs = self.renderer.GetActors()
   [2914](file:///d%3A/Applications/Miniconda/envs/mH_gui2/lib/site-packages/vedo/plotter.py?line=2913) shad_acs.InitTraversal()
   [2915](file:///d%3A/Applications/Miniconda/envs/mH_gui2/lib/site-packages/vedo/plotter.py?line=2914) for _ in range(shad_acs.GetNumberOfItems()):

AttributeError: 'NoneType' object has no attribute 'GetActors'

vedo -- info shows this:

vedo version      : 2023.4.4   https://vedo.embl.es
vtk version       : 9.1.0
numpy version     : 1.25.2
python version    : 3.9.18 | packaged by conda-forge | (main, Aug 30 2023, 03:40:31) [MSC v.1929 64 bit (AMD64)]
python interpreter: D:\Applications\Miniconda\envs\mH_gui\python.exe
vedo installation : D:\Applications\Miniconda\envs\mH_gui\lib\site-packages\vedo
system            : Windows 10 nt AMD64
monitor           : info is unavailable. Try "pip install screeninfo".

I was also looking at a closed issue ( #504 ) and realised it is possible to create a video of rotating meshes having different subplots. Can you please provide me with an example to do this?

Thanks in advance! Juliana

marcomusy commented 11 months ago

Hi Juliana I suggest to upgrade to a newer version

pip install vtk -U
pip install vedo -U
pip install imageio[ffmpeg]

then e.g.:


from vedo import dataurl, Plotter, Mesh, Video

msh = Mesh(dataurl+"spider.ply").rotate_x(-90)
msh.texture(dataurl+"textures/leather.jpg")

plt = Plotter(bg="beige", bg2="lb", interactive=False)
plt += [msh]
plt.show()  # render the scene

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

# Any rendering loop goes here, e.g.:
for i in range(80):
    plt.azimuth(2).elevation(1)
    video.add_frame() # add individual frame
video.close() # merge all the recorded frames and write to disk
print("done.")

plt.interactive().close()