Skip to content
Snippets Groups Projects
Verified Commit dd3f07d4 authored by Andrej Ramašeuski's avatar Andrej Ramašeuski
Browse files

Rizeni nahravani parametrem v rtmp push url

parent c41e5432
Branches
Tags
No related merge requests found
Pipeline #1437 failed
package PiTube::Controller::Nginx;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::UserAgent;
use Mojo::IOLoop;
use constant HLS => qr/^\/hls\/([a-z0-9\-]+)(_\w+)?(\/\w+)?\.(m3u8|ts)$/i;
......@@ -7,10 +9,11 @@ sub callback_rtmp {
my $c = shift;
if ( $c->param('call') =~ /publish/ ) {
my $name = $c->param('name');
# stream
my $stream = $c->schema->resultset('Stream')->find({
key => $c->param('name')
key => $name,
});
$c->render( status => 404, text => '' ), return if ! $stream;
......@@ -20,15 +23,32 @@ sub callback_rtmp {
});
$c->render( status => 403, text => ''), return if ! $user;
# TODO: autorizace user/stream
# aktualizace stavu streamu
$stream->update({
publish_last => '\now()',
publish_user_id => $user->id,
publish_time => ( $c->param('time') // 0 ),
});
# zapnuti nahravani
if ( $c->param('record') && $c->param('record') =~ /(all|audio)/) {
my $record = $1;
my $ua = Mojo::UserAgent->new;
Mojo::IOLoop->timer(1 => sub ($loop) {
my $res = $ua->get(
$c->config->{nginx}{base_url}
. "/control/record/start?app=stream&name=$name&rec=$record"
);
});
}
}
$c->render( status => 204, text => '' );
}
sub callback_hls {
......
......@@ -14,42 +14,35 @@ rtmp {
application stream {
live on;
on_publish http://pitube:3000/callback/rtmp;
on_publish http://pitube:3000/callback/rtmp;
on_publish_done http://pitube:3000/callback/rtmp;
on_update http://pitube:3000/callback/rtmp;
notify_update_timeout 15s;
# -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 1000k -f flv -g 30 -r 30 -s 854x480 -preset superfast -profile:v baseline
# rtmp://localhost:1935/hls/$name_480p1128kbs
# -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 750k -f flv -g 30 -r 30 -s 640x360 -preset superfast -profile:v baseline
# rtmp://localhost:1935/hls/$name_360p878kbs
# -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 400k -f flv -g 30 -r 30 -s 426x240 -preset superfast -profile:v baseline
# rtmp://localhost:1935/hls/$name_240p528kbs
exec ffmpeg -i rtmp://localhost:1935/stream/$name
-c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 2500k -f flv -g 30 -r 30 -s 1280x720 -preset superfast -profile:v baseline
rtmp://localhost:1935/hls/$name_720p2628kbs
-c:a libfdk_aac -b:a 64k -c:v libx264 -b:v 200k -f flv -g 15 -r 15 -s 426x240 -preset superfast -profile:v baseline
rtmp://localhost:1935/hls/$name_240p264kbs;
hls on;
hls_path /tmp/hls;
hls_fragment 15s;
recorder all {
record all manual;
record_suffix -%y%m%d-%h%m%s.flv;
record_path /tmp;
record_unique on;
record_max_size 4000m;
}
recorder audio {
record audio manual;
record_suffix -%y%m%d-%h%m%s.audio.flv;
record_path /tmp;
record_unique on;
record_max_size 500m;
}
application hls {
live on;
hls on;
hls_fragment_naming system;
hls_fragment 5;
hls_playlist_length 10;
hls_path /tmp/hls;
hls_nested on;
hls_variant _720p2628kbs BANDWIDTH=2628000,RESOLUTION=1280x720;
# hls_variant _480p1128kbs BANDWIDTH=1128000,RESOLUTION=854x480;
# hls_variant _360p878kbs BANDWIDTH=878000,RESOLUTION=640x360;
# hls_variant _240p528kbs BANDWIDTH=528000,RESOLUTION=426x240;
hls_variant _240p264kbs BANDWIDTH=264000,RESOLUTION=426x240;
}
}
}
......@@ -64,8 +57,12 @@ http {
server {
listen ${HTTP_PORT};
location /control {
rtmp_control all;
}
location /hls {
auth_request /callback/hls;
# auth_request /callback/hls;
alias /tmp/hls;
types {
application/vnd.apple.mpegurl m3u8;
......
......@@ -32,5 +32,8 @@
},
rtmp => {
base_url => $ENV{RTMP_BASE_URL},
},
nginx => {
base_url => $ENV{NGINX_BASE_URL} // 'http://nginx-rtmp',
}
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment