Skip to main content

Educational Python implementation of CineForm wavelet compression - for learning, not performance

Project description

PyCineForm

A pure Python implementation of the CineForm/VC-5 wavelet codec, built for learning and understanding.

⚠️ Important: This is an educational project. For production use, please use the GoPro CineForm SDK which is optimized for performance.

Purpose

This project exists to help understand how CineForm compression works by implementing it from scratch in Python. It prioritizes clarity and readability over performance - the goal is well-documented code that can be stepped through, visualized, and experimented with.

Why Python?

  • Easy-to-follow code with clear algorithm implementations
  • Excellent debugging and visualization tools
  • NumPy for clean array operations without hiding the math
  • No low-level optimizations obscuring the algorithms

What this is NOT:

  • A high-performance encoder/decoder
  • A drop-in replacement for the CineForm SDK
  • Optimized for real-time video processing

Cross-codec testing was used to verify that this Python implementation matches the CineForm SDK output (at least to the extent of the testing done so far).

What's Implemented

  • 2-6 Integer Wavelet Transform - SDK-compatible forward/inverse transforms
  • Multi-level Decomposition - 3-level wavelet pyramid
  • Quantization - SDK-compatible subband quantization tables
  • VLC Encoding - Variable-length coding with SDK codebooks
  • SDK Bitstream Format - Produces bitstreams the SDK can decode
  • Color Support - RGB 4:4:4, YUV 4:2:2, grayscale (uses one of the RGB channels)
  • Cross-codec Validation - Compare PyCineForm against the real SDK

Visualizations

The educational walkthrough (examples/encoder_decoder_walkthrough.py) generates visualizations to help understand the compression pipeline:

3-Level Wavelet Pyramid Decomposition:

Wavelet Pyramid

Full Encode/Decode Roundtrip with Quality Metrics:

Full Roundtrip

Quick Start

# Install dependencies and project
uv sync

# Run tests
uv run pytest

# Try the educational walkthrough (recommended!)
uv run python examples/encoder_decoder_walkthrough.py

# Or basic encode/decode demo
uv run python examples/basic_usage.py

NOTE: Some tests/examples rely on the SDK DLL being built. See below for instructions.

Project Structure

Folder Purpose
src/pycineform/ Main Python implementation
notes/ Technical documentation and notes
cross_codec/ SDK comparison and validation tools
examples/ Usage examples and demos
tests/ Test suite
cineform-sdk/ GoPro SDK source (for reference/building DLL)
diagnostics/ Visualization and debugging tools

Documentation

Document Description
notes/compression_overview.md How CineForm compression works
notes/bitstream.md Bitstream format documentation
notes/python_overview.md Python codebase structure
notes/sdk_overview.md SDK architecture notes
cross_codec/README.md SDK validation tools
examples/README.md Example scripts

Basic Usage

from pycineform import encode_color, decode_color, SDKQuality
import numpy as np

# Create or load an RGB image (H, W, 3), uint8
image = np.random.randint(0, 256, (256, 256, 3), dtype=np.uint8)

# Encode
result = encode_color(image, quality=SDKQuality.FILMSCAN1)
print(f"Compressed to {len(result.bitstream)} bytes ({result.compression_ratio:.1f}:1)")

# Decode
decoded = decode_color(result.bitstream, output_bit_depth=8)

SDK Validation

The cross-codec tests verify PyCineForm produces bitstreams the SDK can decode (and vice versa):

# Run cross-codec validation
uv run pytest tests/test_sdk_reference.py -v -k "cross_codec"

Building the CineForm SDK Library

The cross-codec validation requires the CineForm SDK shared library.

Windows:

cd cineform-sdk/build
.\build_stock.bat
# Creates cineform-sdk/build/Release/CFHDCodec.dll

Linux:

cd cineform-sdk && mkdir -p build && cd build
cmake .. && make -j$(nproc)
# Creates cineform-sdk/build/libCFHDCodec.so

macOS:

cd cineform-sdk && mkdir -p build && cd build
cmake .. && make -j$(sysctl -n hw.ncpu)
# Creates cineform-sdk/build/libCFHDCodec.dylib

Current status:

  • ✅ PyCineForm encode → SDK decode (8, 10, 12-bit RGB and Bayer RAW)
  • ✅ SDK encode → PyCineForm decode (8-bit RGB)
  • 🔄 Higher bit-depth decoder support in progress
  • ⚠️ Image dimensions must be multiples of 16 (use crop_to_multiple() or pad_to_multiple() from pycineform.utils)

Learning Resources

To understand the compression pipeline, start with:

  1. notes/compression_overview.md - High-level algorithm overview
  2. src/pycineform/core/wavelet.py - Wavelet transform implementation
  3. src/pycineform/core/quantization.py - Quantization tables
  4. src/pycineform/core/vlc_encoder.py - Entropy coding
  5. diagnostics/wavelet_diag.py - Visualize wavelet behavior

References

License

This project is licensed under the MIT License - see LICENSE for details.

Copyright (c) 2025-2026 Anthony Lukes

The cineform-sdk/ directory contains the GoPro CineForm SDK, which is separately licensed under Apache 2.0 OR MIT (at your option). See cineform-sdk/LICENSE.txt.

Acknowledgments

This project would not be possible without the GoPro team's decision to open-source the CineForm SDK. The SDK source code served as the authoritative reference for understanding the codec's algorithms, bitstream format, and quantization tables.

Project details


Download files

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

Source Distribution

pycineform-0.1.0.tar.gz (16.1 MB view details)

Uploaded Source

Built Distribution

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

pycineform-0.1.0-py3-none-any.whl (273.5 kB view details)

Uploaded Python 3

File details

Details for the file pycineform-0.1.0.tar.gz.

File metadata

  • Download URL: pycineform-0.1.0.tar.gz
  • Upload date:
  • Size: 16.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pycineform-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a4b2ea7ff20076b3589bf1aa7ce792c0d7ebcb0b35626859a83e5e9ae06dca46
MD5 c7a99723997b5ade333e7a8226b0cdf6
BLAKE2b-256 735598f1e0fe1c865f25f09029118172f739044e3d57dc5c9bed5ec5dd631292

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycineform-0.1.0.tar.gz:

Publisher: publish.yml on chiplukes/pycineform

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

File details

Details for the file pycineform-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pycineform-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 273.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pycineform-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9cf10bd9fc60f1b3b21ab32031bc68789297e6bc1bde746627893292ac9df128
MD5 26d63dc6f0e850d664de9ae0f7b2af3d
BLAKE2b-256 779ca4f99869098c325191793b4dd148ce5d988c68256bfd1a1f26410dd89607

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycineform-0.1.0-py3-none-any.whl:

Publisher: publish.yml on chiplukes/pycineform

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