brainglobe / brainrender

a python based software for visualization of neuroanatomical and morphological data.
https://brainglobe.info/documentation/brainrender/index.html
BSD 3-Clause "New" or "Revised" License
544 stars 77 forks source link

VideoMaker ~ actors not rendered bug #45

Closed FedeClaudi closed 4 years ago

FedeClaudi commented 4 years ago

The VideoMaker class is a bit buggy. Some actors (e.g. cells) are not rendered in the video frames. This is probably because in brainrender.scene the vtkplotter plotter is populated with show(*self.get_actors()... while videomaker uses show().

This will be fixed when I update the VideoMaker class (currently under development in the Animation branch), but for now a workaround is to:

  1. render the scene with Scene.render()
  2. Close the scene by pressing 'q'
  3. Use videomaker to crate the video.
youeh1 commented 4 years ago

Thanks for sharing this wonderful codes.

I am trying to make a video, but there's an error while I running "from brainrender.Utils.videomaker import VideoMaker"

No module named 'brainrender.Utils.videomaker'

Do I need to update the source files?

Thanks, Capture

FedeClaudi commented 4 years ago

Hi, thanks for getting in touch.

I'm in the process of updating the code to generate videos to fix a few problems with it, so it's currently not functional. I will have it fixed by the end of the day though, so will let you know soon. Sorry about that!

FedeClaudi commented 4 years ago

Hi,

The code for making videos is now fixed. However there seems to be a problem with the underlying vtkplotter video making code (see this issue https://github.com/marcomusy/vtkplotter/issues/122) which means that you might encounter problems if you're using brainrender on Windows, we'll try to fix it ASAP.

You can find an example on how to make videos with the new code here: https://github.com/BrancoLab/BrainRender/blob/master/Examples/basic_video_maker.py

And a more detailed description of how to use the code here: https://github.com/BrancoLab/BrainRender/blob/master/Docs/MakingVideos.md

Hope this works, but let me know otherwise.

P.S.: for this to work you'll have to update your brainrender installation: pip install brainrender --upgrade.

youeh1 commented 4 years ago

Thanks for your work. I create a new virenv as you've instructed us in the other issue. (also applied the upgrade)

I just wonder whether the line that evokes the error might have some typo for the module name. Capture2

Since from brainrender.scene import Scene works, while from brainrender.Utils.videomaker import Video maker not

you mean a Window user still has the problem not having the module in your library?

Best

FedeClaudi commented 4 years ago

Hi,

If you'll look to the example script I've linked above you'll notice that I've changed a few things around as I've reorganised the code.

The code for making videos is not in brainrender.animation.video, which means that you'll have to change

from brainrender.Utils.videomaker import VideoMaker

to

from brainrender.animation.video import BasicVideoMaker as VideoMaker

This is an example of how you can make a simple video:

import brainrender
brainrender.WHOLE_SCREEN = True
brainrender.SHADER_STYLE = 'cartoon'
from brainrender.scene import Scene

from brainrender.animation.video import BasicVideoMaker  as VideoMaker

scene = Scene(display_inset=False, camera="sagittal")

scene.add_brain_regions(['MOs'])

vmkr = VideoMaker(scene)
vmkr.make_video(azimuth=1, niters=360, duration=30, save_name="test")

The problem with windows is (presumably) a bug with vtkplotter which is what brainrender uses for creating the renderings and the videos. You won't get an error because of it, so the code should run smoothly, but unfortunately the video will not be formatted correctly.

p.s.: I'm hoping for the author of vtkplotter to fix this issue soon, but if you need to make a video urgently we can work out a solution together, let me know :)

youeh1 commented 4 years ago

Thanks for your help. I tried your new suggestion, but I still have problem when I run the last line. Actually, I also run the code in linux but still... Screenshot from 2020-04-07 21-15-58

the image I've attached here is from linux.

It says both in Windows and linux 'NoneType' object has no attribute 'SetPosition'

Thanks.

FedeClaudi commented 4 years ago

Hi,

Thanks for trying. I have good news: I've found what the problem is.

When using jupyter/ipython vtkplotter will handle things differently depending on which backend and other packages you have installed.

I believe that you have k3d installed and that's what's causing the problem. It seems that when using k3d the vtkplotter plotter (which is what brainrender's scenes consist of) doesn't have a camera object (or its called something different). Thus when the scene gets rendered and brainrender tries to specify the position of the camera you get that error.

I will fix this in the future, but for now the quickest solution is to either not use jupyter notebooks or to uninstall k3d (pip uninstall k3d). If you restart jupyter after uninstall k3d you'll see a warning message below the first cell (see image below) and I'm confident that you'll be able to create your videos.

image

Hope this helps!

youeh1 commented 4 years ago

Thanks for your early response!

I am happy to get less errors while working with you.

I tried your suggestion, it looks like have no error while running the codes. However, once the rendering is done (rotating 360) then the rendering window gets frozen. Also even though the output message said "test.mp4" saved as mp.4 file, but I couldn't find the corresponding file in .brainrender/Output/Videos. Capture3

Thanks!

FedeClaudi commented 4 years ago

Hi,

the window remains frozen because you're using jupyter notebooks. Until brainrender supports k3d I'm afraid that this will remain an issue, but I will work on this soon.

Regarding the video not being saved, you'll see in the output text in your screenshot the message ffmepg returning error, this means that there where a problem with the creation of the video, which is why the video wasn't saved.

Video Creation for now requires ffmpeg for creating the video, do you have ffmpeg correctly installed? If not you can follow these instructions: http://blog.gregzaal.com/how-to-install-ffmpeg-on-windows/

jt522 commented 4 years ago

Hi,

Thanks for sharing the fantastic code! Let me jump in.

I have trouble saving a video as well (on Mac and tried Jupyter and Spyder).

The error I got is shown below. Do you have any ideas to solve this problem?

Thanks,

image
youeh1 commented 4 years ago

I just install ffmpeg. Thanks for your advice. Capture5

So it seems create a video with mp4 extension, but I couldn't open the file in my computer, while I am still able to open other mp4 files.

I shared the video file to my friend through slack, and noticed that some weird movie was shown. not like I've seen in the rendering window.

Capture4

this is what I am seeing through the window Capture6

The error when I try to open it. Capture7

FedeClaudi commented 4 years ago

@youeh1 that's probably a codec issue, have you tried opening with VLC, that should be open to deal with it. I will be extending the video functionality soon to support more codecs and video formats so hopefully this won't be an issue in the future.

FedeClaudi commented 4 years ago

@jt522 I've never seen that error before, so I'm not sure. A bit more information could help here, specifically: 1) which versions of brainrender and vtkplotter you're using 2) Are you able to render scenes without errors?

youeh1 commented 4 years ago

I can open it but i got this. Capture8

Thanks for your work and let us know later once it is figured out.

FedeClaudi commented 4 years ago

I don't know what it is. I suspect that it's an ffmpeg issue as it seems that the frames got corrupted, but hard for me to diagnose. You can check online how to know if your ffmpeg installation has errors and/or if you need to install more codecs for creating mp4 videos.

If you don't need the video urgently however I'd suggest waiting a couple days, I will change things so that you won't need ffmpeg anymore for creating videos, so this problem will be solved with the new changes (see https://github.com/BrancoLab/BrainRender/issues/50).

jt522 commented 4 years ago

Thanks for quick reply! Here is my answer.

  1. brainrender 0.3.4.2 vtkplotter 2020.2.3

  2. I can render scene without error.

FedeClaudi commented 4 years ago

@jt522 let's move this conversation to a separate issue since it's not related to the issue above.

FedeClaudi commented 4 years ago

@youeh1 I will close this issue for now as the original problem has been fixed, but stay tuned for updates on how to create videos with brainrender.

FedeClaudi commented 4 years ago

@youeh1 if you'd like you could test the new code for creating videos, which doesn't require ffmpeg and also lets you save videos as .avi.

To do so you need to:

  1. Install brainrender from the animation github branch with:

    pip uninstall brainrender
    pip install brainrender git+https://github.com/BrancoLab/BrainRender.git@animation
  2. Install termcolor and opencv with

    pip install termcolor opencv-python

Then you can try creating a video. The code for creating videos is the same as what you've already used, but hopefully you'll get better results.

Let me know if you get a chance to try this and if you get better results, thanks.