webcodecs-py
Project description
webcodecs-py
[!CAUTION] webcodecs-py はまだ開発中であり、安定版ではありません。将来的に API が変更される可能性があります。 開発状況は webcodecs-py 対応状況 をご確認ください。
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
コーデック
- Opus
- FLAC
- AV1
- H.264 (AVC)
- H.265 (HEVC)
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file webcodecs_py-2025.1.0.dev0-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: webcodecs_py-2025.1.0.dev0-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 5.4 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27b56d194f554aab8d014f8b11f96824800cb4eea39cca846561da1335ad2bdc
|
|
| MD5 |
0a310a71b1d284a97f8b64a70b2252e8
|
|
| BLAKE2b-256 |
6674cc45e5f12a152008d5b640c5520f1c357a36214aa7b9307f5a95024240b4
|
Provenance
The following attestation bundles were made for webcodecs_py-2025.1.0.dev0-cp313-cp313-win_amd64.whl:
Publisher:
wheel.yml on shiguredo/webcodecs-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
webcodecs_py-2025.1.0.dev0-cp313-cp313-win_amd64.whl -
Subject digest:
27b56d194f554aab8d014f8b11f96824800cb4eea39cca846561da1335ad2bdc - Sigstore transparency entry: 717735918
- Sigstore integration time:
-
Permalink:
shiguredo/webcodecs-py@be217b2bd3e524bcfd00810559123d3fa0b978ca -
Branch / Tag:
refs/tags/2025.1.0.dev0 - Owner: https://github.com/shiguredo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheel.yml@be217b2bd3e524bcfd00810559123d3fa0b978ca -
Trigger Event:
push
-
Statement type:
File details
Details for the file webcodecs_py-2025.1.0.dev0-cp313-cp313-manylinux_2_38_x86_64.whl.
File metadata
- Download URL: webcodecs_py-2025.1.0.dev0-cp313-cp313-manylinux_2_38_x86_64.whl
- Upload date:
- Size: 4.7 MB
- Tags: CPython 3.13, manylinux: glibc 2.38+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8fff5be45f69647385209b7357909ad74d2b9a0ec57f3065bbb9b67131d253d4
|
|
| MD5 |
324ad8f3e7482caa29c25f460469da57
|
|
| BLAKE2b-256 |
60161625f072bb19cad38a4383d5d5ad6e4936542fcedf90b19b310d544d003a
|
Provenance
The following attestation bundles were made for webcodecs_py-2025.1.0.dev0-cp313-cp313-manylinux_2_38_x86_64.whl:
Publisher:
wheel.yml on shiguredo/webcodecs-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
webcodecs_py-2025.1.0.dev0-cp313-cp313-manylinux_2_38_x86_64.whl -
Subject digest:
8fff5be45f69647385209b7357909ad74d2b9a0ec57f3065bbb9b67131d253d4 - Sigstore transparency entry: 717735974
- Sigstore integration time:
-
Permalink:
shiguredo/webcodecs-py@be217b2bd3e524bcfd00810559123d3fa0b978ca -
Branch / Tag:
refs/tags/2025.1.0.dev0 - Owner: https://github.com/shiguredo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheel.yml@be217b2bd3e524bcfd00810559123d3fa0b978ca -
Trigger Event:
push
-
Statement type:
File details
Details for the file webcodecs_py-2025.1.0.dev0-cp313-cp313-manylinux_2_38_aarch64.whl.
File metadata
- Download URL: webcodecs_py-2025.1.0.dev0-cp313-cp313-manylinux_2_38_aarch64.whl
- Upload date:
- Size: 4.0 MB
- Tags: CPython 3.13, manylinux: glibc 2.38+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
763946b484b12a1d94074bc65c6b1064cb5d3bc626591cad00a17788b0eb10db
|
|
| MD5 |
49cff28f4722104474f007a62aabc8b9
|
|
| BLAKE2b-256 |
eaea83739d41b42172785849036219229121f58bfb1f7d4dd1ea542501cf72d7
|
Provenance
The following attestation bundles were made for webcodecs_py-2025.1.0.dev0-cp313-cp313-manylinux_2_38_aarch64.whl:
Publisher:
wheel.yml on shiguredo/webcodecs-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
webcodecs_py-2025.1.0.dev0-cp313-cp313-manylinux_2_38_aarch64.whl -
Subject digest:
763946b484b12a1d94074bc65c6b1064cb5d3bc626591cad00a17788b0eb10db - Sigstore transparency entry: 717735957
- Sigstore integration time:
-
Permalink:
shiguredo/webcodecs-py@be217b2bd3e524bcfd00810559123d3fa0b978ca -
Branch / Tag:
refs/tags/2025.1.0.dev0 - Owner: https://github.com/shiguredo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheel.yml@be217b2bd3e524bcfd00810559123d3fa0b978ca -
Trigger Event:
push
-
Statement type:
File details
Details for the file webcodecs_py-2025.1.0.dev0-cp313-cp313-manylinux_2_35_x86_64.whl.
File metadata
- Download URL: webcodecs_py-2025.1.0.dev0-cp313-cp313-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 4.5 MB
- Tags: CPython 3.13, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c57131326a5f56a55dae752c3f4fb39577a50fd6944b540e3e51ebecac43999
|
|
| MD5 |
9a19b437f50d1dfd4cc2ec58e3c28faa
|
|
| BLAKE2b-256 |
c6a2617cbbcec06c86ede6693f356ce189d51dac5cb973954bd0610738b80668
|
Provenance
The following attestation bundles were made for webcodecs_py-2025.1.0.dev0-cp313-cp313-manylinux_2_35_x86_64.whl:
Publisher:
wheel.yml on shiguredo/webcodecs-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
webcodecs_py-2025.1.0.dev0-cp313-cp313-manylinux_2_35_x86_64.whl -
Subject digest:
0c57131326a5f56a55dae752c3f4fb39577a50fd6944b540e3e51ebecac43999 - Sigstore transparency entry: 717735964
- Sigstore integration time:
-
Permalink:
shiguredo/webcodecs-py@be217b2bd3e524bcfd00810559123d3fa0b978ca -
Branch / Tag:
refs/tags/2025.1.0.dev0 - Owner: https://github.com/shiguredo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheel.yml@be217b2bd3e524bcfd00810559123d3fa0b978ca -
Trigger Event:
push
-
Statement type:
File details
Details for the file webcodecs_py-2025.1.0.dev0-cp313-cp313-manylinux_2_35_aarch64.whl.
File metadata
- Download URL: webcodecs_py-2025.1.0.dev0-cp313-cp313-manylinux_2_35_aarch64.whl
- Upload date:
- Size: 3.9 MB
- Tags: CPython 3.13, manylinux: glibc 2.35+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
319923589d861643678e7ed3c46fd56e858223e01a9eca3d669d14460599776c
|
|
| MD5 |
3c20e6b0acafcf68da915a3d150823c5
|
|
| BLAKE2b-256 |
50a0786151bd6bcd1b5fdb9527fe7d17ba9efd090ed7e176c87fdaa2b83ed627
|
Provenance
The following attestation bundles were made for webcodecs_py-2025.1.0.dev0-cp313-cp313-manylinux_2_35_aarch64.whl:
Publisher:
wheel.yml on shiguredo/webcodecs-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
webcodecs_py-2025.1.0.dev0-cp313-cp313-manylinux_2_35_aarch64.whl -
Subject digest:
319923589d861643678e7ed3c46fd56e858223e01a9eca3d669d14460599776c - Sigstore transparency entry: 717735961
- Sigstore integration time:
-
Permalink:
shiguredo/webcodecs-py@be217b2bd3e524bcfd00810559123d3fa0b978ca -
Branch / Tag:
refs/tags/2025.1.0.dev0 - Owner: https://github.com/shiguredo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheel.yml@be217b2bd3e524bcfd00810559123d3fa0b978ca -
Trigger Event:
push
-
Statement type:
File details
Details for the file webcodecs_py-2025.1.0.dev0-cp313-cp313-macosx_15_0_arm64.whl.
File metadata
- Download URL: webcodecs_py-2025.1.0.dev0-cp313-cp313-macosx_15_0_arm64.whl
- Upload date:
- Size: 3.3 MB
- Tags: CPython 3.13, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35b7203d9ec949677f774a606bbf6b9dd75d0fdcb6d6a6a4b0befeb260273d48
|
|
| MD5 |
fbac6658c959c4483810fc4c82d5e651
|
|
| BLAKE2b-256 |
c27e0e50a2cd005cca4032b4dc1db9b6466aecc703009c0f139fd48ecb14bcb3
|
Provenance
The following attestation bundles were made for webcodecs_py-2025.1.0.dev0-cp313-cp313-macosx_15_0_arm64.whl:
Publisher:
wheel.yml on shiguredo/webcodecs-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
webcodecs_py-2025.1.0.dev0-cp313-cp313-macosx_15_0_arm64.whl -
Subject digest:
35b7203d9ec949677f774a606bbf6b9dd75d0fdcb6d6a6a4b0befeb260273d48 - Sigstore transparency entry: 717735882
- Sigstore integration time:
-
Permalink:
shiguredo/webcodecs-py@be217b2bd3e524bcfd00810559123d3fa0b978ca -
Branch / Tag:
refs/tags/2025.1.0.dev0 - Owner: https://github.com/shiguredo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheel.yml@be217b2bd3e524bcfd00810559123d3fa0b978ca -
Trigger Event:
push
-
Statement type: