libvpx-rs

July 31, 2026 · View on GitHub

crates.io docs.rs License GitHub Actions Discord

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 before use.

時雨堂のオープンソースソフトウェアについて

利用前に https://github.com/shiguredo/oss をお読みください。

概要

libvpx を利用した VP8 / VP9 エンコーダーおよびデコーダーの Rust バインディングです。

特徴

  • VP8 エンコーダー / デコーダー
  • VP9 エンコーダー / デコーダー
  • VP9 High Bitdepth (10-bit / Profile 2) デコード対応
  • 複数の画像フォーマット対応 (I420, YV12, NV12, I422, I444, I440, I42016, I42216, I44416, I44016)
  • エンコーダーの詳細設定 (レート制御、品質、速度)
  • VP9 固有設定 (適応的量子化、タイル分割、行マルチスレッド)
  • VP8 固有設定 (デノイザー、ARNR フィルタ)
  • シンボル書き換えによる他ライブラリとの衝突回避 (shiguredo_vpx_ プレフィックス付与)
  • prebuilt バイナリによる高速ビルド (デフォルト)
  • ソースからのビルドも可能 (--features source-build)

動作要件

  • Ubuntu 26.04 x86_64
  • Ubuntu 26.04 arm64
  • Ubuntu 24.04 x86_64
  • Ubuntu 24.04 arm64
  • Ubuntu 22.04 x86_64
  • Ubuntu 22.04 arm64
  • macOS 26 arm64
  • macOS 15 arm64
  • Windows Server 2025 x86_64
  • Windows 11 x86_64

ソースビルド時の追加要件

  • Git
  • C コンパイラ (build-essential 等)
  • YASM または NASM (libvpx のアセンブリ最適化に必要)
  • Windows の場合は MSYS2 + MINGW64 (gcc / make / nasm / clang) が必要
# Ubuntu
sudo apt-get install -y build-essential nasm

# macOS
brew install nasm

# Windows (MSYS2 MINGW64)
pacman -S git make nasm mingw-w64-x86_64-gcc mingw-w64-x86_64-binutils mingw-w64-x86_64-clang

ビルド

デフォルトでは GitHub Releases から prebuilt バイナリをダウンロードしてビルドします。

cargo build

ソースからビルド

libvpx をソースからビルドする場合は source-build feature を有効にしてください。

cargo build --features source-build

docs.rs 向けビルド

libvpx がない環境では、docs.rs 向けのドキュメント生成のみ可能です。

DOCS_RS=1 cargo doc --no-deps

使い方

エンコード

入力は ImageData 列挙型で画像フォーマットと各プレーンのデータを渡します。

use shiguredo_libvpx::{
    CodecConfig, EncodeOptions, Encoder, EncoderConfig,
    EncodingDeadline, ImageData, ImageFormat, RateControlMode, Vp9Config,
};

// 必須パラメータを指定して設定を生成
let mut config = EncoderConfig::new(
    1920,                                    // width
    1080,                                    // height
    ImageFormat::I420,                       // image_format
    CodecConfig::Vp9(Vp9Config::default()),  // codec
);

// 必要に応じてオプションパラメータを変更
config.deadline = EncodingDeadline::Realtime;
config.rate_control = RateControlMode::Cbr;
config.cpu_used = Some(4);
config.threads = std::num::NonZeroUsize::new(4);

// エンコーダーを作成
let mut encoder = Encoder::new(config)?;

// I420 形式の YUV データをエンコード
let image = ImageData::I420 { y: &y_data, u: &u_data, v: &v_data };
encoder.encode(&image, &EncodeOptions { force_keyframe: false })?;

// キーフレームを強制する場合
encoder.encode(&image, &EncodeOptions {
    force_keyframe: true,
})?;

// エンコード済みフレームを取得
while let Some(frame) = encoder.next_frame() {
    let data = frame.data();
    let is_key = frame.is_keyframe();
    println!("encoded: {} bytes, keyframe: {}", data.len(), is_key);
}

// 残りのフレームをフラッシュ
encoder.finish()?;
while let Some(frame) = encoder.next_frame() {
    // ...
}

VP8 の場合は CodecConfig::Vp8(Vp8Config::default()) を指定してください。

デコード

use shiguredo_libvpx::{Decoder, DecoderCodec, DecoderConfig};

// VP9 デコーダーを作成
let mut decoder = Decoder::new(DecoderConfig::new(DecoderCodec::Vp9))?;

// 圧縮データをデコード
decoder.decode(&compressed_data)?;

// デコード済みフレームを取得
while let Some(frame) = decoder.next_frame() {
    let y = frame.y_plane();
    let u = frame.u_plane();
    let v = frame.v_plane();
    let y_stride = frame.y_stride();
    let u_stride = frame.u_stride();
    let v_stride = frame.v_stride();
    let is_high_depth = frame.is_high_depth();
    println!("{}x{} high_depth={}", frame.width(), frame.height(), is_high_depth);
}

// 残りのフレームをフラッシュ
decoder.finish()?;
while let Some(frame) = decoder.next_frame() {
    // ...
}

VP8 の場合は codec: DecoderCodec::Vp8 を指定してください。

設定

EncoderConfig

