Skip to main content

HDF5 filter plugin for FFMPEG video codec compression

Project description

FFMPEG HDF5 Filter Enables High-Ratio Image Compression for Faithful Scientific Analysis

The FFMPEG HDF5 filter enables high-ratio compression of scientific datasets in HDF5 files using video codec technology. It supports a wide range of codecs (H.264, H.265/HEVC, AV1, etc.) with hardware acceleration options for NVIDIA GPUs and Intel QuickSync.

Features

  • High Compression Ratios: Achieve 10-10,000× compression while preserving analysis fidelity
  • Multiple Codec Support: H.264, H.265/HEVC, AV1, and more
  • Hardware Acceleration: NVIDIA GPU and Intel QuickSync support
  • Simple Python API: Easy-to-use interface for H5Py
  • Automated Optimization: Film grain synthesis and artifact minimization
  • Cross-Platform: Works on Linux, macOS, and Windows
  • ImageJ/Fiji Plugin Support: Direct visualization and analysis in popular scientific imaging tools

Installation

Via pip (recommended)

pip install h5ffmpeg

Using pre-built binaries for ImageJ/Fiji

We recommend using our imageJ update sites.

Note: Due to the limitation of static built ffmpeg to comply with Java, some codecs are not supported. We strongly recommend using our python package. If working with large-scale dataset, SISF_CDN with neuroglancer is recommended.

From source (not recommended)

git clone https://github.com/Cai-Lab-at-University-of-Michigan/ffmpeg_HDF5_filter.git
cd ffmpeg_HDF5_filter
pip install -e .

This is not recommended since it requires compiling FFmpeg from source with HDF5 support, which is complex and error-prone. Our pip package includes pre-built, tested binaries.

Quick Start

import h5py
import numpy as np
import h5ffmpeg as hf

# Create sample data
data = np.random.rand(100, 512, 512).astype(np.uint8)

# Save with default settings (H.264)
with h5py.File("compressed.h5", "w") as f:
    f.create_dataset("data", data=data, **hf.x264())

# Save with H.265/HEVC compression
with h5py.File("compressed_hevc.h5", "w") as f:
    f.create_dataset("data", data=data, **hf.x265(crf=28))

# Save with AV1 compression (highest ratio)
with h5py.File("compressed_av1.h5", "w") as f:
    f.create_dataset("data", data=data, **hf.svtav1(crf=30))

# Use with NVIDIA GPU acceleration
with h5py.File("compressed_gpu.h5", "w") as f:
    f.create_dataset("data", data=data, **hf.h264_nvenc())

Advanced Usage

Custom Codec Configuration

import h5ffmpeg as hf

# Access the full ffmpeg API for complete control
compression_options = hf.ffmpeg(
    codec="libx264",        # Codec to use
    preset="medium",        # Encoding speed vs compression efficiency
    tune="film",            # Content-specific optimization
    crf=23,                 # Quality level (lower = higher quality)
    bit_mode=hf.BitMode.BIT_10,  # 8, 10, or 12-bit encoding
    film_grain=50,          # Film grain synthesis (0-50)
    gpu_id=0                # GPU ID (Default: 0)
)

Automated Hardware Acceleration

The library can detect and use available hardware acceleration:

import h5ffmpeg as hf

# This will automatically use NVIDIA GPU if available, 
# or fall back to CPU if not
compression_options = hf.ffmpeg(
    codec="h264_nvenc" if hf.has_nvidia_gpu() else "libx264",
    preset="p4" if hf.has_nvidia_gpu() else "medium",
    crf=23
)

Available Codecs

Codec Implementation Description Typical Use Case
XVID libxvid MPEG-4 codec Legacy support
H.264 libx264 General-purpose codec Good balance of quality and speed
H.265/HEVC libx265 Higher efficiency than H.264 Better compression for same quality
AV1 libsvtav1 Next-gen open codec Highest compression ratio
AV1 librav1e Rust AV1 encoder Alternative AV1 implementation
H.264 NVENC h264_nvenc NVIDIA GPU-accelerated H.264 Fast encoding on NVIDIA GPUs
HEVC NVENC hevc_nvenc NVIDIA GPU-accelerated HEVC High-quality, fast encoding on NVIDIA GPUs
AV1 NVENC av1_nvenc NVIDIA GPU-accelerated AV1 Next-gen encoding on newest NVIDIA GPUs
AV1 QSV av1_qsv Intel QuickSync AV1 Hardware acceleration on Intel GPUs

Compatibility

  • Python: 3.11+
  • Operating Systems: Linux-x86_64, macOS Apple Silicon, and Windows-AMD64
  • hdf5: 1.14+
  • h5py: 3.8+

License

MIT License

Citation

If you use this software in your research, please cite:

Duan, B., Walker, L.A., Xie, B., Lee, W.J., Lin, A., Yan, Y., and Cai, D. (2024).
Artifact-Minimized High-Ratio Image Compression with Preserved Analysis Fidelity.

Acknowledgments

This work was funded by the United States National Institutes of Health (NIH) grants RF1MH123402, RF1MH124611, and RF1MH133764.

Community and Support

  • GitHub Issues: For bug reports and feature requests
  • Contact: Feel free to reach out to us with questions

Related Projects

Feel free to check out other tools from the Cai Lab:)

  • nGauge: Python library for neuron morphology analysis
  • nTracer2: Browser-based tool for neuron tracing
  • pySISF: Python wrapper for SISF format
  • SISF_CDN:Scalable Image Storage Format CDN

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

h5ffmpeg-2.0.0.tar.gz (56.0 kB view details)

Uploaded Source

Built Distributions

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

h5ffmpeg-2.0.0-cp312-cp312-win_amd64.whl (34.6 MB view details)

Uploaded CPython 3.12Windows x86-64

h5ffmpeg-2.0.0-cp312-cp312-manylinux_2_34_x86_64.whl (36.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

h5ffmpeg-2.0.0-cp312-cp312-macosx_12_0_arm64.whl (24.8 MB view details)

Uploaded CPython 3.12macOS 12.0+ ARM64

h5ffmpeg-2.0.0-cp311-cp311-win_amd64.whl (34.6 MB view details)

Uploaded CPython 3.11Windows x86-64

h5ffmpeg-2.0.0-cp311-cp311-manylinux_2_34_x86_64.whl (36.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

h5ffmpeg-2.0.0-cp311-cp311-macosx_12_0_arm64.whl (24.8 MB view details)

Uploaded CPython 3.11macOS 12.0+ ARM64

File details

Details for the file h5ffmpeg-2.0.0.tar.gz.

File metadata

  • Download URL: h5ffmpeg-2.0.0.tar.gz
  • Upload date:
  • Size: 56.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for h5ffmpeg-2.0.0.tar.gz
Algorithm Hash digest
SHA256 5ee6b1805fa78036387dbc9f03e07710575586b76341256782d1e72d4f7db7dd
MD5 58509a3b9dbf14cb343b332ec7f57429
BLAKE2b-256 c9ad56d48e73b59f363f5c27db34061873a52cfd9221b1b648dab8d0d6ed6d58

See more details on using hashes here.

File details

Details for the file h5ffmpeg-2.0.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: h5ffmpeg-2.0.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 34.6 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for h5ffmpeg-2.0.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c8c0f7d633a9bf14e8456e5230997dd791e1d8de1e0b9137de21c0aeda6cf81b
MD5 cfe05ea74f8cd31d05e3ba37dc2b7fd0
BLAKE2b-256 ef7a07f236ba2a4522b9eb6f84f8a23e777b9422b94b063ff567c705c2a9532c

See more details on using hashes here.

File details

Details for the file h5ffmpeg-2.0.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for h5ffmpeg-2.0.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 993069065030f59d25363570b14fa3a61217f25d787ed410acc3f40482383cfd
MD5 f4aea1fbfca237119572e6f36a893a2e
BLAKE2b-256 77f4609e067d35bfa3fd67da27b34e7254681726d413b45a5948e8b1791ddc88

See more details on using hashes here.

File details

Details for the file h5ffmpeg-2.0.0-cp312-cp312-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for h5ffmpeg-2.0.0-cp312-cp312-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 62264000b6020d6e1fa1f7c0ebbfb23ba5c9270a5cde83a9489ed7d9ef6ac585
MD5 b2fd9fa6d0904cdffb4d9878055af97d
BLAKE2b-256 a73e0c7d73274f11a22d70ef8c42b9ea110f1ce1864e17fff0e715b0d2399567

See more details on using hashes here.

File details

Details for the file h5ffmpeg-2.0.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: h5ffmpeg-2.0.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 34.6 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for h5ffmpeg-2.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4b7edef28233bd5238e889dd7713e8f62a6555a7307256234b046f38de1b227c
MD5 9b1f3c4786fc8ef063010ed1d5c624b6
BLAKE2b-256 f2b77c9de1e984012b1d4eb12e650265930ebc42b73dddf506d2e3103ddac2a2

See more details on using hashes here.

File details

Details for the file h5ffmpeg-2.0.0-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for h5ffmpeg-2.0.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b872ba7c4457a12e1548bd94f1f6680bc348615ec4f58e8cfb165a74212a3940
MD5 085082945f98263dbc1d89ef810ebee0
BLAKE2b-256 85b8f5b14127b1e4f250eab2320fbf08c57195a73d915d70c32841b9aa1da54a

See more details on using hashes here.

File details

Details for the file h5ffmpeg-2.0.0-cp311-cp311-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for h5ffmpeg-2.0.0-cp311-cp311-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 079eb32ef257dc283111a6f61b64b6c00965dc5dbb55496f08ba12643a9a8260
MD5 6bb8ec6557e990906a3cf43c7bc5725e
BLAKE2b-256 7667375a462e690c78c9d51b59cf83497857f3860ff4882eab84a0bd423cffd3

See more details on using hashes here.

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