Friday, 27 March 2009

The easy way to add MPEG2 encoding to VTK!

The Visualization Toolkit (VTK) can be set up at build time to provide MPEG2 encoding. This is an optional extra due to the fact that there are patents attached to MPEG2 encoding and Kitware, who develop VTK, want to be able to distribute it as both free and unencumbered software. They do provide an MPEG2 library that can be slotted in at build time but it is not immediately obvious how to do so.

I have found that the most straight forward method of building this MPEG2 library is to drop it into the VTK source directory and add it directly into the build system rather than building it separately outside of VTK. Indeed, the VTK MPEG2 distribution has all the necessary CMake hooks required to do just that.
  • Once you have un-tarred the VTK source tree cd into VTK/Utilities.
  • Un-tar the VTK MPEG2 library here.
  • Go back to the root of the VTK source tree and load CMakeLists.txt into your favourite editor.
  • Search for 'MPEG2' in the file (line 764 in version 5.2.1, line 793 in version 5.4.0) and about 30 lines below that comment out this line: INCLUDE(${VTK_CMAKE_DIR}/FindMPEG2.cmake OPTIONAL) - CMakeLists.txt uses # as a comment marker.
  • In place of that line you need to add the following one: ADD_SUBDIRECTORY(${VTK_SOURCE_DIR}/Utilities/vtkmpeg2encode)
Now you can build VTK as normal, making sure that you turn on VTK_USE_MPEG2_ENCODER in the configure stage. When building VTK the MPEG2 library will be one of the first to be built.

No comments: