rtmp 설정
https://juyoung-1008.tistory.com/31
1.nginx
wget http://nginx.org/download/nginx-1.7.5.tar.gz
2.rtmp get
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
3.unzip 이 없다면
yum install unzip
4.혹시 yum 이 안되면
vi /etc/yum.repos.d/CentOS-Base.repo
# CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-$releasever - Base #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra baseurl=http://vault.centos.org/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 #released updates [updates] name=CentOS-$releasever - Updates #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra baseurl=http://vault.centos.org/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra baseurl=http://vault.centos.org/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra baseurl=http://vault.centos.org/centos/$releasever/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 #contrib - packages by Centos Users [contrib] name=CentOS-$releasever - Contrib #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib&infra=$infra baseurl=http://vault.centos.org/centos/$releasever/contrib/$basearch/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
5. nginx 도 풀고
tar -zxvf nginx-1.7.5.tar.gz
6. nginx 폴더에서 rtmp 모듈 추가
./configure --add-module=/path/to-nginx/rtmp-module --with-debug --with-http_ssl_module
7. gcc가 없다면 (그리고 다시6)
yum install gcc
8. error 라면
./configure: error: the HTTP rewrite module requires the PCRE library.
yum -y install pcre-devel
9.제길 귀찮다 . 개발 툴 다 설치하자.
# yum groupinstall "Development Tools"
# yum install pcre-devel openssl-devel libxslt-devel gd-devel perl-ExtUtils-Embed epel-release
# yum install GeoIP-devel
10.그리고 다시6
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ md5: using OpenSSL library
+ sha1: using OpenSSL library
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
11.make
12.make install
13. RTMP URL format
rtmp://rtmp.example.com/app/[/name]
app - 설정파일의 하나의 application 이름과 같아야 한덴다.
name - 설정하게 되면 개별의 방송을 할 수 있습니다. ( 방개념이란다) streamkey이기도하다.
14.ffmpeg도 해두자 .영상 저장 혹은 로컬 영상 배포용이다.
yum install ffmpeg
15. 이제 nginx에 rtmp 포트및 기타 설정하자.
심플한 사용방법은 이렇다
....
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;
application show {
live on;
allow publish all;
# # Turn on HLS
hls on;
hls_path /mnt/hls/;
hls_fragment 3;
hls_playlist_length 60;
# # disable consuming the stream from nginx as rtmp
# deny play all;
}
}
}
http{
...
-일단 간단하게 서버의 파일을 스트리밍 하는걸로 해보자 ffmpeg가 짱이다.
wget https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_640_3MG.mp4
ffmpeg -re -i example-vid.mp4 -vcodec libx264 -vprofile baseline -g 30 -acodec aac -strict -2 -f flv rtmp://너의서버아이피겠쥐?/show/stream
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 32x32. 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 ffmpeg -re -i rtmp://localhost:1935/$app/$name -vcodec flv -acodec copy -s 32x32 -f flv rtmp://localhost:1935/small/${name}; } application small { live on; # Video with reduced resolution comes here from ffmpeg } application webcam { live on; # Stream from local webcam exec_static ffmpeg -f video4linux2 -i /dev/video0 -c:v libx264 -an -f flv rtmp://localhost:1935/webcam/mystream; } 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; } application mystaticpull { live on; # Static pull is started at nginx start pull rtmp://rtmp4.example.com pageUrl=www.example.com/index.html name=mystream static; } # 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 /tmp/vc; record_max_frames 10; record_interval 2m; # Async notify about an flv recorded on_record_done http://localhost:8080/record_done; } # HLS # For HLS to work please create a directory in tmpfs (/tmp/hls here) # for the fragments. The directory contents is served via HTTP (see # http{} section in config) # # Incoming stream must be in H264/AAC. 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 { live on; hls on; hls_path /tmp/hls; } # MPEG-DASH is similar to HLS application dash { live on; dash on; dash_path /tmp/dash; } } }
------------------------------------
에러가 날떄.
1.Failed to set locale, defaulting to C 는
export LC_ALL=C
yudo yum check
2.centos6레포에러..
sed -i "s/mirrorlist=https/mirrorlist=http/" /etc/yum.repos.d/epel.repo
yum -y install epel-release
3.혹시 포트 열었는지
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 1935 -j ACCEPT
/etc/init.d/iptables restart
0 comments:
댓글 쓰기