Skip to main content

webcodecs-py

Project description

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

開発状況は webcodecs-py 対応状況 をご確認ください。

実装しない機能

  • ImageDecoder: 画像デコード機能は実装対象外

    • Pillow や OpenCV を使用してください
  • CanvasImageSource: VideoFrame の CanvasImageSource コンストラクタはブラウザ固有機能のため実装対象外

サンプルコード

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.2-cp314-cp314-win_amd64.whl (5.5 MB view details)

Uploaded CPython 3.14Windows x86-64

webcodecs_py-2025.1.2-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.2-cp314-cp314-manylinux_2_38_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.38+ ARM64

webcodecs_py-2025.1.2-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.2-cp314-cp314-manylinux_2_35_aarch64.whl (3.9 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.35+ ARM64

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

Uploaded CPython 3.14macOS 15.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

webcodecs_py-2025.1.2-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.2-cp313-cp313-manylinux_2_38_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.38+ ARM64

webcodecs_py-2025.1.2-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.2-cp313-cp313-manylinux_2_35_aarch64.whl (3.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.35+ ARM64

webcodecs_py-2025.1.2-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.2-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for webcodecs_py-2025.1.2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 8fa1a2a7df26cd8771c79142e0f67c73b3252d19c9dcf69f7101d29efec49a9f
MD5 06e7c8152bdb65d8c29e00fa6cc0a63d
BLAKE2b-256 ee70bbbf6199a4e0eebc7ee4b43b7bc226b2431e1df41a716937c8447891717a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webcodecs_py-2025.1.2-cp314-cp314-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 9ae901ae5e1f4469dd5f6c87bde4962e8458cc050be3a5d0fb54887d079d42cf
MD5 4df78720d4da1c80d17aaad415f65997
BLAKE2b-256 e660cce5decb54420d845068652673b27a282129fbb5500f98080c8ffc0adefb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webcodecs_py-2025.1.2-cp314-cp314-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 62e1b6b7a79c9a7a392783acabf21e16683193f589c0adeca72b85d7d4b3e0d3
MD5 516095675dc03d6a84ec38742a1d4fbb
BLAKE2b-256 66c652f6b523517203395c4c1ee2397208df26685f6c28fa91fba3300a1f0794

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webcodecs_py-2025.1.2-cp314-cp314-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 83e57dedc08bf671a9028cb2837a4943df0d34ce71d62073aba33de4f675acc0
MD5 26c9d30460d21c95e1f879c7b169892e
BLAKE2b-256 da60cc213d4d37bc6bf6f2f3200861c014209869b3b6d06623ed22aff7aaa81e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webcodecs_py-2025.1.2-cp314-cp314-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 38dc85d9cd99700f058a1c57b70e896a88eaf1bdc0baf07fffd83dd2753c735a
MD5 37c77de53432fddddda9dc19e9fb909c
BLAKE2b-256 fc91049b5659016b333f932b98e4d21ea9181e5611eacfe7b2440969724d2aac

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webcodecs_py-2025.1.2-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 3861d7ab23c47b98dea56ecd16ae7fb9e1d702ad8433b0c283f1d0d54348dad5
MD5 35b6fac7f28b370d44d6ce9d41988404
BLAKE2b-256 11027934a1bf53684cb34a1f3edec10cdf0c73591118a71a9c4840cab6b55798

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webcodecs_py-2025.1.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 9fff7455b6981b1019a041c0e98943a9aad05d0f02036322a7c8a82e153be5b2
MD5 68494321bdd5f93bc8720335bf02b8c3
BLAKE2b-256 7db66296600f8c8fe15d4e4df5def8df81f0281c217d827043a945ab52315272

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webcodecs_py-2025.1.2-cp313-cp313-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 7dedd209e295ea83cfecc120df0ee0f0cc8ba4cf7dacf703ec57808a71355253
MD5 cc4cc1510c2da6ea08e09f8d088a50ed
BLAKE2b-256 ca61fae14ec945b63442cf2bac83156ba983c2279af61294c8ea23ecd9acae9c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webcodecs_py-2025.1.2-cp313-cp313-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 8e87aea43d103da28b9e3b99269774fc9d46b0cdcded411103c77eba3f60532b
MD5 7521de3e11ffa0501a50bc1c3527af03
BLAKE2b-256 09ffab932442c4b8ead8a842475fc9fc00acc34840a62db128cdbc307eb3265d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webcodecs_py-2025.1.2-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 c1090340f4ea7cc3b351fa4e8e930f847670fadc38ae60764795a42b0890db9a
MD5 36295dc74cbb9586d1671f23d1c78c38
BLAKE2b-256 c0bc1068b9435421313edd94c4126051cbfc41c50d5677f7f2d60b60a2b6ac3a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webcodecs_py-2025.1.2-cp313-cp313-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 9f19009f80aaf83f44801e803b21f80dcfc1d07fbf6e8e04133fe482a2274230
MD5 0995ca9e88f285d621d11f54b7b0d621
BLAKE2b-256 2b85f83e403a2c22ac85b003e576e91b9438141e8e94a18c506039720821facf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webcodecs_py-2025.1.2-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 7350fa2babeb29b47b19929aa44a53a8174e9880444b5413f01b401457522697
MD5 38cb6c1a0588af4aac09362b030a831b
BLAKE2b-256 4e1c771d874dfc333b0301746689d11871167c85a52e47c0d5d43e45df29e970

See more details on using hashes here.

Provenance

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