Skip to main content

This module provides classes to encode and stream frames from a VTK OpenGL render window using video codecs.

Project description

VTKStreaming

This module provides classes to encode and stream frames from a VTK OpenGL render window using video codecs. It supports video encoding with VP9 (through libvpx) and H.264/H.265 (through NVENC).

Installation

VTKStreaming is available on PyPi on the following platforms:

  • Linux x86_64 for python 3.10 to 3.13 included.
  • Windows x86_64 for python 3.10 to 3.13 included.
  • MacOSX arm64 for python 3.10 to 3.13 included.

It is currently based on VTK 9.6.0.

pip install vtk-streaming

Example

from vtkmodules.vtkCommonCore import vtkUnsignedCharArray
from vtkmodules.vtkRenderingCore import vtkRenderer, vtkRenderWindow, vtkRenderWindowInteractor
from vtkmodules.util.numpy_support import vtk_to_numpy
from vtkmodules.util.misc import calldata_type
from vtkmodules.util.vtkConstants import VTK_OBJECT

from vtk_streaming.vtkStreamingEncode import vtkVideoEncoder
from vtk_streaming.vtkStreamingNvEncode import vtkNvEncoderGL
from vtk_streaming.vtkStreamingVpxEncode import vtkVpxEncoder
from vtk_streaming.vtkStreamingOpenGL2 import vtkOpenGLVideoFrame
from vtk_streaming.vtkStreamingCore import VTKVC_H264, VTKVC_H265, VTKVC_VP9, VTKPF_IYUV, vtkCompressedVideoPacket

ren = vtkRenderer()
ren.SetBackground(0.1, 0.2, 0.4)
win = vtkRenderWindow()
win.AddRenderer(ren)
width, height = 641, 953 # size of video frames will likely be aligned to some value such as %4 or %8
win.SetSize(width, height)
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(win)
iren.Initialize()
iren.Render()

# Encoder takes the window to get the OpenGL context from it
encoder: vtkVideoEncoder = None
if vtkNvEncoderGL.CheckAvailability():
    encoder = vtkNvEncoderGL()
    encoder.SetCodec(VTKVC_H264)
    print("Using H264 through NVENC")
else:
    encoder = vtkVpxEncoder()
    encoder.SetCodec(VTKVC_VP9)
    print("Using VP9 through libvpx")
encoder.SetGraphicsContext(win)
encoder.SetWidth(width) # to handle in resize event!
encoder.SetHeight(height)
encoder.SetInputPixelFormat(VTKPF_IYUV)

# This is used to copy the framebuffer of the window to a NVENC shared-texture
picture = vtkOpenGLVideoFrame()
picture.SetContext(win)
picture.SetWidth(width) # to handle in resize event!
picture.SetHeight(height)
picture.SetPixelFormat(VTKPF_IYUV)
picture.AllocateDataStore()

# You will receive video packets through this callback
@calldata_type(VTK_OBJECT)
def receive_data(_obj: vtkVideoEncoder, _ev: int, data: vtkCompressedVideoPacket):
    frame_data: vtkUnsignedCharArray = data.GetData()
    raw_bytes = vtk_to_numpy(frame_data).tobytes() # do something with it
encoder.AddObserver(vtkVideoEncoder.EncodedVideoChunkEvent, receive_data)

# We have logic to insert in rendering loop,
# Depending on the application and used GUI etc, this might differ.
while True:
    # Render current frame
    iren.ProcessEvents()
    iren.Render()
    # Capture last framebuffer
    picture.Capture(win)
    # Encode using choosen backend, this may invoke EncodedVideoChunkEvent any number of times
    encoder.Encode(picture)

# In a real application this should be called on exit
# this example is simply killed by user with ctrl+c
enc.Drain()
enc.Shutdown()

Getting help

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

vtk_streaming-0.3.2-cp313-cp313-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.13Windows x86-64

vtk_streaming-0.3.2-cp313-cp313-manylinux_2_28_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

vtk_streaming-0.3.2-cp313-cp313-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

vtk_streaming-0.3.2-cp312-cp312-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.12Windows x86-64

vtk_streaming-0.3.2-cp312-cp312-manylinux_2_28_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

vtk_streaming-0.3.2-cp312-cp312-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

vtk_streaming-0.3.2-cp311-cp311-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.11Windows x86-64

vtk_streaming-0.3.2-cp311-cp311-manylinux_2_28_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

vtk_streaming-0.3.2-cp311-cp311-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

vtk_streaming-0.3.2-cp310-cp310-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.10Windows x86-64

vtk_streaming-0.3.2-cp310-cp310-manylinux_2_28_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

vtk_streaming-0.3.2-cp310-cp310-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file vtk_streaming-0.3.2-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c175fe84570cd6c4363ddabf83b3a22de5e371b601e6b20439d08c4ec860f073
MD5 c711adcf61af2f5f8030df496a11d530
BLAKE2b-256 fca0b18b98f6089547fb06d7ee530b846153e2e1a94dd47d68e2cfd19d63e676

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.2-cp313-cp313-win_amd64.whl:

