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、AAC、AV1、H.264、H.265 コーデックをサポート
    • AAC は macOS の AudioToolbox を利用
    • 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.dev3-cp314-cp314-win_amd64.whl (5.5 MB view details)

Uploaded CPython 3.14Windows x86-64

webcodecs_py-2025.1.0.dev3-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.dev3-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.dev3-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.dev3-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.dev3-cp314-cp314-macosx_15_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

webcodecs_py-2025.1.0.dev3-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.dev3-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.dev3-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.dev3-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.dev3-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.dev3-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev3-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 144faf2f67f802869bce2c9b3fab611ad4254ad245e0da53712c53090ed1e68b
MD5 af5311b986dce021d319d12c965e0173
BLAKE2b-256 3a62a344d0e3bd2081afe4655cf4f7c1c840ab6de8ded7a63c8de3e7a2518ae0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev3-cp314-cp314-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 9267818de98dd9a25bcda7a12b8c922a0ca21ac92685ccd439170f309a948e4b
MD5 96598fc6106ab08a84ad489d145d9330
BLAKE2b-256 300a415148fedc1c6f2e00d71591bc2c6435fdfb13cefac6608ad8cb8544343b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev3-cp314-cp314-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 0024c6e771da112cafa926da4762bf82b3b246f56827249dc94ae3e0152aa97d
MD5 46a3df3d9d94e777643e5c1928aefd1d
BLAKE2b-256 b8c3f41d47def5e9ce7e582c6fdb6c150bf62209828d9b4ab4ce2311fe318a01

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev3-cp314-cp314-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 c244f9cb8a9f62627923ee209a21a00e37b3d91cfa4b77d54ab4205068bfa9d4
MD5 380a31cb59a3368a6a3b58d78f97dfb1
BLAKE2b-256 07dadf7e41b2e030b3cef084c9a26837b27622c6eeb3b3186e9421fdbcd95e2e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev3-cp314-cp314-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 867afe51311db23f59f80fd809b946c8fdd9633622f308729afedbede4e114a9
MD5 41ebca96b38c465c3a893d87afca1cdf
BLAKE2b-256 d55a30908d04387975c56d608780537fc66024578be22a388b44e8862bd548bc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev3-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 1d0a87e589d5f02b2994df05c35614656bb6f8bdd12731a1e1da22e130ffe248
MD5 9de3418b15bb1b0de2f3ee7d6bf6cfee
BLAKE2b-256 5a5fc6cabb6d00ba264d7d5aa1cf5de4d82b3470b86139c2c61f97ea57ef6446

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ed85a66a39cd51c96e2fde02ffe05b5caf616d744a4f9cf19741f0ef14526d11
MD5 b02a1ebf75ae6cd02160dbbdbfb53543
BLAKE2b-256 1e6f04b32b49ae1e067989988d3656a9dd41343e9898c607b8a230ce9dbb1706

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev3-cp313-cp313-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 77a3d064b2154023f29300f555ea53d84241929b4220418ca68b769507577a54
MD5 0ea152d26dc421a60e8a34bc2bb63e74
BLAKE2b-256 b85aa9df5ab14f8fa969a8fbef92e1d354aa20a048cc560e164e340156c54a40

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev3-cp313-cp313-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 f57501c176b39bd13fea1469e050b1a475a0bc3189a6391f2609e21b1677f429
MD5 5aa9a00f0eb894bbee7e76b0d75136de
BLAKE2b-256 7c7300986113e7af538b8bfec54488eb15dd5f543fe459445e7a246be25a237e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev3-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 bb6c284a9f248b110ab2c71941a27f56cf69fea7d65b468b79cc4adb6ea031de
MD5 00beab78867cdf4c601288faa5812479
BLAKE2b-256 fcbdbf44cf767261120708d3ab6e9b19bef4704ddf18be26476e7144c031384d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev3-cp313-cp313-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 17f3f2b748d545965a87761824cf8c54323a031471276527c67fe6bf5ed97fe5
MD5 be746cf64bf9de840cc5cbc434b6f76a
BLAKE2b-256 e112136d6303a4d3fc54f27e71f51ff0fb8ef4c6bcc7eaab934ee19f0f3446d3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webcodecs_py-2025.1.0.dev3-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 85138b223d79889d8e154df25e57fec7604b413ef1a98fe6ba702e98f4fe5431
MD5 b602a9be8d9f04036f813ea067faf213
BLAKE2b-256 c3cf929e698bdd8eeaf1f191c99e6417ab1aa9b5e8255331bc94c7632cfdc3b5

See more details on using hashes here.

Provenance

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