フィールド説明
widthusize映像の幅
heightusize映像の高さ
image_formatImageFormat入力画像フォーマット
fps_numeratorusizeフレームレートの分子
fps_denominatorusizeフレームレートの分母
target_bitrateusizeターゲットビットレート (bps)
min_quantizerusize最小量子化パラメーター
max_quantizerusize最大量子化パラメーター
cq_levelusizeCQ レベル
cpu_usedOption<usize>エンコード速度 (VP8: 0-16, VP9: 0-9)
deadlineEncodingDeadlineエンコード期限
rate_controlRateControlModeレート制御モード
lag_in_framesOption<NonZeroUsize>先読みフレーム数
threadsOption<NonZeroUsize>スレッド数
error_resilientboolエラー耐性モード
keyframe_intervalOption<NonZeroUsize>キーフレーム間隔
frame_drop_thresholdOption<usize>フレームドロップ閾値 (0-100)
codecCodecConfigコーデック固有設定

EncodingDeadline

バリアント説明
Best最高品質 (最も時間がかかる)
Good良い品質 (品質と速度のバランス)
Realtimeリアルタイム (最も高速)

RateControlMode

バリアント説明
VbrVariable Bitrate (可変ビットレート)
CbrConstant Bitrate (固定ビットレート)
CqConstant Quality (固定品質)

ImageFormat

バリアント説明
I420YUV 4:2:0 planar (3 プレーン: Y, U, V)
Yv12YUV 4:2:0 planar (3 プレーン: Y, V, U)
Nv12YUV 4:2:0 semi-planar (2 プレーン: Y, UV interleaved)
I422YUV 4:2:2 planar (3 プレーン: Y, U, V)
I444YUV 4:4:4 planar (3 プレーン: Y, U, V)
I440YUV 4:4:0 planar (3 プレーン: Y, U, V)
I42016YUV 4:2:0 planar 16-bit (3 プレーン: Y, U, V)
I42216YUV 4:2:2 planar 16-bit (3 プレーン: Y, U, V)
I44416YUV 4:4:4 planar 16-bit (3 プレーン: Y, U, V)
I44016YUV 4:4:0 planar 16-bit (3 プレーン: Y, U, V)

ImageData

バリアント説明
I420 { y, u, v }I420 (3 プレーン: Y, U, V)
Yv12 { y, u, v }YV12 (3 プレーン: Y, V, U)
Nv12 { y, uv }NV12 (2 プレーン: Y, UV interleaved)
I422 { y, u, v }I422 (3 プレーン: Y, U, V)
I444 { y, u, v }I444 (3 プレーン: Y, U, V)
I440 { y, u, v }I440 (3 プレーン: Y, U, V)
I42016 { y, u, v }I42016 (3 プレーン: Y, U, V / 16-bit)
I42216 { y, u, v }I42216 (3 プレーン: Y, U, V / 16-bit)
I44416 { y, u, v }I44416 (3 プレーン: Y, U, V / 16-bit)
I44016 { y, u, v }I44016 (3 プレーン: Y, U, V / 16-bit)

CodecConfig

バリアント説明
Vp8(Vp8Config)VP8 コーデック設定
Vp9(Vp9Config)VP9 コーデック設定

EncodeOptions

フィールドデフォルト説明
force_keyframeboolfalseキーフレームを強制する

DecoderConfig

フィールド説明
codecDecoderCodecデコードするコーデック

DecoderCodec

バリアント説明
Vp8VP8
Vp9VP9

Vp9Profile

バリアント説明
Profile08-bit 4:2:0 (デフォルト)
Profile210/12-bit 4:2:0

Vp9Config

フィールド説明
profileVp9Profileプロファイル
aq_modeOption<i32>適応的量子化モード (0-3)
noise_sensitivityOption<i32>デノイザー設定 (0-3)
tile_columnsOption<i32>タイル列数 (並列処理用)
tile_rowsOption<i32>タイル行数 (並列処理用)
row_mtbool行マルチスレッド
frame_parallel_decodingboolフレーム並列デコード
tune_contentOption<ContentType>コンテンツタイプ最適化

Vp8Config

フィールド説明
noise_sensitivityOption<i32>デノイザー設定 (0-3)
static_thresholdOption<i32>静的閾値
token_partitionsOption<i32>トークンパーティション数
max_intra_bitrate_pctOption<i32>最大イントラビットレート率
arnr_configOption<ArnrConfig>ARNR フィルタ設定

サポートコーデック

エンコード

コーデックCodecConfig
VP8CodecConfig::Vp8(Vp8Config { .. })
VP9CodecConfig::Vp9(Vp9Config { .. })

デコード

コーデックDecoderCodec
VP8DecoderCodec::Vp8
VP9DecoderCodec::Vp9

環境変数

変数説明
LIBVPX_TARGETprebuilt バイナリのプラットフォーム名を明示的に指定する

libvpx ライセンス

https://chromium.googlesource.com/webm/libvpx/+/refs/heads/main/LICENSE

Copyright (c) 2010, The WebM Project authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

  * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.

  * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.

  * Neither the name of Google, nor the WebM Project, nor the names
    of its contributors may be used to endorse or promote products
    derived from this software without specific prior written
    permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

ライセンス

Apache License 2.0

Copyright 2026-2026, 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.