일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
- 빈
- Library
- workmanager
- PHP
- schedule
- Job
- alarmanager
- jobdispatcher
- epmty
- Background
- Service
- livedatam
- shceduler
- firebase
- Android
- jobschduler
- 검사
- Today
- Total
에몽이
Nginx - HLS - RTMP 본문
unzip git-devel.zip
cd git-master/
autoconf
./configure
make
make install
3.4 설치 패키지 디렉토리를 만듭니다
mkdir ~/ffmpeg-source
4. FFmpeg 및 해당 종속 패키지 설치
4.1、Yasm
cd ~/ffmpeg-source
wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
tar xzvf yasm-1.2.0.tar.gz
cd yasm-1.2.0
./configure
make
make install
4.2、x264
cd ~/ffmpeg-source
git clone git://git.videolan.org/x264
cd x264
./configure –enable-shared
make
make install
4.3、LAME
cd ~/ffmpeg-source
wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar xzvf lame-3.99.5.tar.gz
cd lame-3.99.5
./configure –enable-nasm
make
make install
4.4、libogg
cd ~/ffmpeg-source
wget http://downloads.xiph.org/releases/ogg/libogg-1.3.0.tar.gz
tar xzvf libogg-1.3.0.tar.gz
cd libogg-1.3.0
./configure
make
make install
4.5、libvorbis
cd ~/ffmpeg-source
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.3.tar.gz
tar xzvf libvorbis-1.3.3.tar.gz
cd libvorbis-1.3.3
./configure
make
make install
4.6、libvpx
cd ~/ffmpeg-source
git clone http://git.chromium.org/webm/libvpx.git
cd libvpx
./configure –enable-shared
make
make install
4.7、 FAAD2
cd ~/ffmpeg-source
wget http://downloads.sourceforge.net/project/faac/faad2-src/faad2-2.7/faad2-2.7.tar.gz
tar zxvf faad2-2.7.tar.gz
cd faad2-2.7
./configure
make
make install
4.8、FAAC
cd ~/ffmpeg-source
wget http://downloads.sourceforge.net/project/faac/faac-src/faac-1.28/faac-1.28.tar.gz
tar zxvf faac-1.28.tar.gz
cd faac-1.28
./configure
make
make install
4.9、Xvid
cd ~/ffmpeg-source
wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz
tar zxvf xvidcore-1.3.2.tar.gz
cd xvidcore/build/generic
./configure
make
make install
4.10、FFmpeg
cd ~/ffmpeg-source
git clone git://source.ffmpeg.org/ffmpeg
cd ffmpeg
./configure –enable-version3 –enable-libvpx –enable-libfaac –enable-libmp3lame –enable-libvorbis –enable-libx264 –enable-libxvid –enable-shared –enable-gpl –enable-postproc –enable-nonfree –enable-avfilter –enable-pthreads
make
make install
ldconfig –v
5、 nginx 와 nginx-rtmp-module 설치
mkdir ~/nginx-source
cd ~/nginx-source
wget http://nginx.org/download/nginx-1.2.4.tar.gz
tar zxvf nginx-1.2.4.tar.gz
wget -O nginx-rtmp-module.zip https://github.com/arut/nginx-rtmp-module/archive/master.zip
unzip nginx-rtmp-module.zip
wget -O ngx_cache_purge.zip https://github.com/FRiCKLE/ngx_cache_purge/archive/master.zip
unzip ngx_cache_purge.zip
cd nginx-1.2.4
./configure –user=daemon –group=daemon –prefix=/usr/local/nginx-1.2.4/ –add-module=../nginx-rtmp-module-master –add-module=../nginx-rtmp-module-master/hls –add-module=../ngx_cache_purge-master –with-http_stub_status_module –with-http_ssl_module –with-http_sub_module –with-md5=/usr/lib –with-sha1=/usr/lib –with-http_gzip_static_module
nginx.conf 에 rtmp 모듈 구성 정보 추가
구성예
rtmp {
server {
listen 1935;
chunk_size 4000;
# TV mode: one publisher, many subscribers
application mytv {
# enable live streaming
live on;
# record first 1K of stream
record all;
record_path /tmp/av;
record_max_size 1K;
# append current timestamp to each flv
record_unique on;
# publish only from localhost
allow publish 127.0.0.1;
deny publish all;
#allow play all;
}
# Transcoding (ffmpeg needed)
application big {
live on;
# On every pusblished stream run this command (ffmpeg)
# with substitutions: $app/${app}, $name/${name} for application & stream name.
#
# This ffmpeg call receives stream from this application &
# reduces the resolution down to 32×32. The stream is the published to
# ‘small’ application (see below) under the same name.
#
# ffmpeg can do anything with the stream like video/audio
# transcoding, resizing, altering container/codec params etc
#
# Multiple exec lines can be specified.
exec /usr/local/bin/ffmpeg -re -i rtmp://localhost:1935/$app/$name -vcodec flv -acodec copy -s 32×32 -f flv rtmp://localhost:1935/small/${name};
}
application small {
live on;
# Video with reduced resolution comes here from ffmpeg
}
application mypush {
live on;
# Every stream published here
# is automatically pushed to
# these two machines
#push rtmp1.example.com;
#push rtmp2.example.com:1934;
}
application mypull {
live on;
# Pull all streams from remote machine
# and play locally
#pull rtmp://rtmp3.example.com pageUrl=www.example.com/index.html;
}
# video on demand
application vod {
play /var/flvs;
}
application vod2 {
play /var/mp4s;
}
# Many publishers, many subscribers
# no checks, no recording
application videochat {
live on;
# The following notifications receive all
# the session variables as well as
# particular call arguments in HTTP POST
# request
# Make HTTP request & use HTTP retcode
# to decide whether to allow publishing
# from this connection or not
on_publish http://localhost:8080/publish;
# Same with playing
on_play http://localhost:8080/play;
# Publish/play end (repeats on disconnect)
on_done http://localhost:8080/done;
# All above mentioned notifications receive
# standard connect() arguments as well as
# play/publish ones. If any arguments are sent
# with GET-style syntax to play & publish
# these are also included.
# Example URL:
# rtmp://localhost/myapp/mystream?a=b&c=d
# record 10 video keyframes (no audio) every 2 minutes
record keyframes;
record_path /var/vc;
record_max_frames 10;
record_interval 2m;
# Async notify about an flv recorded
on_record_done http://localhost:8080/record_done;
}
# HLS
# HLS requires libavformat & should be configured as a separate
# NGINX module in addition to nginx-rtmp-module:
# ./configure … –add-module=/path/to/nginx-rtmp-module/hls …
# For HLS to work please create a directory in tmpfs (/tmp/app here)
# for the fragments. The directory contents is served via HTTP (see
# http{} section in config)
#
# Incoming stream must be in H264/AAC/MP3. For iPhones use baseline H264
# profile (see ffmpeg example).
# This example creates RTMP stream from movie ready for HLS:
#
# ffmpeg -loglevel verbose -re -i movie.avi -vcodec libx264
# -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1
# -f flv rtmp://localhost:1935/hls/movie
#
# If you need to transcode live stream use ‘exec’ feature.
#
application hls {
hls on;
hls_path /var/app;
hls_fragment 5s;
}
}
}
# HTTP can be used for accessing RTMP stats
http {
server {
listen 8080;
# This URL provides RTMP statistics in XML
location /stat {
rtmp_stat all;
# Use this stylesheet to view XML as web page
# in browser
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
# XML stylesheet to view RTMP stats.
# Copy stat.xsl wherever you want
# and put the full directory path here
root /path/to/stat.xsl/;
}
location /hls {
# Serve HLS fragments
alias /var/app;
}
}
}
6、 segmenter 설치
svn co http://httpsegmenter.googlecode.com/svn/
move svn segmenter
cd segmenter/trunk
gcc -Wall -g segmenter.c -o segmenter -lavformat -lavcodec -lavutil -std=c99
cp segmenter /usr/bin/
서버에 파일 저장
baluobu.flv
10year.mp3
mkdir /var/flvs /var/mp4s /var/vc /var/app /var/app/10year /var/app/baluobu
FFmpeg를 사용하여
MPEG을 TS로 비디오 및 오디오 포맷 파일을 테스트ffmpeg -i /var/flvs/baluobu.flv -f mpegts -acodec libmp3lame -ar 48000 -ab 128k -vcodec libx264 -b 96k -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 200k -maxrate 96k -bufsize 96k -rc_eq ‘blurCplx^(1-qComp)’ -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 320:240 -g 30 -async 2 /var/app/baluobu/baluobu.ts
ffmpeg -i /var/flvs/10year.mp3 -f mpegts -acodec libmp3lame -ar 48000 -ab 128k -vcodec libx264 -b 96k -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 200k -maxrate 96k -bufsize 96k -rc_eq ‘blurCplx^(1-qComp)’ -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 320:240 -g 30 -async 2 /var/app/10year/10year.ts
cd /var/app/10year
segmenter -i 10year.ts -d 5 -o 10year -x 10year.m3u8
cd /var/app/baluobu
segmenter -i baluobu.ts -d 5 -o buluobu -x baluobu.m3u8
7, 테스트
단순 VLC 테스트를 사용합니다.
http://192.168.1.11:8080/hls/10year/10year.m3u8
http://192.168.1.11:8080/hls/baluobu/baluobu.m3u8
아무 문제가 없다면, 성공을 나타내는 제대로 HTTP 라이브 스트리밍 (HLS) 서비스 구성되었습니다
그런 다음 위의 주소에 액세스 할 IOS 장치에서 사파리를 사용할 수 있습니다
또는 안드로이드 VPLAYER은 위의 주소로 방문 후 시스템에 설치
당신은 웹 양식을 통해 온라인 비디오를 제공 할 필요가있는 경우에, 당신은 Nginx에의 mime.types 파일에 필요, 다음과 같은 MIME 유형을 추가 :
. M3u8 응용 프로그램 / x-mpegURL
. TS video/MP2T
한편 HTML5 비디오 태그 페이지에 비디오를 포함 m3u8 파일을 사용하여
<VIDEO controls>
<source src=http://192.168.1.11:8080/hls/baluobu/baluobu.m3u8 />
</ 비디오>
8. 개발 설명
IOS HTTP 라이브 스트리밍 (HLS)에 대한 기본 지원을하고 있습니다 만 위의 주소를 재생할 수 MPMoviePlayerController를 사용합니다
애플 문서 : http://bit.ly/Rnpsef
나중에 새 클래스 안드로이드 3.x를의 NuPlayer는 HTTP 스트리밍 라이브 지원하지만, 그 기능은 프로세스를 단순화하기 위해, 약한, 당신은 사용할 수 있습니다
Vitamio http://vov.io/vitamio/ 또는 http://code.taobao.org/p/oplayer/src/ 다운로드
Servestream의 http://sourceforge.net/projects/servestream/
Nginx - RTMP module 자체도 온라인 방송 시스템을 구축 Nginx에 기반으로 할 수 있습니다 RTMP 프로토콜을 지원합니다.
'Backend > web server' 카테고리의 다른 글
vert.x는 무엇이 좋은가? (0) | 2017.03.09 |
---|---|
비동기 네트워크 서버 프레임웍 Vert.x 소개 (0) | 2017.03.09 |
Forward Proxy와 Reverse Proxy (0) | 2017.03.09 |
What is .htaccess? (0) | 2017.03.03 |
What are the disadvantages of using Node.js for handling static resources? (0) | 2017.03.03 |