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. We support Windows, Ubuntu, MacOS (ARM64).

MacOS users: Run setup_macos_fiji.sh to prevent crashes during compression/decompression.

SetUpH5FFMPEG.ijm: This macro runs automatically. After system restarts, open Fiji twice to configure HDF5_PLUGIN_PATH properly.

Ubuntu users: After the first time opening Fiji, You may need to Logout and LogIn for Fiji picking up the HDF5_PLUGIN_PATH enviroment variable.

Note: Due to the limitation of 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.4.0.tar.gz (67.7 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.4.0-cp313-cp313-win_amd64.whl (34.6 MB view details)

Uploaded CPython 3.13Windows x86-64

h5ffmpeg-2.4.0-cp313-cp313-manylinux_2_34_x86_64.whl (38.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

h5ffmpeg-2.4.0-cp313-cp313-macosx_12_0_arm64.whl (25.2 MB view details)

Uploaded CPython 3.13macOS 12.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

h5ffmpeg-2.4.0-cp312-cp312-manylinux_2_34_x86_64.whl (38.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

h5ffmpeg-2.4.0-cp312-cp312-macosx_12_0_arm64.whl (25.2 MB view details)

Uploaded CPython 3.12macOS 12.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

h5ffmpeg-2.4.0-cp311-cp311-manylinux_2_34_x86_64.whl (38.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

h5ffmpeg-2.4.0-cp311-cp311-macosx_12_0_arm64.whl (25.2 MB view details)

Uploaded CPython 3.11macOS 12.0+ ARM64

h5ffmpeg-2.4.0-cp310-cp310-win_amd64.whl (34.6 MB view details)

Uploaded CPython 3.10Windows x86-64

h5ffmpeg-2.4.0-cp310-cp310-manylinux_2_34_x86_64.whl (38.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

h5ffmpeg-2.4.0-cp310-cp310-macosx_12_0_arm64.whl (25.2 MB view details)

Uploaded CPython 3.10macOS 12.0+ ARM64

File details

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

File metadata

  • Download URL: h5ffmpeg-2.4.0.tar.gz
  • Upload date:
  • Size: 67.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for h5ffmpeg-2.4.0.tar.gz
Algorithm Hash digest
SHA256 7a467afcf4693d0eca359b4554e51b396bfda7a43ce125f15e25846a40d88256
MD5 872a0b2fd712f782c9e41504f0ab2fb4
BLAKE2b-256 f7c1870265f62e1a11d6584d62809bc2b38a2133f6c5493b3ddc471688d68525

See more details on using hashes here.

File details

Details for the file h5ffmpeg-2.4.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: h5ffmpeg-2.4.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 34.6 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for h5ffmpeg-2.4.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e9003fefe887c5b5738f4b999a034771850c3a2016420aebb0be8ee5e962cf03
MD5 8b2ff62f7219c3de12ab125322548427
BLAKE2b-256 03e3a48d8e3c27689fe59825df5c5762cd6564d9484aef6f0aa3391b65032c34

See more details on using hashes here.

File details

Details for the file h5ffmpeg-2.4.0-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for h5ffmpeg-2.4.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1c643c69949c04bfe726dccfb4ced3fe1689e3f5b36b585d2a72c2a13fa0ac22
MD5 ba6346146e7addfb0adbfa69e5e3565c
BLAKE2b-256 f72dd4f91660146a6fe7eb01861c8244fe62ebbc99e9ddc374158b1dca34fa7e

See more details on using hashes here.

File details

Details for the file h5ffmpeg-2.4.0-cp313-cp313-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for h5ffmpeg-2.4.0-cp313-cp313-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 04b322bbfb259f529376e0cb009a46dc73e26859961cd21d5dbbeb33924c0271
MD5 e31549954ce7a5f78c5c361c9398db4c
BLAKE2b-256 309fbe84033b556dad6b38bf6087b8329c5199515de785d842f65caaea072458

See more details on using hashes here.

File details

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

File metadata

  • Download URL: h5ffmpeg-2.4.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.2.0 CPython/3.10.19

File hashes

Hashes for h5ffmpeg-2.4.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0395e0ed607ec0429cc5ede76b89606b21dfbda22495aef75a310f37e6a5e9b5
MD5 b1a943769a494e4a2a353f549e41631e
BLAKE2b-256 6495a39e2841c7f198da1549f0ba4f2d3d065a0cb00ed5d3bcc2ca2a00f2c7bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for h5ffmpeg-2.4.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 224aad76cf7adeebe150c97b64c49d6338c6739874a8392053317774a4e0aaf4
MD5 8c0ed3579e97a29d2416901a8e8abdad
BLAKE2b-256 00c14ed143e19a91416944bcd8b57b0aba1eea0f09090499528b927dcee6f547

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for h5ffmpeg-2.4.0-cp312-cp312-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 7b1075e56d4ef8d464c1621da42a53ce7902afdf0ceaefa4b2e8c5b3d6199da1
MD5 8804afae762d2d516725203bd41d403f
BLAKE2b-256 ad0be836ee3bd42b6990e45b0b971bb380e5fcb973094b3066b20c8686817aec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: h5ffmpeg-2.4.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.2.0 CPython/3.10.19

File hashes

Hashes for h5ffmpeg-2.4.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 612e9bde3c5c75f1e1fb4a9cda606b7808912ec251860f49b01b3d891b9394bd
MD5 f6f9630a7fc2c2fe85a72a1d3765f297
BLAKE2b-256 8c75f54221d7a6d723aed9871727e8f683b217585591c7d58fc36118cd0f3faa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for h5ffmpeg-2.4.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 590ac6a8c02e214966c150f1e85570897914c7181e656036691ecab602be8b85
MD5 edde1b6a4fafda5de75d5858eb36387f
BLAKE2b-256 c4f0fa8cc8f985bb202f5d862edb42240022c58e4c62d5cb1e8ffb2afb46cc3b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for h5ffmpeg-2.4.0-cp311-cp311-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 3b4336e1ba7f3455e0e7491c87452d8a4021dd6a3775eabc1307a57ddfb88fec
MD5 b6c2c451eeab4afed700ad77b6b42c2b
BLAKE2b-256 795a9294cb7ae885edd4a349c2ba9eea691a1d39a7cf7d4006328c1516e0939b

See more details on using hashes here.

File details

Details for the file h5ffmpeg-2.4.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: h5ffmpeg-2.4.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 34.6 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for h5ffmpeg-2.4.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 56cebd0d01aee95e3f2d9ff0e1f71edcff66626c55b554293a4f20f10fd34722
MD5 9a4aa7e75ec926f6f1456699c3a1c52c
BLAKE2b-256 4d17adc4b97a68667c8db39439f2c9e3f902207251fb4b685d5eb9d0526c4e8c

See more details on using hashes here.

File details

Details for the file h5ffmpeg-2.4.0-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for h5ffmpeg-2.4.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 842a20b77630391bcd16319ebd48f04baf6cfa85f61317220d8268ce57f88771
MD5 21da9ac285e61b83d6319b5b7149e9a7
BLAKE2b-256 b0f6c82c4f298018d33489e848bf0f44b71ad71c3669929fea78100cdc382d30

See more details on using hashes here.

File details

Details for the file h5ffmpeg-2.4.0-cp310-cp310-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for h5ffmpeg-2.4.0-cp310-cp310-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 b6639030db5e5754f868db10b2d36236c6297cf4d268ba49d73817f7571e75cc
MD5 b4d05fecca04d32df9dd790e1de6ccae
BLAKE2b-256 f5f11029720f7247fb4ede0aa57d65c8ee979748aa457d9ba07c71361478cb01

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