[vtkusers] Python VTK, how to record a video?
Miroslav Drahos
mdrahos at thinksurgical.com
Tue Jun 16 15:36:15 EDT 2015
vtkFFMPEGWriter is derived from vtkImageAlgorithm, so it's input is an image.
So you should be able to use vtkWindowToImageFilter to pass your renderwindow output as an image into vtkFFMPEGWriter.
Note the warning in the 'detail' section of vtkWindowToImageFilter:
To force an update of the output image, call vtkWindowToImageFilter's Modified method after rendering to the window.
HTH,
Miro
________________________________________
From: vtkusers [vtkusers-bounces at vtk.org] On Behalf Of Maksim Surov [surov.m.o at gmail.com]
Sent: Tuesday, June 16, 2015 3:26 AM
To: vtkusers at vtk.org
Subject: [vtkusers] Python VTK, how to record a video?
Hello.
I am trying to record a video of VTK 3D animation in Python. 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 to canvas.
I write 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()
My question is how to connect vtkRenderer to vtkFFMPEGWriter?
--
Best regards,
Maksim Surov
More information about the vtkusers
mailing list