Skip to main content

Python bindings for mp4-rust

Project description

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
  • macOS 14 arm64
  • Ubuntu 24.04 x86_64
  • Ubuntu 24.04 arm64

対応予定プラットフォーム

  • Windows 11 x86_64

対応 Python

  • 3.14
  • 3.13
  • 3.12

インストール

uv add mp4-py

使い方(基本 API)

  • 提供: Mp4FileDemuxer, Mp4FileMuxer
  • ビデオ/オーディオトラックの読み書きをサポート
  • VP8/VP9/AV1、H.264/H.265、Opus/AAC/FLAC コーデック対応

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

ビルド

uv build --wheel

mp4-rust ライセンス

Apache License 2.0

Copyright 2024-2025, Takeru Ohta (Original Author)
Copyright 2024-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.

mp4-py ライセンス

Apache License 2.0

Copyright 2025-2025, Takeru Ohta (Original Author)
Copyright 2025-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.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

mp4_py-2025.1.0.dev4-cp314-cp314-manylinux_2_34_x86_64.whl (336.4 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

mp4_py-2025.1.0.dev4-cp314-cp314-manylinux_2_34_aarch64.whl (321.8 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

mp4_py-2025.1.0.dev4-cp314-cp314-macosx_15_0_arm64.whl (335.2 kB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

mp4_py-2025.1.0.dev4-cp314-cp314-macosx_14_0_arm64.whl (335.2 kB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

mp4_py-2025.1.0.dev4-cp313-cp313-manylinux_2_34_x86_64.whl (336.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

mp4_py-2025.1.0.dev4-cp313-cp313-manylinux_2_34_aarch64.whl (321.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

mp4_py-2025.1.0.dev4-cp313-cp313-macosx_15_0_arm64.whl (335.2 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

mp4_py-2025.1.0.dev4-cp313-cp313-macosx_14_0_arm64.whl (335.2 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

mp4_py-2025.1.0.dev4-cp312-cp312-manylinux_2_34_x86_64.whl (336.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

mp4_py-2025.1.0.dev4-cp312-cp312-manylinux_2_34_aarch64.whl (321.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

mp4_py-2025.1.0.dev4-cp312-cp312-macosx_15_0_arm64.whl (335.2 kB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

mp4_py-2025.1.0.dev4-cp312-cp312-macosx_14_0_arm64.whl (335.2 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

File details

Details for the file mp4_py-2025.1.0.dev4-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev4-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d7ab94dc8935db49e38a1b093202f063262528adb552b14529e3c72219cf22d1
MD5 7221f76889052cee4ba6e835572484d5
BLAKE2b-256 206f0f6edf6b99f1d09d472c3d12208e46fab77dd9d6613776d1c468d1b58fa8

See more details on using hashes here.

Provenance

The following attestation bundles were made for mp4_py-2025.1.0.dev4-cp314-cp314-manylinux_2_34_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-2025.1.0.dev4-cp314-cp314-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev4-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 ef8ac08d2df54826e78c333fa009bada01ebdda6a846655e43b36431a6b09540
MD5 41b686d6f444f07af0dd123f02b97f62
BLAKE2b-256 d2c01a41385cd9fce0036aab7b5b9726858af517ceb5b5662cf9889e9b2ae41f

See more details on using hashes here.

Provenance

The following attestation bundles were made for mp4_py-2025.1.0.dev4-cp314-cp314-manylinux_2_34_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-2025.1.0.dev4-cp314-cp314-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev4-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 b5509af49ad4839d15fff8739e34850a68d6594e0d876f73c63ff34b4b844019
MD5 f9366d80b1c9a72f0ec8ceec0a368b50
BLAKE2b-256 810fb3e23964a49850ef92aac793603bd023074d87811db56dcb4f4ac6a57bd8

See more details on using hashes here.

Provenance

The following attestation bundles were made for mp4_py-2025.1.0.dev4-cp314-cp314-macosx_15_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-2025.1.0.dev4-cp314-cp314-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev4-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 6410b042a36635bbcc76f7db6bc33c4b713213e0a414b64414795a828f33a5c0
MD5 e56e8ee451e5e8d6d55d350ebcb4a0f8
BLAKE2b-256 3f8bf1d69c78967be6f06642a668d3a4edc01a84e60ea0730b9f6a80a9d13f59

See more details on using hashes here.

Provenance

The following attestation bundles were made for mp4_py-2025.1.0.dev4-cp314-cp314-macosx_14_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-2025.1.0.dev4-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev4-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 453c8e7a845a27349d02e130592a9539492279ed6459e1b59700773257f0439d
MD5 9fbb6377056f1e7c47a71abe31d4e373
BLAKE2b-256 ec013bd504aa14f346810757ab04a4b03a3a61318f8c3233be94c490297ab89e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mp4_py-2025.1.0.dev4-cp313-cp313-manylinux_2_34_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-2025.1.0.dev4-cp313-cp313-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev4-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 3ff70a63f50583e2667c9a1dd596e75e507742c9d790bde4e6de6ea3e4534993
MD5 b1b6476c93c770eddc4e044fb4cd423f
BLAKE2b-256 4b7ecb51a1de7b7028cf17538155b1e60fc87a654908e4ba505307697207c7a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for mp4_py-2025.1.0.dev4-cp313-cp313-manylinux_2_34_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-2025.1.0.dev4-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev4-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 b7fcd6d4e61f131797ac6605cbe6d4f2dc9237aa31833b108ad4d57db91d2b25
MD5 f44c933e09e028e74fcf5ef0544c4d6d
BLAKE2b-256 b44f5da55f9e626f0817d5f1fe9e23c7d38b2682a074112da435beefb150f4e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for mp4_py-2025.1.0.dev4-cp313-cp313-macosx_15_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-2025.1.0.dev4-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev4-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 546a0303ce488c61ac88122e62bdcc147ef6afdfc39dc75d41fb16eb23a6b991
MD5 1ee8efcadfa5621487c7c9f4e769ba1f
BLAKE2b-256 049409a8ba59b03e6bf1697ca3b7eeac7a7535b825396e79cab9983f19157629

See more details on using hashes here.

Provenance

The following attestation bundles were made for mp4_py-2025.1.0.dev4-cp313-cp313-macosx_14_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-2025.1.0.dev4-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev4-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 938270cdd26ade7c0b8a74a7ec668158320261bc1548f0f4a6508c24eca0e5e3
MD5 1fb00b23a836f428ffa8a6c515a6eb3d
BLAKE2b-256 8c3c15238d6be49a2b04bca99ae089508edfd0ca2eb477a997116719ce3de73f

See more details on using hashes here.

Provenance

The following attestation bundles were made for mp4_py-2025.1.0.dev4-cp312-cp312-manylinux_2_34_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-2025.1.0.dev4-cp312-cp312-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev4-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 f79bbb36f0fa921322a38eaf5d861e4890b43be5a147908befc54abc177284da
MD5 6446d9ac9af1544b840b6a4a8d8c6425
BLAKE2b-256 e2b8515cb6f86e06b349bdb1d8256def6bb4fc72ee8f45664c079900dc69f35f

See more details on using hashes here.

Provenance

The following attestation bundles were made for mp4_py-2025.1.0.dev4-cp312-cp312-manylinux_2_34_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-2025.1.0.dev4-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev4-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 fc5ad65c2ac1c5f79370e1ceed69e72fe12bcb98e0762298a56cd1508be52a33
MD5 36707231486df72a9876a41de8de304b
BLAKE2b-256 a95383993ad1372ddc889835e1d4c62b870fed9ff7d39909c3f03cc99df61a5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mp4_py-2025.1.0.dev4-cp312-cp312-macosx_15_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-2025.1.0.dev4-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev4-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a15f3849123d8687745a070d5b479b601571f42dfd405bb55412a883474620d1
MD5 1eeea0aec43007d99287088703bc177c
BLAKE2b-256 53bdda510800f460cf5cecd39009ad5fa4e6eb700611f2c77de7cb3d93f1b146

See more details on using hashes here.

Provenance

The following attestation bundles were made for mp4_py-2025.1.0.dev4-cp312-cp312-macosx_14_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 Pingdom Monitoring Sentry Error logging StatusPage Status page