Skip to main content

webcodecs-py

Project description

webcodecs-py

[!CAUTION] webcodecs-py はまだ開発中であり、安定版ではありません。将来的に API が変更される可能性があります。 開発状況は webcodecs-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 をお読みください。

webcodecs-py について

webcodecs-py は WebCodecs API に似た API を Python で利用できるようにするライブラリです。

特徴

  • WebCodecs API に寄せた Python バインディング
  • Opus、FLAC、AV1、H.264、H.265 コーデックをサポート
    • H.264 と H.265 は macOS の VideoToolbox を利用
  • クロスプラットフォーム対応
    • macOS
    • Ubuntu
    • Windows

実装しない機能

  • ImageDecoder(画像デコード機能は PIL/Pillow や OpenCV を使用してください)

サンプルコード

Opus オーディオエンコード

import numpy as np

from webcodecs import (
    AudioData,
    AudioDataInit,
    AudioEncoder,
    AudioEncoderConfig,
    AudioSampleFormat,
)

sample_rate = 48000
frame_size = 960  # 20ms @ 48kHz

# エンコーダを作成
encoded_chunks = []


def on_output(chunk):
    encoded_chunks.append(chunk)


def on_error(error):
    raise RuntimeError(f"エンコーダエラー: {error}")


encoder = AudioEncoder(on_output, on_error)
encoder_config: AudioEncoderConfig = {
    "codec": "opus",
    "sample_rate": sample_rate,
    "number_of_channels": 1,
    "bitrate": 64000,
}
encoder.configure(encoder_config)

# サイン波を生成してエンコード
t = np.linspace(0, frame_size / sample_rate, frame_size, dtype=np.float32)
audio_samples = (np.sin(2 * np.pi * 440 * t) * 0.5).reshape(frame_size, 1)

init: AudioDataInit = {
    "format": AudioSampleFormat.F32,
    "sample_rate": sample_rate,
    "number_of_frames": frame_size,
    "number_of_channels": 1,
    "timestamp": 0,
    "data": audio_samples,
}
audio_data = AudioData(init)
encoder.encode(audio_data)
encoder.flush()

print(f"エンコード完了: {len(encoded_chunks)} チャンク")

audio_data.close()
encoder.close()

AV1 ビデオエンコード

import numpy as np

from webcodecs import (
    LatencyMode,
    VideoEncoder,
    VideoEncoderConfig,
    VideoFrame,
    VideoFrameBufferInit,
    VideoPixelFormat,
)

width, height = 320, 240

# エンコーダを作成
encoded_chunks = []


def on_output(chunk):
    encoded_chunks.append(chunk)


def on_error(error):
    raise RuntimeError(f"エンコーダエラー: {error}")


encoder = VideoEncoder(on_output, on_error)
encoder_config: VideoEncoderConfig = {
    "codec": "av01.0.04M.08",
    "width": width,
    "height": height,
    "bitrate": 500_000,
    "framerate": 30.0,
    "latency_mode": LatencyMode.REALTIME,
}
encoder.configure(encoder_config)

# I420 フォーマットのテストフレームを作成
data_size = width * height * 3 // 2
frame_data = np.zeros(data_size, dtype=np.uint8)
init: VideoFrameBufferInit = {
    "format": VideoPixelFormat.I420,
    "coded_width": width,
    "coded_height": height,
    "timestamp": 0,
}
frame = VideoFrame(frame_data, init)

# エンコード
encoder.encode(frame, {"keyFrame": True})
encoder.flush()

print(f"エンコード完了: {len(encoded_chunks)} チャンク, {encoded_chunks[0].byte_length} bytes")

frame.close()
encoder.close()

インストール

uv add webcodecs-py

コーデック

Python

  • 3.14
  • 3.13

プラットフォーム

  • macOS 26 arm64
  • macOS 15 arm64
  • Ubuntu 24.04 LTS x86_64
  • Ubuntu 24.04 LTS arm64
  • Ubuntu 22.04 LTS x86_64
  • Ubuntu 22.04 LTS arm64
  • Windows 11 x86_64

ビルド

make develop

テスト

uv sync
make test

サンプル

uv sync --group example
make develop
uv run python examples/blend2d_to_mp4.py

ライセンス

Apache License 2.0

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.

webcodecs_py-2025.1.0.dev2-cp314-cp314-win_amd64.whl (5.5 MB view details)

Uploaded CPython 3.14Windows x86-64

