https://www.freesion.com/article/51881008653/
https://gitee.com/LateWinter/nginx-rtmp-http-flv/blob/master/README.md
docker run -d -p 1945:1935 -p 8890:80 --name ggg --restart=unless-stopped -v /speed/data/nginx-web/www:/usr/share/nginx/html -v /speed/data/nginx-web/conf/:/etc/nginx/ -v /speed/data/nginx-web/log:/var/log/nginx winter227/nginx-http-flv:1.20.2
ffmpeg -re -rtsp_transport tcp -i rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov -f flv -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 rtmp://47.56.158.48:1935/live/video
结合使用ffmpeg+rtmp插件进行rtsp流转换,使用nginx+http-flv插件,可以用http协议播放flv格式实时流视频
开启nginx的rtmp功能
rtmp {
server {
listen 1935;
application live {
live on;
gop_cache on ; #打开GOP缓存,减少首屏等待时间
### 保存视频/start
record video; #记录直播视频
}
application hls {
live on;
hls on;
hls_path temp/hls;
hls_fragment 8s;
}
}
}
使用ffmpeg命令,推流到nginx的rtmp的流服务器,本例是把rtsp流转换成rtmp流的命令
推流到nginx的rtmp的流服务器
ffmpeg -re -rtsp_transport tcp -i rtsp://admin:abc12345@ip -f flv -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 rtmp://rtmpip:1935/live/video
使用FFMpeg命令行录屏推rtmp流
ffmpeg -f gdigrab -video_size 1920x1080 -framerate 25 -i desktop -vcodec libx264 -f flv rtmp://192.168.10.140/live/video
docker run -d --name video2 jrottenberg/ffmpeg:4-alpine -re -rtsp_transport tcp -i rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov -f flv -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -q 10 rtmp://192.168.10.140:1935/live/video1
配置nginx http-flv插件,是实时视频能http协议播放
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
server {
listen 9092;
location / {
root html;
}
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root html;
}
location /live {
flv_live on ; # 打开HTTP播放FLV直播流功能
chunked_transfer_encoding on ; # 支持'Transfer-Encoding: chunked'方式回复
add_header 'Access-Control-Allow-Origin' '*'; # 添加额外的HTTP头
add_header 'Access-Control-Allow-Credentials' 'true'; # 添加额外的HTTP头
expires -1;
}
location /hls {
# 指定允许跨域的方法,*代表所有
add_header Access-Control-Allow-Methods *;
# 预检命令的缓存,如果不缓存每次会发送两次请求
add_header Access-Control-Max-Age 3600;
# 带cookie请求需要加上这个字段,并设置为true
add_header Access-Control-Allow-Credentials true;
# 表示允许这个域跨域调用(客户端发送请求的域名和端口)
# $http_origin动态获取请求客户端请求的域 不用*的原因是带cookie的请求不支持*号
add_header Access-Control-Allow-Origin $http_origin;
# 表示请求头的字段 动态获取
add_header Access-Control-Allow-Headers
$http_access_control_request_headers;
# OPTIONS预检命令,预检命令通过时才发送请求
# 检查请求的类型是不是预检命令
if ($request_method = OPTIONS){
return 200;
}
#server hls fragments
types{
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
alias temp/hls;
expires -1;
}
}
}
使用flv.js插件播放,播放地址为
http://localip:9092/live?port=1935&app=live&stream=video
port为rtmp的端口
app为rtmp配置的live
stream为rtmp地址流路径, rtmp://rtmpip:1935/live/video
FROM mycujoo/nginx-http-flv-module
RUN mkdir /temp
ADD nginx-http-flv-module /temp/nginx-http-flv-module
ADD nginx-1.2.1 /temp/nginx-1.2.1
#ADD openssl-1.0.2l.tar.gz /temp/
#ADD openssl /temp/openssl
ADD perl-5.28.0 /temp/perl-5.28.0
ADD pcre-8.38.tar.gz /temp/
ADD zlib-1.2.11.tar.gz /temp/
#RUN cd /temp && ls && cd perl-5.28.0 && ls && ./Configure -des -Dprefix=/usr/local/localperl && make && make install
#RUN ln -s /usr/local/localperl/bin/perl /usr/bin/perl
#ADD openssl /temp/openssl
#RUN cd /temp && ls && cd openssl && ls && sh config --prefix=/usr/local/openssl && make && make install
RUN cd /temp && cd nginx-1.2.1 && ls && ./configure --prefix=/usr/local/nginx/ --add-module=../nginx-http-flv-module --with-http_stub_status_module --with-http_ssl_module --with-pcre=../pcre-8.38 --with-zlib=../zlib-1.2.11 && make && make install
#RUN cd /temp && cd nginx-1.2.1 && ls && ./configure --prefix=/usr/local/nginx --add-module=../nginx-http-flv-module --with-pcre=../pcre-8.38 --with-openssl=../openssl-1.0.2l --with-zlib=../zlib-1.2.11 && make && make install
RUN chmod +x /usr/local/nginx/sbin/nginx
RUN ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
RUN cp -rf /usr/local/nginx /tmp/
#RUN cp -rf /opt/nginx/nginx.conf /tmp/nginx/conf/
#RUN chmod +x /opt/nginx/sbin/nginx
#RUN ln -s /opt/nginx/sbin/nginx /usr/bin/nginx
#RUN cp -rf /opt/nginx/ /tmp/
ADD docker-run.sh /
RUN chmod +x /docker-run.sh
RUN rm -rf /temp/
#CMD ["/usr/local/nginx/sbin/nginx"]
#CMD ["sh","-c","/docker-run.sh"]
ENTRYPOINT ["/docker-run.sh"]
#CMD ["nginx","-g","daemon off;"]
#!/bin/sh
if [ ! -f "/usr/local/nginx/conf/nginx.conf" ];then
echo 'nginx init' && cp -rf /tmp/nginx /usr/local/
else
echo "nginx已经初始化"
fi
echo 'chmod' && chmod +x /usr/local/nginx/sbin/nginx && echo 'run:nginx' && nginx
#ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
#nginx
Content type
Image
Digest
Size
95.8 MB
Last updated
almost 5 years ago
docker pull winter227/nginx-http-flv:1.20.2