| Crates.io | shiguredo_rtmp |
| lib.rs | shiguredo_rtmp |
| version | 2026.1.0-canary.2 |
| created_at | 2026-01-21 09:59:45.629782+00 |
| updated_at | 2026-01-26 01:34:15.488849+00 |
| description | RTMP library |
| homepage | https://github.com/shiguredo/rtmp-rs |
| repository | https://github.com/shiguredo/rtmp-rs |
| max_upload_size | |
| id | 2058776 |
| size | 355,039 |
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 ライブラリです。
use shiguredo_rtmp::{RtmpPublishClientConnection, VideoFrame, AudioFrame};
// 配信用クライアント接続を作成
let mut connection = RtmpPublishClientConnection::new(
"rtmp://localhost:1935/live",
"stream"
);
// 送信バッファを取得してソケットに書き込む
let send_data = connection.send_buf();
// send_data を送信...
connection.advance_send_buf(send_data.len());
// 受信データを 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 shiguredo_rtmp::RtmpPlayClientConnection;
// 再生用クライアント接続を作成
let mut connection = RtmpPlayClientConnection::new(
"rtmp://localhost:1935/live",
"stream"
);
// 送信バッファを取得してソケットに書き込む
let send_data = connection.send_buf();
// send_data を送信...
connection.advance_send_buf(send_data.len());
// 受信データを feed
// connection.feed_recv_buf(&received_data)?;
// イベントを処理 (映像/音声フレーム受信など)
// while let Some(event) = connection.next_event() { ... }
use shiguredo_rtmp::{RtmpServerConnection, RtmpConnectionEvent};
// サーバー接続を作成
let mut connection = RtmpServerConnection::new();
// 受信データを feed
// connection.feed_recv_buf(&received_data)?;
// イベントを処理
while let Some(event) = connection.next_event() {
match event {
RtmpConnectionEvent::PublishRequested { app, stream_name, .. } => {
// 配信要求を許可/拒否
// connection.accept()?;
// connection.reject("reason")?;
}
RtmpConnectionEvent::PlayRequested { app, stream_name, .. } => {
// 再生要求を許可/拒否
// connection.accept()?;
}
RtmpConnectionEvent::VideoReceived(frame) => {
// 映像フレームを受信
}
RtmpConnectionEvent::AudioReceived(frame) => {
// 音声フレームを受信
}
_ => {}
}
}
// 送信バッファを取得してソケットに書き込む
let send_data = connection.send_buf();
// send_data を送信...
connection.advance_send_buf(send_data.len());
| 構造体 | 説明 |
|---|---|
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 を利用しています。
MP4 ファイルを RTMP/RTMPS サーバーに配信するクライアントの例です。
# RTMP
cargo run -p publish -- -H 127.0.0.1 -p 1935 -a live -s stream input.mp4
# RTMPS (--tls フラグ)
cargo run -p publish -- -H example.com -p 443 -a live -s stream --tls input.mp4
# RTMPS (URL スキーム)
cargo run -p publish -- -u rtmps://example.com/live/stream input.mp4
オプション:
-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: 詳細出力RTMP/RTMPS サーバーの例です。
# RTMP
cargo run -p server -- -H 0.0.0.0 -p 1935
# RTMPS
cargo run -p server -- --tls --cert cert.pem --key key.pem -p 443
オプション:
-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.