Skip to main content

Python bindings for mp4-rust

Project description

mp4-py

PyPI 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 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.dev2-cp314-cp314-manylinux_2_34_x86_64.whl (312.2 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

mp4_py-2025.1.0.dev2-cp314-cp314-manylinux_2_34_aarch64.whl (296.3 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

mp4_py-2025.1.0.dev2-cp314-cp314-macosx_15_0_arm64.whl (310.5 kB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

mp4_py-2025.1.0.dev2-cp314-cp314-macosx_14_0_arm64.whl (310.5 kB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

mp4_py-2025.1.0.dev2-cp313-cp313-manylinux_2_34_x86_64.whl (312.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

mp4_py-2025.1.0.dev2-cp313-cp313-manylinux_2_34_aarch64.whl (296.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

mp4_py-2025.1.0.dev2-cp313-cp313-macosx_15_0_arm64.whl (310.5 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

mp4_py-2025.1.0.dev2-cp313-cp313-macosx_14_0_arm64.whl (310.5 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

mp4_py-2025.1.0.dev2-cp312-cp312-manylinux_2_34_x86_64.whl (312.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

mp4_py-2025.1.0.dev2-cp312-cp312-manylinux_2_34_aarch64.whl (296.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

mp4_py-2025.1.0.dev2-cp312-cp312-macosx_15_0_arm64.whl (310.5 kB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

mp4_py-2025.1.0.dev2-cp312-cp312-macosx_14_0_arm64.whl (310.5 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

File details

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev2-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 46905fe845416b4b55b816c53033aeac1e388851d08bb0a270ceebbf096cc1ea
MD5 f010b49a5d98a9a4070696a95e3a9608
BLAKE2b-256 4e3732604ede0d947b547d9c62f52c74830b3685fca57035b28e6a2ce1bbd40f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev2-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 ef64bd5d55ccb4b79b994c17a4562ab2d15e1de3e1991df846597bec7bd8443e
MD5 85c0f8e4f9a240aa0d18756b91caf851
BLAKE2b-256 5422098613919aff35c8b12616198986d557b2824023f1eee1381f4141c26ac4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev2-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 5fae618cd83a1b245204c8cbb3d6568c9a5c5ba17619a54c7d6e3d15d69372ac
MD5 11f524279d3d26e275275c20d0be8693
BLAKE2b-256 e24c43158c141e10ee01713c4c7c46cbf51dcb3e4af8658516fd50e90b3eed7c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev2-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 63019c981209f5e6079bb8de2d5331b241a67ccfad5f7fcb49afb14ea03d05b3
MD5 34eeb2c480b1df236f70f6be58ad4933
BLAKE2b-256 7d165b828bf7424493fc06a86ce41a2f7a30e22a2a24d44aa3eca30d0739e671

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev2-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b3dc19973f609310aa35c3abd6d47ba130e9cc00ab2894c50d3d9846c8f9cd99
MD5 800ed46bfb3d79458e69693f02b1cadd
BLAKE2b-256 cb8d73f87bcd743bd5063e6322075040c0d55fe382d9577728755fdbeda58fda

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev2-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 b5988905bebc180cd33ddcd0cd47b3acecd097c623dad02bc13e4e2bd2e07323
MD5 dce3121b52c1d9b2b31460afb488e00d
BLAKE2b-256 9c0856ef6ed7ba84db5d9af0fa7a1a446e9ce31481c2b08e354f021dbb462881

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev2-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 db081cd9f5a7ba797f6474b75d3dd15c73b2ae0a560b65627ad88a0ffe6ceda0
MD5 6779355eb12054b8b4eaca334ce505cf
BLAKE2b-256 c085d26480a529f995c0774d083ee726c7658bfa8f3ff217c36574b168e73d00

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev2-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 ee55f116feed3f5e00e94814e30a4069134ccd2d34b0b11b31228a048dc4ca5e
MD5 cb607e9ae4d1f71261061a1c4d126db3
BLAKE2b-256 6542c0c769c2b81aad9283fd82d993f2d71c02b50b90db36626f2e501cf737c4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev2-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e4bac46cf4c641a13d143e6cb12f491d09d4201dc8a5fe0db6b6d7facea4f78a
MD5 e7940b055a697cc33c3458c63d29e847
BLAKE2b-256 80217414f1d50fa522b579294b14e77148281434450c580ca031c3d5f6078448

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev2-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 0a3da1b50966af564a63bd2850d165be92a91544e7bc3fc3590a1c1ea29c8043
MD5 7befb80ff1655bc2e354022ed8b750b6
BLAKE2b-256 e4d65e2b012eb2a98ef0983668b00d87e28a37678e3b65e686a0ed064a78310d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev2-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 dd26e386c71f9487043253956bec71dbb85d9fbf42c36a9b338339bf99ef87cb
MD5 d1d7513557707d8c328e25758a4f166b
BLAKE2b-256 6442dfc029e11d5191a84f8eaa72a553dc4e7097240bc94b86e85ca3b9f12a42

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mp4_py-2025.1.0.dev2-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c1afa2c6d86b3df57152018f2c683ab0a211b5594362b959310a560cfec82eb1
MD5 8757265e8fb3434211f398e551d1a048
BLAKE2b-256 059bbdf53e94cbed7a912114ec15492d28c4eeee25bb56aa32f53f68dd2f5433

See more details on using hashes here.

Provenance

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