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.2.4.tar.gz (62.6 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.2.4-cp313-cp313-win_amd64.whl (34.6 MB view details)

Uploaded CPython 3.13Windows x86-64

h5ffmpeg-2.2.4-cp313-cp313-manylinux_2_34_x86_64.whl (36.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

h5ffmpeg-2.2.4-cp313-cp313-macosx_12_0_arm64.whl (24.8 MB view details)

Uploaded CPython 3.13macOS 12.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.12macOS 12.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

h5ffmpeg-2.2.4-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.2.4.tar.gz.

File metadata

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

File hashes

Hashes for h5ffmpeg-2.2.4.tar.gz
Algorithm Hash digest
SHA256 fe7bc8f546d245f1ff5008aeba403baefae7e1868db649614f7a8d1582a7491b
MD5 102008606322bb33df47d1e41c8b39ed
BLAKE2b-256 33b6a939f8c1b1983224762cda642351600bb59a078b68b109fde9a2e92acdc3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: h5ffmpeg-2.2.4-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.1.0 CPython/3.11.13

File hashes

Hashes for h5ffmpeg-2.2.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 cac880e4bca429ea9394c6ac2b82d1904c8bc3a407fefe1bd0c4c4ff23c22c9d
MD5 c02ef55c64f96deec54a5d3820d86d34
BLAKE2b-256 8b01aba52252ceb6a01b51b3cd1b10677aa6020555d64ee7e460ba3dd72be63d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for h5ffmpeg-2.2.4-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c63a2d899537905be018e769c828871e7583f2c986555918579b6533003640eb
MD5 f9293392512826f6144feaf01df9fd23
BLAKE2b-256 e3330e163454eeb44bc9cd82f41b63c4f256f3260112cbf6531433ddd5255c81

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for h5ffmpeg-2.2.4-cp313-cp313-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 6b3f4dbca422a1130f51892fb239fc40156357b29cbfa36189e11f0cd9d364cf
MD5 abf83fe189b44fa2df89528a03c83e5e
BLAKE2b-256 b5ba42664a21ea979419bd6b7974e54bddc1acfe9ead7f064b4f87d4c576e383

See more details on using hashes here.

File details

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

File metadata

  • Download URL: h5ffmpeg-2.2.4-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.13

File hashes

Hashes for h5ffmpeg-2.2.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5c879f633a43c23764136c375e6f784a340147a65b8989af982ee00726bbd8cd
MD5 3b3b79b525239accdd99df158b7b1492
BLAKE2b-256 e195ce9a871eabb932ed8c3c8c8834d0bab6e2c7d621a20b49ca301d5f3b9fad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for h5ffmpeg-2.2.4-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b6b1c8a41f0f10c615e3c3db2027cee5b44f93190505dad5c3c5cc93cbc421f8
MD5 6823ae99cfe895ab0d556125e9d0d11d
BLAKE2b-256 6e10e18bb8e1a9af9788b208783bc76be0503bfe58defbe8394f63c6a8ef7177

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for h5ffmpeg-2.2.4-cp312-cp312-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 caa8329a3cdcceec92540b06bb399e918f68207403bfaef9146003e576b0a367
MD5 056635316c2d0568c33bd9a41cf95a8b
BLAKE2b-256 039ff99055707bbfc2271e72f436ebec3fdd37950b106bddde286dc8f335dce2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: h5ffmpeg-2.2.4-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.13

File hashes

Hashes for h5ffmpeg-2.2.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6ca6f08e33cc3993a84287438f0453dfc84705cb372d008f60a123aa095cea68
MD5 67d4b322fc3131b86118c9df9a874201
BLAKE2b-256 999dfa9e0cbaf4a3f9869cb1ca0517e88581eed96d61517b84af83d0e2506122

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for h5ffmpeg-2.2.4-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 30e8a189b4041ee54753e9b893e47d2d455ad58a54b8c9a156e929a9a94bc718
MD5 966be77fa7ca14ea2b7d285f35726579
BLAKE2b-256 fb7af0f6d7b962139854f5e60724d7fbfa375a53b4f13acb84cd0d213401a74c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for h5ffmpeg-2.2.4-cp311-cp311-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 1d53f6fc02762f57b515a80abeab65701deaab88b8d609b46a11579c398b6fb0
MD5 044d2b89b6b74c2f6d17dc6ad5ffafa2
BLAKE2b-256 34cf02e9745c7d4c1ffda165d591fea4b509936c7750ebbe58346410c720ed18

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