Publisher: release.yml on Kitware/VTKStreaming

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vtk_streaming-0.3.2-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.2-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 41d9679a248948c39921fd2966da9f4baced63cdfec82faed54251bd90ef1d00
MD5 76301726f17b7e3f1a6e55773524cf36
BLAKE2b-256 8f28f0384554b7e1a9d818ee526c4a1b0dd631bf803a93904164d22601094286

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.2-cp313-cp313-manylinux_2_28_x86_64.whl:

Publisher: release.yml on Kitware/VTKStreaming

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vtk_streaming-0.3.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 26080556ddc01c65d5196ab44a2725f9929c1caca80e03705e95929a0dfb379b
MD5 af69e097406bd21731dd1a1ec5ac6f4d
BLAKE2b-256 797e1a1a15f3fd9395d2231e0901d840dcb4df2adda71ec8e07e570d3f388a87

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.2-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yml on Kitware/VTKStreaming

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vtk_streaming-0.3.2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0a6444d3a3814e69279b04c054f24fb178d303462c6a0ebf777415092314dafc
MD5 9ef32aec7ba579d6c68b8f2441998747
BLAKE2b-256 8e6a5b57be6cca6a838e2ad86c0a074bca38b92f1e9c9346e9318e88fb6dce18

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.2-cp312-cp312-win_amd64.whl:

Publisher: release.yml on Kitware/VTKStreaming

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vtk_streaming-0.3.2-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.2-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4e35067138005acfb828b5ae54793419112581c3e52c0397f2e918add0723af1
MD5 ee870762100da6a4176e52f2bc4de7e4
BLAKE2b-256 a1fb813aea4af661421534f3537618820cb19e44b78894a0a74f00809c7b00e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.2-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: release.yml on Kitware/VTKStreaming

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vtk_streaming-0.3.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cb6dfb9f39ad51d0f36c643777728469e381efdaefae5ed445e8b2e2ee6bf1c2
MD5 aa089f0d666ea741a98f775a4bf9ca45
BLAKE2b-256 dcced1d59afae8c86a5fe10fbe220486509dc75e182327833404361ca6156e64

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.2-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on Kitware/VTKStreaming

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vtk_streaming-0.3.2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 df04ec2d72ff06db3acd2769cec736869e61da9126003adbcf0b606dc9098ab4
MD5 afe5c69a3b9a247a09a489e270923eae
BLAKE2b-256 2f5c80fa550716a969cd0328dfe03633930e0a77058112e999c7abbabf3a9df8

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.2-cp311-cp311-win_amd64.whl:

Publisher: release.yml on Kitware/VTKStreaming

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vtk_streaming-0.3.2-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.2-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 37c909064b03e9f1860fc52aae1409273c14b1ffa88002b4e2b17883a1025c20
MD5 c521ac2ed31d2b26753c45daab3ff9d9
BLAKE2b-256 f9fe8620e47f6ee92cb6d10728e6501f3b0185b3f0124bb52b6b5b8d556e011c

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.2-cp311-cp311-manylinux_2_28_x86_64.whl:

Publisher: release.yml on Kitware/VTKStreaming

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vtk_streaming-0.3.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f421b079a12cde670bff5d95aac47f009daaa8a2ccfcd2861aae96bc897d750a
MD5 07fdf5ce601e6a3cab52f0da2945eea8
BLAKE2b-256 c38f24776dce2eb01efad30da117a6b574b06ca8be2ba16640aa52b9c5c9903c

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.2-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release.yml on Kitware/VTKStreaming

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vtk_streaming-0.3.2-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6f48e3f423429f35d202ce9ab1b5ed0ae436d09944a0a9862de56fb967e06579
MD5 50bb074872453fe053fb30950ffba7c8
BLAKE2b-256 c7e6dd17f917bbf825e7bda6fc971dca195ec1620159540cff687008e465e3c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.2-cp310-cp310-win_amd64.whl:

Publisher: release.yml on Kitware/VTKStreaming

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vtk_streaming-0.3.2-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.2-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ed2da7ad472ee8ee2d5b1bb5664fa301180e6a55d188adec84ec00f28e2a58ac
MD5 e8fbae35911696fd0eb329f58dd541b3
BLAKE2b-256 28aef46820ccaf7a8c7ac8fc6b3db8bdcffa712e180fb41ca1348b6655e9c23f

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.2-cp310-cp310-manylinux_2_28_x86_64.whl:

Publisher: release.yml on Kitware/VTKStreaming

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vtk_streaming-0.3.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ed10a7396b634b11d976f9e9d1ebfc52498258f8c8940ba383e4601d2376b625
MD5 8ae6a46c5abf1e3b0d80686a0fd2a847
BLAKE2b-256 c832f640716e062f7524c6c8ded6501c14cf66c161158bf222ed1ee83617f69d

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.2-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: release.yml on Kitware/VTKStreaming

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page