Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

mp4-py

PyPI SPEC 0 — Minimum Supported Dependencies image License Actions status

About Shiguredo's open source software

We will not respond to PRs or issues that have not been discussed on Discord. Also, Discord is only available in Japanese.

Please read https://github.com/shiguredo/oss/blob/master/README.en.md before use.

時雨堂のオープンソースソフトウェアについて

利用前に https://github.com/shiguredo/oss をお読みください。

mp4-py について

mp4-rust の Python バインディングです。 MP4 コンテナフォーマットの読み書きをサポートしています。

対応プラットフォーム

  • macOS 26 arm64
  • macOS 15 arm64
  • Ubuntu 24.04 x86_64 (manylinux2014 wheel は glibc 2.17+ 対応)
  • Ubuntu 24.04 arm64 (manylinux2014 wheel は glibc 2.17+ 対応)
  • Windows Server 2025 x86_64
  • Windows 11 x86_64

対応 Python

  • 3.14 (abi3 wheel: 3.12/3.13/3.14 共通)
  • 3.14t (Free-Threading, 専用 wheel)
  • 3.13 (abi3 wheel)
  • 3.12 (abi3 wheel)

インストール

uv add mp4-py

使い方(基本 API)

  • Mp4FileDemuxer / Mp4FileMuxer
  • ビデオ/オーディオトラックの読み書きをサポート
  • Opus / AAC / FLAC 音声コーデック対応
  • VP8 / VP9 / AV1 / H.264 / H.265 映像コーデック対応
  • Python Free Threading 対応

MP4 ファイルの読み込み

import io
from mp4 import Mp4FileDemuxer

# ファイルパスから demuxer を作成
with Mp4FileDemuxer("input.mp4") as demuxer:
    # サンプルを走査して処理
    for sample in demuxer:
        print(f"Sample: {sample.timestamp_seconds}s, keyframe={sample.keyframe}")
        print(f"Data size: {len(sample.data)} bytes")

# バイナリストリームから demuxer を作成
with open("input.mp4", "rb") as fp:
    demuxer = Mp4FileDemuxer(fp)
    for sample in demuxer:
        # サンプルを処理...
        pass

MP4 ファイルの作成

import io
from mp4 import (
    Mp4FileMuxer,
    Mp4MuxSample,
    Mp4SampleEntryVp08,
)


# ファイルにマルチプレックス
with Mp4FileMuxer("output.mp4") as muxer:
    # VP8 ビデオサンプルエントリーを作成
    video_entry = Mp4SampleEntryVp08(
        width=1920,
        height=1080,
    )

    # フレームを追加
    for i in range(30):
        is_keyframe = (i % 10) == 0  # 10フレームごとにキーフレーム

        # ビデオデータ(実際のエンコード済みデータに置き換えてください)
        video_data = b'\x00' * 1000

        # サンプルを作成して追加
        sample = Mp4MuxSample(
            track_kind="video",
            sample_entry=video_entry,
            keyframe=is_keyframe,
            timescale=30,
            duration=1,
            data=video_data,
        )
        muxer.append_sample(sample)

    # finalize() を呼んでファイルを完成させる(自動的に呼ばれるが明示的に呼ぶこともできます)

# バイナリストリームにマルチプレックス
with open("output.mp4", "wb") as fp:
    with Mp4FileMuxer(fp) as muxer:
        # マルチプレックス処理...
        pass

トラック情報の取得

from mp4 import Mp4FileDemuxer

with Mp4FileDemuxer("input.mp4") as demuxer:
    for track in demuxer.tracks:
        print(f"Track ID: {track.track_id}")
        print(f"Kind: {track.kind}")  # 'video' または 'audio'
        print(f"Duration: {track.duration_seconds:.2f}s")

[!WARNING]

  • 現在は基本的な読み書き機能をサポートしています
  • マルチプレックス時は最初のサンプルで sample_entry を必須で指定してください
  • 同じトラック内で同じコーデック設定が続く場合、sample_entryNone を指定できます

