rtmp-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 をお読みください。
概要
Rust で実装された依存 0 かつ Sans I/O な RTMP ライブラリです。
特徴
- Sans I/O
- https://sans-io.readthedocs.io/index.html
- I/O 操作を含まない純粋なプロトコル処理
- 依存ライブラリ 0
- 標準ライブラリのみで実装
使い方
クライアント (配信)
use ;
// 配信用クライアント接続を作成
let mut connection = new;
// 送信バッファを取得してソケットに書き込む
let send_data = connection.send_buf;
// send_data を送信...
connection.advance_send_buf;
// 受信データを feed
// connection.feed_recv_buf(&received_data)?;
// イベントを処理
// while let Some(event) = connection.next_event() { ... }
// 映像/音声フレームを送信
// connection.send_video(video_frame)?;
// connection.send_audio(audio_frame)?;
クライアント (再生)
use RtmpPlayClientConnection;
// 再生用クライアント接続を作成
let mut connection = new;
// 送信バッファを取得してソケットに書き込む
let send_data = connection.send_buf;
// send_data を送信...
connection.advance_send_buf;
// 受信データを feed
// connection.feed_recv_buf(&received_data)?;
// イベントを処理 (映像/音声フレーム受信など)
// while let Some(event) = connection.next_event() { ... }
サーバー
use ;
// サーバー接続を作成
let mut connection = new;
// 受信データを feed
// connection.feed_recv_buf(&received_data)?;
// イベントを処理
while let Some = connection.next_event
// 送信バッファを取得してソケットに書き込む
let send_data = connection.send_buf;
// send_data を送信...
connection.advance_send_buf;
公開 API
接続
| 構造体 | 説明 |
|---|---|
RtmpPublishClientConnection |
配信用クライアント接続 |
RtmpPlayClientConnection |
再生用クライアント接続 |
RtmpServerConnection |
サーバー接続 |
イベント
| 列挙型 | 説明 |
|---|---|
RtmpConnectionEvent |
接続イベント (配信/再生要求、フレーム受信など) |
RtmpConnectionState |
接続状態 (Handshaking, Connecting, Publishing など) |
メディア
| 型 | 説明 |
|---|---|
VideoFrame |
映像フレーム |
AudioFrame |
音声フレーム |
MediaFrame |
メディアフレーム (Audio/Video の enum) |
VideoCodec |
映像コーデック |
VideoFrameType |
映像フレームタイプ (Keyframe, Inter など) |
AudioFormat |
音声フォーマット |
AudioSampleRate |
音声サンプルレート |
AvcPacketType |
AVC パケットタイプ |
タイムスタンプ
| 型 | 説明 |
|---|---|
RtmpTimestamp |
タイムスタンプ (ミリ秒単位、符号なし 32 ビット) |
RtmpTimestampDelta |
タイムスタンプ差分 (ミリ秒単位、符号付き 32 ビット) |
エラー
| 型 | 説明 |
|---|---|
Error |
エラー型 (kind, reason, location, backtrace を含む) |
ErrorKind |
エラー種別 (InvalidInput, InvalidData, InvalidState, Unsupported) |
サンプル
サンプルは Tokio と Rustls を利用しています。引数のライブラリには noargs を利用しています。
publish
MP4 ファイルを RTMP/RTMPS サーバーに配信するクライアントの例です。
# RTMP
# RTMPS (--tls フラグ)
# RTMPS (URL スキーム)
オプション:
-H, --host <HOST>: サーバーホスト (デフォルト: 127.0.0.1)-p, --port <PORT>: サーバーポート (デフォルト: 1935、TLS 時: 443)-a, --app <APP>: アプリケーション名 (デフォルト: live)-s, --stream <STREAM>: ストリーム名 (デフォルト: stream)-u, --url <URL>: RTMP/RTMPS URL (例: rtmps://example.com/live/stream)--tls: TLS (RTMPS) 有効化--verbose: 詳細出力
server
RTMP/RTMPS サーバーの例です。
# RTMP
# RTMPS
オプション:
-H, --host <HOST>: リッスンホスト (デフォルト: 0.0.0.0)-p, --port <PORT>: リッスンポート (デフォルト: 1935、TLS 時: 443)--tls: TLS (RTMPS) 有効化--cert <PATH>: 証明書ファイル (PEM 形式)--key <PATH>: 秘密鍵ファイル (PEM 形式)--verbose: 詳細出力
ライセンス
Apache License 2.0
Copyright 2026-2026, Takeru Ohta (Original Author)
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.