webcodecs_py-2025.1.0.dev2-cp314-cp314-manylinux_2_38_x86_64.whl (4.7 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.38+ x86-64

webcodecs_py-2025.1.0.dev2-cp314-cp314-manylinux_2_38_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.38+ ARM64

webcodecs_py-2025.1.0.dev2-cp314-cp314-manylinux_2_35_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.35+ x86-64

webcodecs_py-2025.1.0.dev2-cp314-cp314-manylinux_2_35_aarch64.whl (3.9 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.35+ ARM64

webcodecs_py-2025.1.0.dev2-cp314-cp314-macosx_15_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

webcodecs_py-2025.1.0.dev2-cp313-cp313-win_amd64.whl (5.4 MB view details)

Uploaded CPython 3.13Windows x86-64

webcodecs_py-2025.1.0.dev2-cp313-cp313-manylinux_2_38_x86_64.whl (4.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.38+ x86-64

webcodecs_py-2025.1.0.dev2-cp313-cp313-manylinux_2_38_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.38+ ARM64

webcodecs_py-2025.1.0.dev2-cp313-cp313-manylinux_2_35_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.35+ x86-64

webcodecs_py-2025.1.0.dev2-cp313-cp313-manylinux_2_35_aarch64.whl (3.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.35+ ARM64

webcodecs_py-2025.1.0.dev2-cp313-cp313-macosx_15_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

File details

Details for the file webcodecs_py-2025.1.0.dev2-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 6562ac11b515963649b42820482ac87e1e6645ec02a19d0b46eba0ba33dbe41c
MD5 d0ca2cf12ee4b9ca0ab8a9bcd5f5bf72
BLAKE2b-256 df3e59b930f8f4e521a63c78dd66ad30277f625f2bff0b1da3435d440c9702a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for webcodecs_py-2025.1.0.dev2-cp314-cp314-win_amd64.whl:

Publisher: wheel.yml on shiguredo/webcodecs-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 webcodecs_py-2025.1.0.dev2-cp314-cp314-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev2-cp314-cp314-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 b645972f63b18e087f23a8d7a65f71a7357d83d27d8f4519ac22cc9ae74ae412
MD5 3a2cf7d1c72b056986dac74371c7a93d
BLAKE2b-256 2b3ca25c6398b2c050a02c0c583fe365ea1cb076fe34370005cdd21807b6916b

See more details on using hashes here.

Provenance

The following attestation bundles were made for webcodecs_py-2025.1.0.dev2-cp314-cp314-manylinux_2_38_x86_64.whl:

Publisher: wheel.yml on shiguredo/webcodecs-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 webcodecs_py-2025.1.0.dev2-cp314-cp314-manylinux_2_38_aarch64.whl.

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev2-cp314-cp314-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 fe90d6e145c79757c559ce55cd21754829f7c708aa13be9a416afd8afa73a961
MD5 1c8abe156637c4f0628c49f3bc146017
BLAKE2b-256 ed3af2ed510c75b339092715e4c6b3fb71a9af8c48a294c0eb96632717b10d87

See more details on using hashes here.

Provenance

The following attestation bundles were made for webcodecs_py-2025.1.0.dev2-cp314-cp314-manylinux_2_38_aarch64.whl:

Publisher: wheel.yml on shiguredo/webcodecs-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 webcodecs_py-2025.1.0.dev2-cp314-cp314-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev2-cp314-cp314-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 531fb04acc554e295e995611be21c2b019011e63a68f7adfdcafba68f39b6517
MD5 e4069fc7b8291b11c9aed88284a98c0a
BLAKE2b-256 724883f7d9bd7ef46ff222d7e1c78208de5e2e954f8e2986597226f9ac2e998c

See more details on using hashes here.

Provenance

The following attestation bundles were made for webcodecs_py-2025.1.0.dev2-cp314-cp314-manylinux_2_35_x86_64.whl:

Publisher: wheel.yml on shiguredo/webcodecs-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 webcodecs_py-2025.1.0.dev2-cp314-cp314-manylinux_2_35_aarch64.whl.

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev2-cp314-cp314-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 cd4bc5bf8f9bc9c3ceaa0ecfb549054314ab7a0b6a1f6d78e39e1b12887922f8
MD5 5220f49dbbb6d8af3f51853feba70d46
BLAKE2b-256 30c93dc4b9dbfdcf4c6f652e6c63706ada7f1a58e7ed6c367dbbaefd09de9e58

See more details on using hashes here.

Provenance

The following attestation bundles were made for webcodecs_py-2025.1.0.dev2-cp314-cp314-manylinux_2_35_aarch64.whl:

Publisher: wheel.yml on shiguredo/webcodecs-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 webcodecs_py-2025.1.0.dev2-cp314-cp314-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev2-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 42453e2493a6bf4b80dbe4f71a1b23f253b530d752c25c963951b4446f4a976f
MD5 081d859210c206b22a9abc9ab643249e
BLAKE2b-256 e6587d31347a66e582ce6eec3e10137b8733839706e22dd604e4a164bae79551

See more details on using hashes here.

Provenance

The following attestation bundles were made for webcodecs_py-2025.1.0.dev2-cp314-cp314-macosx_15_0_arm64.whl:

Publisher: wheel.yml on shiguredo/webcodecs-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 webcodecs_py-2025.1.0.dev2-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3deca9c3dc219e4576bd3ec4120c91fcb62fba0ac07f4c8b256e2a4301162403
MD5 2ec9d1678707ed4b620425f53958b36b
BLAKE2b-256 4035690a50d53241323830f9b6349d706193f0fddc003c21047b99575545a0ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for webcodecs_py-2025.1.0.dev2-cp313-cp313-win_amd64.whl:

Publisher: wheel.yml on shiguredo/webcodecs-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 webcodecs_py-2025.1.0.dev2-cp313-cp313-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev2-cp313-cp313-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 117f6e4bfbddc37762408b88b9d7908142bd1472f2f86b72a32f49434281cd33
MD5 f84bfe0efb1d1b78c286a517ddde40f1
BLAKE2b-256 d878e498998cdbdd5a94984a54c6630b2bc0154a685b8cfc63eb2b2bc7f88638

See more details on using hashes here.

Provenance

The following attestation bundles were made for webcodecs_py-2025.1.0.dev2-cp313-cp313-manylinux_2_38_x86_64.whl:

Publisher: wheel.yml on shiguredo/webcodecs-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 webcodecs_py-2025.1.0.dev2-cp313-cp313-manylinux_2_38_aarch64.whl.

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev2-cp313-cp313-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 3151bab4305d80290b40f45702f5208db2f81cce325c057b8d863b6bf8a16ba5
MD5 71e8f598b5ee21e1e1bcebe9b7e89eef
BLAKE2b-256 7265f888944a6009e35c0d63b42ea5eec42c0f5ac67f1178ee2149d624f32624

See more details on using hashes here.

Provenance

The following attestation bundles were made for webcodecs_py-2025.1.0.dev2-cp313-cp313-manylinux_2_38_aarch64.whl:

Publisher: wheel.yml on shiguredo/webcodecs-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 webcodecs_py-2025.1.0.dev2-cp313-cp313-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev2-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 8ec3230b84174f0a8c65edf91a7cd60f01e1bea07a6c8f13e2648a5e06fd2fed
MD5 934d6890434bad65f2c42b07354e049a
BLAKE2b-256 30b8430a8ac83eb255cd436a357702583aace918772a62a7d150e3adec2448ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for webcodecs_py-2025.1.0.dev2-cp313-cp313-manylinux_2_35_x86_64.whl:

Publisher: wheel.yml on shiguredo/webcodecs-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 webcodecs_py-2025.1.0.dev2-cp313-cp313-manylinux_2_35_aarch64.whl.

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev2-cp313-cp313-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 cd977070b0bd27ff01d937cc3f50c5cee54257f3d4e920026bb0e4924f60ba58
MD5 b2890cb70a48b0709b989f620752fdd3
BLAKE2b-256 e9c14c93fa1c9ddc010d0d3c4cfbd22d75dceda77b8991ef2f58b9523d98ea26

See more details on using hashes here.

Provenance

The following attestation bundles were made for webcodecs_py-2025.1.0.dev2-cp313-cp313-manylinux_2_35_aarch64.whl:

Publisher: wheel.yml on shiguredo/webcodecs-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 webcodecs_py-2025.1.0.dev2-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev2-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 9cd1059ec8806cda7fae0d032c71721646904fd39eeccbfa2b15cb16886b8c3d
MD5 aefdc20b6e21d2f9fb6654c25f6506ba
BLAKE2b-256 4e873c93e48e88cecdb00a5e00d5b00d2c5e0a99e87353aadfc5c32eb08fb68b

See more details on using hashes here.

Provenance

The following attestation bundles were made for webcodecs_py-2025.1.0.dev2-cp313-cp313-macosx_15_0_arm64.whl:

Publisher: wheel.yml on shiguredo/webcodecs-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