このNGINXモジュールはその場でhlsストリームのためのオーディオトラックを生成します。
GitHubで利用可能です。
Apple HTTP Live Streaming (HLS) はほとんど全てのビデオストリームプレイヤーのために採用されてきました。そして回線が細い接続を経験しているユーザに対してオーディオのみのトラックを提供することがお勧めの一つです。
This module aims to serve audio-only track directly on NGINX, without the necessity to pre-demux the stream on Video On Demand (VoD) scenarios or the overhead and occupation of one stream output on the encoder side for live streams.
Luaで書かれた単純なスクリプトを使ったNGINXのlocationとこのモジュールの組み合わせを使って、NGINX上で完全なオーディオトラックを生成することができます。ものごとがどのように行われるかを見ましょう。
ビュワーがマスタープレイリストをリクエストし、応答が修正されます。単純なluaスクリプトはリストの最初のストリームを取得し、最後にオーディオ プレイリストを追加します:
location ~ /master-playlist.m3u8$ {
rewrite (.*)master-playlist.m3u8$ $1playlist.m3u8 break;
content_by_lua '
local res = ngx.location.capture(ngx.var.uri);
local first_playlist = res.body:match("[^\\n]*m3u8")
local audio_playlist = first_playlist:gsub("\.m3u8", "-audio.m3u8")
local ext_inf = "#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=64000\\n"
ngx.print(res.body)
ngx.print(ext_inf)
ngx.print(audio_playlist)
ngx.print("\\n")
';
}
そして、ユーザの接続が悪くなり、オーディオターゲットに行かなければならなくなると、他のlocationがリクエストを処理し、もとの(ビデオ)プレイリストを取得しchunkの拡張子を変更するでしょう:
location ~ -audio\.m3u8$ {
default_type application/vnd.apple.mpegurl;
content_by_lua '
local base_m3u8_url = ngx.var.uri:gsub("-audio.m3u8", ".m3u8")
local res = ngx.location.capture(base_m3u8_url)
local new_body = res.body:gsub("\.ts", ".aac")
ngx.print(new_body)
';
}
.aac
拡張子への各リクエストはオーディオ抽出モジュールを起動するでしょう:
location ~ (\.aac)$ {
ngx_hls_audio_track;
ngx_hls_audio_track_rootpath "/path/were/video/chunks/are/";
expires 10m;
}
以上です!
このモジュールは大いに開発中です。フィードバック、問題およびパッチは歓迎です。
このモジュールは、その前にインストールされる必要がある幾つかの(ヘッダおよび共有オブジェクト)に依存し、一般的に FFmpegと一緒に一般的に配布されます:
今のところ、オーディオ抽出モジュールは mpegts
ビデオチャックから aac
オーディオのみのチャックの抽出のみをサポートします。
将来サポートされる予定のほかのフォーマットを見るには project issuesを見てください。
以下のステップに従ってください:
このプロジェクトをクローンする
$ git clone git://github.com/flavioribeiro/nginx-audio-track-for-hls-module.git
Clone Lua module
$ git clone git://github.com/chaoslawful/lua-nginx-module.git
NGINXをダウンロードし両方のモジュールを使ってコンパイルします:
$ ./configure --add-module=/path/to/nginx-audio-track-for-hls-module --add-module=/path/to/lua-nginx-module
$ make install
これでNGINX 設定例を調べ、変更をすることができます。楽しんでください!
警告
It’s highly recommended to use caching in all locations of HLS, in special the one that returns the generated .aac
.