amf-rs
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 をお読みください。
概要
AMD AMF (Advanced Media Framework) を利用したハードウェアビデオエンコーダーおよびデコーダーの Rust バインディングです。
AMF ランタイムライブラリ (libamfrt64.so.1) は AMD GPU ドライバーに同梱されており、dlopen で動的にロードするため、ビルド時のリンクは不要です。
特徴
- AMF によるハードウェアエンコード (H.264 / H.265 / AV1)
- AMF によるハードウェアデコード (H.264 / H.265 / AV1)
- AMF ランタイムライブラリの実行時動的ロード (ビルド時のリンク不要)
- Vulkan バックエンドによる GPU 処理
- エンコード入力フォーマット選択 (NV12 / YV12 / I420 / BGRA / ARGB / RGBA / YUY2 / UYVY / P010 / P012 / P016 / Y210 / AYUV / Y410 / Y416)
- デコード出力は NV12 フォーマット
- フレーム単位のエンコードオプション (IDR フレーム強制)
- CQP / CBR / VBR / LCVBR / QVBR / HQVBR / HQCBR レート制御モード
- ビルド時に GitHub から AMF ヘッダーを自動取得
動作要件
- Linux (x86_64)
- AMD GPU (RDNA 以降推奨)
- AMD GPU ドライバー (AMF ランタイムライブラリを含む)
- Vulkan ドライバー
- ビルド時: git
ビルド
ビルド時に GitHub から AMF ヘッダーを自動取得します。
docs.rs 向けビルド
AMF ランタイムがない環境では、docs.rs 向けのドキュメント生成のみ可能です。
DOCS_RS=1
使い方
エンコード
use ;
let mut config = new;
config.target_kbps = Some;
let mut encoder = new?;
// フレームデータをエンコード
let options = EncodeOptions ;
encoder.encode?;
// IDR フレームを強制してエンコード
encoder.encode?;
// エンコード済みフレームを取得
while let Some = encoder.next_frame
// 残りのフレームをすべて取得する
encoder.finish?;
while let Some = encoder.next_frame
デコード
use ;
let config = DecoderConfig ;
let mut decoder = new?;
// ビットストリームデータをデコード
decoder.decode?;
// デコード済みフレームを取得 (NV12 フォーマット)
while let Some = decoder.next_frame
// 残りのフレームをすべて取得する
decoder.finish?;
while let Some = decoder.next_frame
コーデック対応状況の確認
use supported_codecs;
let codecs = supported_codecs;
for info in &codecs
AMF ランタイムがロードできない環境では、全コーデックが非対応として返されます。
サポートコーデック
エンコード
| コーデック | CodecConfig |
|---|---|
| H.264 | CodecConfig::H264(H264EncoderConfig) |
| H.265 | CodecConfig::Hevc(HevcEncoderConfig) |
| AV1 | CodecConfig::Av1(Av1EncoderConfig) |
デコード
| コーデック | DecoderCodec |
|---|---|
| H.264 | DecoderCodec::H264 |
| H.265 | DecoderCodec::Hevc |
| AV1 | DecoderCodec::Av1 |
サポートフォーマット
エンコード入力フォーマット (FrameFormat)
| フォーマット | FrameFormat |
説明 |
|---|---|---|
| NV12 | FrameFormat::Nv12 |
Semi-Planar YUV 4:2:0 8bit |
| YV12 | FrameFormat::Yv12 |
Planar YUV 4:2:0 8bit (Y+V+U) |
| I420 | FrameFormat::I420 |
Planar YUV 4:2:0 8bit (Y+U+V) |
| BGRA | FrameFormat::Bgra |
Packed BGRA 8bit |
| ARGB | FrameFormat::Argb |
Packed ARGB 8bit |
| RGBA | FrameFormat::Rgba |
Packed RGBA 8bit |
| YUY2 | FrameFormat::Yuy2 |
Packed YUV 4:2:2 8bit |
| UYVY | FrameFormat::Uyvy |
Packed YUV 4:2:2 8bit |
| P010 | FrameFormat::P010 |
Semi-Planar YUV 4:2:0 10bit |
| P012 | FrameFormat::P012 |
Semi-Planar YUV 4:2:0 12bit (16bit 格納) |
| P016 | FrameFormat::P016 |
Semi-Planar YUV 4:2:0 16bit |
| Y210 | FrameFormat::Y210 |
Packed YUV 4:2:2 10bit (16bit 格納) |
| AYUV | FrameFormat::Ayuv |
Packed YUV 4:4:4 8bit |
| Y410 | FrameFormat::Y410 |
Packed YUV 4:4:4 10bit |
| Y416 | FrameFormat::Y416 |
Packed YUV 4:4:4 16bit |
デコード出力フォーマット
| フォーマット | 説明 |
|---|---|
| NV12 | Semi-Planar YUV 4:2:0 8bit |
サポートプロファイル
H.264 (H264Profile)
| プロファイル | H264Profile |
|---|---|
| Baseline | H264Profile::Baseline |
| Main | H264Profile::Main |
| High | H264Profile::High |
| Constrained Baseline | H264Profile::ConstrainedBaseline |
| Constrained High | H264Profile::ConstrainedHigh |
H.265 (HevcProfile)
| プロファイル | HevcProfile |
|---|---|
| Main | HevcProfile::Main |
| Main 10 | HevcProfile::Main10 |
AV1 (Av1Profile)
| プロファイル | Av1Profile |
|---|---|
| Main | Av1Profile::Main |
レート制御モード (RateControlMode)
| モード | RateControlMode |
説明 |
|---|---|---|
| CQP | RateControlMode::Cqp |
固定 QP |
| CBR | RateControlMode::Cbr |
固定ビットレート |
| VBR | RateControlMode::Vbr |
ピーク制約付き可変ビットレート |
| LCVBR | RateControlMode::LatencyConstrainedVbr |
レイテンシ制約付き可変ビットレート |
| QVBR | RateControlMode::QualityVbr |
品質 VBR |
| HQVBR | RateControlMode::HighQualityVbr |
高品質 VBR |
| HQCBR | RateControlMode::HighQualityCbr |
高品質 CBR |
ライセンス
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.