I am trying to record a video of VTK 3D animation using ffmpeg. The example I found http://www.itk.org/Wiki/VTK/Examples/Cxx/Video/FFMPEG is a bit strange for me, because it does not create a render, so it is not clear how to attach actors in this case. So, my question is how to connect vtkRenderer
to vtkFFMPEGWriter
? I wrote a simplified example
import vtk
# draw a plane
plane_source = vtk.vtkPlaneSource()
plane_source.SetCenter(0, 0, 0)
plane_source.SetNormal(0, 0, 1)
plane_mapper = vtk.vtkPolyDataMapper()
plane_mapper.SetInput(plane_source.GetOutput())
plane_actor = vtk.vtkActor()
plane_actor.SetMapper(plane_mapper)
# create render
render = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(render)
renWin.SetSize(800, 600)
renInter = vtk.vtkRenderWindowInteractor()
renInter.SetRenderWindow(renWin)
render.AddActor(plane_actor)
renWin.Render()
renInter.Initialize()
# set callback
def cb(interactor, event):
global plane_actor
plane_actor.RotateZ(0.1)
interactor.GetRenderWindow().Render()
renInter.AddObserver('TimerEvent', cb)
timerId = renInter.CreateRepeatingTimer(100);
# put something here?
writer = vtk.vtkFFMPEGWriter()
# ??? writer.SetInputConnection(...)
writer.SetFileName("test.avi")
writer.Start()
# run
renInter.Start()
The problem can be easily solved by using vtkWindowToImageFilter (description here):