サンプル

  • examples/demux.py: MP4 ファイルをデマルチプレックスしてトラックとサンプル情報を表示
  • examples/remux.py: MP4 ファイルをリマルチプレックス(読み込んで別ファイルに書き込む)

実行例:

uv run python examples/demux.py input.mp4
uv run python examples/remux.py input.mp4 output.mp4

開発ビルド

# maturin をインストール
uv pip install maturin

# 開発ビルド (editable install)
maturin develop --release

# wheel を生成
maturin build --release --out wheelhouse --generate-stubs

# テスト
uv pip install pytest pytest-timeout hypothesis
uv run pytest tests/ --timeout=30

Rust 側は crates.io の shiguredo_mp4 を通常の cargo 依存として参照している (Cargo.toml を参照)。

mp4-rust ライセンス

Apache License 2.0

Copyright 2024-2026, Takeru Ohta (Original Author)
Copyright 2024-2026, Shiguredo Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

mp4-py ライセンス

Apache License 2.0

Copyright 2025 Takeru Ohta (Original Author)
Copyright 2025 Shiguredo Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Download files

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

Source Distribution

mp4_py-2026.2.0.dev1.tar.gz (104.2 kB view details)

Uploaded Source

Built Distributions

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

mp4_py-2026.2.0.dev1-cp314-cp314t-win_amd64.whl (321.9 kB view details)

Uploaded CPython 3.14tWindows x86-64

