Unable to get vtkMP4Writer to work on Windows vtk 9.2

Hi all!

Following the build instructions (https://gitlab.kitware.com/vtk/vtk/-/blob/master/Documentation/dev/build.md#build-settings) I tried the “VTK_USE_VIDEO_FOR_WINDOWS_CAPTURE" option in order to enable the use of vtkMP4Writer.
Then I try to generate a video using the vtkMP4Writer exactly the same way I use a vtkAVIWriter but it doesn’t work. As an avi file is well generated with vtkAVIWriter the mp4 file generated by the vtkMP4Writer is desperately empty (size = 0) but no error is raised.
Here is globally my code :
Initialization :

MP4Writer = vtk.vtkMP4Writer()

Then for each frame :


And at the end :

My questions are : Do I miss something? Is it working for someone? Do I need ffmpeg or something else (If I understand well it uses a native windows encoder calles Sink Writer)?

Thanks in advance for your replies and your help ^^

I wrote the vtkMP4Writer. It works okay, and the code you supplied looks correct. You should enable VTK_USE_MICROSOFT_MEDIA_FOUNDATION in the build, not VTK_USE_VIDEO_FOR_WINDOWS_CAPTURE. That’s the one you need to enable in the build on Windows to make this class work.

Make sure your image size in each dimension is a multiple of 2.

Does TestMP4Writer in your VTK build run and produce an MP4 that you can play?

Hi Cory and thank you for your reply
My bad I well used the VTK_USE_MICROSOFT_MEDIA_FOUNDATION option for my tests.
You are right the problem was that the image size was not a multiple of 2! Maybe this should be more explicit in the doc of this great function.
Now I have to check the best way to crop my image before writting :slight_smile:

Edit: finally this is my working code. I simply modify the vtkWindowToImageFilter Viewport size.

If this can help somebody :

# Creating WindowsToImageFilter
windowToImageFilter= vtk.vtkWindowToImageFilter()
windowToImageFilter.ReadFrontBufferOff() # read from the back buffer

# Modify ViewPort to ensure a multiple of 2
imSize = windowToImageFilter.GetOutput().GetDimensions()
windowToImageFilter.SetViewport(0, 0, (imSize[0]-imSize[0]%2)/imSize[0], (imSize[1]-imSize[1]%2)/imSize[1])

# Creating Writer normally
MOVWriter = vtk.vtkMP4Writer()

# Call windowToImageFilter.Modified() before each MovWriter.Write()
# End with MovWriter.End()