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.1-cp313-cp313-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.13Windows x86-64

vtk_streaming-0.3.1-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.1-cp313-cp313-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

vtk_streaming-0.3.1-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.1-cp312-cp312-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

vtk_streaming-0.3.1-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.1-cp311-cp311-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

vtk_streaming-0.3.1-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.1-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.1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e0e47ac4c4808e7defafceb44461b3de79187fcce2ca09f1b48693d54c476b68
MD5 40399022a5060120693904c0f08fc231
BLAKE2b-256 5aa4ffb1bd6933d7d2422d1ce8ab0c2a935e771a373d309805ede21f5ca94bb6

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.1-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.1-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.1-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 44398ab1cbdfc082b0471c34929a1fcc86cb314f68acaf946e21f0c60528b5bd
MD5 1d464288907580a0b3186d155306a294
BLAKE2b-256 5e1160229ab4c181fe9dd9f4ab75b78d3e3c1f604d1248b12195a3491f7f5593

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.1-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.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 10960961532d725d5113d08084b529d419ac190b5123b54ebe06c00a01633e1c
MD5 4687e606684ed6aec0c1743550de85d1
BLAKE2b-256 f9f623b4abd47acba89cd2a08a2c39cb166583d10abd3ce34bb571fd0cfe0e69

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.1-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.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 960c902cc3a21675c73acea9d56e9ed3c43da4b00e734a6bcf8a3ca7175ed76c
MD5 8a4a3d0389b25ce5c2f00da4bc9396bd
BLAKE2b-256 634b860ba0c2f35e59c5e7ab0a0c06dc4d91b3a3443e826940c7141a0ace4dab

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.1-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.1-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.1-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 572e9e0204282c3971125645f7731f949b4fdd3c0f210beff1546afafd8d8ee9
MD5 e8f0f3a3c3400f7a002689fcee6cf1bf
BLAKE2b-256 30ec9ba6779ec577b11446b0b2f2e2e40e019f0ad53be86ec8cb3e4404df9a8e

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.1-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.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e8da5fd68189e9afc583c6279eeb411979b05f443bfdd68629713afb0bf68622
MD5 b9fc2448cf23b8080df17f058d6bdc5a
BLAKE2b-256 606277b7a69629aab8b8b98c57115adb0dc34f7e0c233a54c2c47ba1d47d20dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.1-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.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 edb9c1441865ca2327f705a6d1648f9e30e8776dfba4bea1a929972131e6cb8c
MD5 b982aa1dc9161e94d6256e220b5f1ff9
BLAKE2b-256 fa79182cddad6d2f63b44b0801e555a2fc78f17ce8b1bb0cf9fafa2c90d61afc

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.1-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.1-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.1-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 eeb084b96884ad5584869f40f28ca53dd3f7583ce206a994a7614dcca1f2cfc3
MD5 56b83332197220269c5dac56d3cd5620
BLAKE2b-256 014b8ef19645dc19992ddd514fbe6b45921d51f92748c5585b0ef3bbe601d2a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.1-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.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cde35ba0ac30d0ffbb9483c8c25f9a10d22a40b86e5e95309d42f4861387d48b
MD5 d7ee3b76a70492e66a89df3e285bc138
BLAKE2b-256 002893de0b94461eb060a9a23b6c63017bff18045211c250bfb756c114b4a344

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.1-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.1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 127996f3dd9a7f57e1936a87ba2663404f3a3a7dcbd772f58bfceb1e130d3624
MD5 00f65c463bfe6b7f247ed55e8525f8e6
BLAKE2b-256 51e73ddeb4f486c70e48bb93f43f860d67262b39957440d74e21e35d0d9d3558

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.1-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.1-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.1-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e881774e41d10e6165b37f0e27ff0bcd5d5aebe05b2eeb672a90491d380e3fa7
MD5 94d29d96fbc36f6e6a9dd7885a68b2bf
BLAKE2b-256 131420fea79cb69e55f82b0fc7ba2b468129b813e5be4a6ecf60da0ebce3b620

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.1-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.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for vtk_streaming-0.3.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6dfac237389359d41e77e4fec4ccf7899b339a09fc098f66524bcc92d30aac91
MD5 4427ad7510278c1ce49dce72cc74ef17
BLAKE2b-256 45de9d21bbf17239d0839fd51b924c88a1b2d9cb45a2f0d0fccfc55289ec1207

See more details on using hashes here.

Provenance

The following attestation bundles were made for vtk_streaming-0.3.1-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