mp4_py-2026.2.0.dev1-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (475.9 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64

mp4_py-2026.2.0.dev1-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (481.5 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ARM64

mp4_py-2026.2.0.dev1-cp314-cp314t-macosx_11_0_arm64.whl (437.9 kB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

mp4_py-2026.2.0.dev1-cp312-abi3-win_amd64.whl (324.8 kB view details)

Uploaded CPython 3.12+Windows x86-64

mp4_py-2026.2.0.dev1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (476.5 kB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ x86-64

mp4_py-2026.2.0.dev1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (483.0 kB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ ARM64

mp4_py-2026.2.0.dev1-cp312-abi3-macosx_11_0_arm64.whl (438.6 kB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

File details

Details for the file mp4_py-2026.2.0.dev1.tar.gz.

File metadata

  • Download URL: mp4_py-2026.2.0.dev1.tar.gz
  • Upload date:
  • Size: 104.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for mp4_py-2026.2.0.dev1.tar.gz
Algorithm Hash digest
SHA256 982ee39126b587afacbb5ca05dd9be6d122043519171df653dd6b2908bdacd50
MD5 06cf388cddd50fc1316b8dc827642035
BLAKE2b-256 4a3d994fad1f573229ae6a3172ed46f2a3b0107fbb39bcce993e7ef16632a238

See more details on using hashes here.

Provenance

The following attestation bundles were made for mp4_py-2026.2.0.dev1.tar.gz:

Publisher: wheel.yml on shiguredo/mp4-py

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

File details

Details for the file mp4_py-2026.2.0.dev1-cp314-cp314t-win_amd64.whl.

File metadata

File hashes

Hashes for mp4_py-2026.2.0.dev1-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 0fae3be14ff443a4403b801a75f35012e0286c3857aa5b2479b1d82961cd35a0
MD5 1f19e84ff1d66c7af209b7e18bd581cc
BLAKE2b-256 d672912e2c0dc587d8a67f8e50017d972fb6df6a004a0308faff3af993823024

See more details on using hashes here.

Provenance

The following attestation bundles were made for mp4_py-2026.2.0.dev1-cp314-cp314t-win_amd64.whl:

Publisher: wheel.yml on shiguredo/mp4-py

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

File details

Details for the file mp4_py-2026.2.0.dev1-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mp4_py-2026.2.0.dev1-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dfeef4168929b947da07329a824b66cc66ef28aa44151d05ce2c7734fc3b6d82
MD5 f2f8030bce4695bdfa92e30cdeff0743
BLAKE2b-256 16a349763b28563635d58ba56bd7001ae05f509c34f8b732aa0d06658a7abea8

See more details on using hashes here.

Provenance

The following attestation bundles were made for mp4_py-2026.2.0.dev1-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheel.yml on shiguredo/mp4-py

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

File details

Details for the file mp4_py-2026.2.0.dev1-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for mp4_py-2026.2.0.dev1-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e985a2c57f2a6dd49d957b1210a9a4aca57ec08de3b2da049e43041b3d903f67
MD5 ef93934370114df0e3e87d9d7fe2b3ed
BLAKE2b-256 fd0af67497bedbcef665327679b983a351014f22790121ebf7ac137cd5e717c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for mp4_py-2026.2.0.dev1-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: wheel.yml on shiguredo/mp4-py

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

File details

Details for the file mp4_py-2026.2.0.dev1-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mp4_py-2026.2.0.dev1-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c5fe517f5436ce7899dc0b3cbcb7870f43a8e712aabda3e6dd33b9b25f671cfd
MD5 4c2ac749b36c8fc59930b4c5fed15266
BLAKE2b-256 bc232644ab935195a067af6dc539e9307df7849cc2be4a15c8336557cf000853

See more details on using hashes here.

Provenance

The following attestation bundles were made for mp4_py-2026.2.0.dev1-cp314-cp314t-macosx_11_0_arm64.whl:

Publisher: wheel.yml on shiguredo/mp4-py

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

File details

Details for the file mp4_py-2026.2.0.dev1-cp312-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for mp4_py-2026.2.0.dev1-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 d6f2ecffebbb1b4b63a71071626daeec72a444e5a85c58499a30788e5054eff1
MD5 f35fdad3de4a137aba01f71203d99be4
BLAKE2b-256 afa5c963ec8eae207a39c109024d53959efc91b013e408441a2837fc91829954

See more details on using hashes here.

Provenance

The following attestation bundles were made for mp4_py-2026.2.0.dev1-cp312-abi3-win_amd64.whl:

Publisher: wheel.yml on shiguredo/mp4-py

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

File details

Details for the file mp4_py-2026.2.0.dev1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mp4_py-2026.2.0.dev1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c2c7e3cb702895989ef79860adeb201f2d32b4283af440a546058ef64810e840
MD5 4972e700915bf7a17c837fbdbaf2dd8a
BLAKE2b-256 95c9d843c5f5533dbfe87944f4311b2647072327275ed9c1c7a97492c28ea186

See more details on using hashes here.

Provenance

The following attestation bundles were made for mp4_py-2026.2.0.dev1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheel.yml on shiguredo/mp4-py

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

File details

Details for the file mp4_py-2026.2.0.dev1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for mp4_py-2026.2.0.dev1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 601cfb6297b45b6f47d2c89c36749e07ba390e9e984d96fa4e829fc66ad84b72
MD5 b9961420eff5dbbe5a1aaf292c97def9
BLAKE2b-256 73cc6addc29adeb3d3bcec77d47b11b6f752f9de92b9e201e08ae90962a6fc40

See more details on using hashes here.

Provenance

The following attestation bundles were made for mp4_py-2026.2.0.dev1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: wheel.yml on shiguredo/mp4-py

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

File details

Details for the file mp4_py-2026.2.0.dev1-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mp4_py-2026.2.0.dev1-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4303ec8573e8162d31458c3e2abaed3e2d3bbe453dc61c91eebd76a0a3c4bd5b
MD5 6416fe7a8c5cb84dcfdcfb938c6daf6c
BLAKE2b-256 6a074ff6283318146552ac553bcc9cf0697f6577ebd60562dd9e043091d0eaa9

See more details on using hashes here.

Provenance

The following attestation bundles were made for mp4_py-2026.2.0.dev1-cp312-abi3-macosx_11_0_arm64.whl:

Publisher: wheel.yml on shiguredo/mp4-py

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 Sentry Error logging StatusPage Status page