Created
June 11, 2026 20:59
-
-
Save mamemomonga/def2973330bf3545fcf49f589eea8390 to your computer and use it in GitHub Desktop.
ffmpegでBluecast, YouTube, ニコニコ, Twitchに同時配信する。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl | |
| use strict; | |
| use warnings; | |
| use feature 'say'; | |
| my @live=( | |
| { | |
| service => 'bluecast', | |
| enable => 1, | |
| url => 'https://bluecast-9y4ewmyc.whip.livekit.cloud/w', | |
| token => 'バリアトークン', | |
| },{ | |
| service => 'youtube', | |
| enable => 1, | |
| url => 'rtmp://a.rtmp.youtube.com/live2', | |
| key => 'ストリームキー', | |
| },{ | |
| service => 'twitch', | |
| enable => 1, | |
| # 最新のURLは以下のスニペットで取得できる | |
| # curl -s https://ingest.twitch.tv/ingests | jq -r '.ingests[] | select(.name | test("Tokyo"; "i")) | .url_template' | |
| url => 'rtmp://apn10.contribute.live-video.net/app', | |
| key => 'ストリームキー', | |
| }, { | |
| service => 'niconico', | |
| enable => 1, | |
| # macOS Tahoeの場合は rtmp:// にすること | |
| url => 'rtmps://liveorigin.dlive.nicovideo.jp/live/input', | |
| key => 'ストリームキー', | |
| }, | |
| ); | |
| =comment | |
| OBSからは「録画」で使用する | |
| ビットレート等は一番高品質な送信先の設定にする | |
| 設定 > 出力 > 出力モード:詳細 > 録画 | |
| 種別: カスタム出力(ffmpeg) | |
| FFmpeg出力の種類: URLに出力 | |
| URL: udp://127.0.0.1:1234 | |
| コンテナフォーマット: mpegts | |
| 映像ビットレート: 6000kbps | |
| 映像エンコーダ: h264_videotoolbox | |
| 音声ビットレート: 192 kbps | |
| 音声エンコーダ: aac_at | |
| =cut | |
| my @ff=('ffmpeg','-i','udp://127.0.0.1:1234?fifo_size=1000000&overrun_nonfatal=1'); | |
| sub bluecast_hd { | |
| my $li=shift; | |
| return unless($li->{enable}); | |
| push @ff,qw(-map 0:v -map 0:a); | |
| push @ff,('-vf','scale=-2:720'); | |
| push @ff,qw(-c:v libx264 -profile:v baseline -bf 0 -pix_fmt yuv420p); | |
| push @ff,qw(-preset veryfast -tune zerolatency); | |
| push @ff,qw(-b:v 2500k -maxrate 2500k -bufsize 5000k -g 60); | |
| push @ff,qw(-c:a libopus -b:a 128k -ar 48000 -ac 2); | |
| push @ff,qw(-f whip); | |
| push @ff,('-authorization',$li->{token},$li->{url}); | |
| } | |
| sub rtmp_720p30 { | |
| my $li=shift; | |
| return unless($li->{enable}); | |
| push @ff,('-vf','scale=-2:720:flags=neighbor,fps=30'); | |
| push @ff,qw(-c:v h264_videotoolbox -b:v 3000k); | |
| push @ff,qw(-c:a aac -b:a 128k -ar 48000); | |
| push @ff,('-f','flv',$li->{url}.'/'.$li->{key}); | |
| } | |
| sub rtmp_copy { | |
| my $li=shift; | |
| return unless($li->{enable}); | |
| push @ff,('-c','copy','-f','flv',$li->{url}.'/'.$li->{key}); | |
| } | |
| foreach my $li(@live) { | |
| bluecast_hd($li) if($li->{service} eq 'bluecast'); | |
| rtmp_720p30($li) if($li->{service} eq 'niconico'); | |
| rtmp_copy($li) if($li->{service} eq 'youtube'); | |
| rtmp_copy($li) if($li->{service} eq 'twitch'); | |
| } | |
| say join(" ",@ff); | |
| exec(@ff); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment