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
  • Ubuntu 22.04 x86_64
  • Ubuntu 22.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 コーデック対応

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.dev3-cp314-cp314-manylinux_2_34_x86_64.whl (312.3 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

mp4_py-2025.1.0.dev3-cp314-cp314-manylinux_2_34_aarch64.whl (296.4 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

mp4_py-2025.1.0.dev3-cp314-cp314-macosx_15_0_arm64.whl (310.6 kB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

mp4_py-2025.1.0.dev3-cp314-cp314-macosx_14_0_arm64.whl (310.6 kB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

mp4_py-2025.1.0.dev3-cp313-cp313-manylinux_2_34_x86_64.whl (312.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

mp4_py-2025.1.0.dev3-cp313-cp313-manylinux_2_34_aarch64.whl (296.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

mp4_py-2025.1.0.dev3-cp313-cp313-macosx_15_0_arm64.whl (310.6 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

mp4_py-2025.1.0.dev3-cp313-cp313-macosx_14_0_arm64.whl (310.6 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

mp4_py-2025.1.0.dev3-cp312-cp312-manylinux_2_34_x86_64.whl (312.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

mp4_py-2025.1.0.dev3-cp312-cp312-manylinux_2_34_aarch64.whl (296.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

mp4_py-2025.1.0.dev3-cp312-cp312-macosx_15_0_arm64.whl (310.6 kB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

mp4_py-2025.1.0.dev3-cp312-cp312-macosx_14_0_arm64.whl (310.6 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

File details

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev3-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ea1d81495563d178ca27d59c1cf696792008ae5b9f3bd8358b05af73c6249092
MD5 3a2128e2b4e9028500a9c2dbd6bd8f91
BLAKE2b-256 c7257850fe798251b2331f7840d99864ba9add5df2324f0ac50221dbe45234f8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev3-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 4719fe3e6fbee232f47646f716636a92c781c0d8b1b4e676a823e21fa88b5b53
MD5 b1ff66b0ea92b9d8f1833b24abb8ca93
BLAKE2b-256 64ed9e360e28c61600b621509cb118e61f2085b735c90b7c07add71dc5ab6a0d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev3-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 82b2fdc7c8921ec207a7bd13890fea7a587f2bede3ebeba9923459ffa2f20101
MD5 8f7beb2d4ac9fc5bc195fcbca92ff5a4
BLAKE2b-256 8b4e3e5bd78cbdef46ecbcacbe55a622531c16031fed1bd99c0a286080d7b295

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev3-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 61c3932f573243dfeccfaaaff862cb4467c064b5f64e61bc53391891dd9dea3a
MD5 92783f7fa7d1099d33883a19affb2c45
BLAKE2b-256 7ac390b9b548a7b255e433a66f317403146c87fa0c162cde3747a6014527f4df

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev3-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 41095c9cfd60b4ffedc3729ca3940391a83d8ad28697740d1d1e7a106a41deca
MD5 77b6dc8b484cac11fc0ecee6e136d39b
BLAKE2b-256 4644c83a4558422484efa6aa8c366d6632b70d8c6fd6745b034caae84835f3ab

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev3-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 4932ace34c689b0a41b5c966ac3718768aa2f5bf3047a3f5afd8869dd7f901b4
MD5 f8aef746ced3c0d236d6568e57ed41a3
BLAKE2b-256 39d2c64696ae54b57f9f2661c11f81ba50e1752c8f3cbfdb4dfde7bc1087e49f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev3-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 084b84afe46c047d62060fca73eedd8e9ea2aff35eaae2ce4b931071bba1c694
MD5 0f8c780687d78dd146092246d8442cd6
BLAKE2b-256 fb22a3ddd6e2e9cd0991faaa635f6e349c908913e0c83a62f24a3afb6c6b4749

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev3-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 cf67ff5711c03e1334027fd9684a7789ea63e618a7891c2c81452c60b83d2b98
MD5 4c4ceccb4e8274d4f7966d2e7b8e537b
BLAKE2b-256 af2afa9fe19ed68156e23668973d5f5f4cb0758805241622ce6fe9a104296be3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev3-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3bbda893b82345d6643f759877d1dfcb627934ba452adad87fa607fc2b878909
MD5 f7e440ba5a22b2a774a5d950e4b5e957
BLAKE2b-256 c6d5a4f70c27ec97b236ef450030a4abf1b0d0fdec5f77fbe80f3e6801005454

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev3-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 bbd6842a99d1aca6dc813dc3265d2ed1fca93c591a10280a25cc4e8833eedd05
MD5 b89319e07a1a58abe27307ce7125cb7b
BLAKE2b-256 b765eb483eee3019231717a79d586b41405b79b272501a6a8b98b928411f0c21

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev3-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 701da23baa0ed0de680a31277348d9a5554c4c5c2527dee163534f862b1259d6
MD5 ea2a9e66d52e7285ea206d5f38e1e81c
BLAKE2b-256 80462474efd5aee3e3bb43932fd650e46cf688ba7c4654caa8a8f94551e0850b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev3-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 1e00480e15f837a8c22ac3ce4dfaf82db3f6c5e338b5c7e5544b39c43d72349b
MD5 5440055fc7be806bf73b159ed1596f39
BLAKE2b-256 fc8e36c047d5755cbddf84e84dda3b10476086abccd670d8223cdcc26731c946

See more details on using hashes here.

Provenance

The following attestation bundles were made for mp4_py-2025.1.0.dev3-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