赞
踩
docker nginx zip_Ubuntu中使用Nginx+rtmp模块搭建流媒体视频点播服务
http://www.zzvips.com/article/39011.html
docker 镜像:tiangolo/nginx-rtmp:latest
ffmpeg 本文基于版本:ffmpeg 4.4.1-static
2、制作镜像
mkdir rtmp && cd rtmp
worker_processes auto; rtmp_auto_push on; events { } #直播流配置 rtmp { server { #端口 listen 1935; # RTMP 直播流配置 application rtmplive { # 非常重要, 设定让ngnix断开阻塞中的连接, 才能触发exec_record_done # 以及客户端的LFLiveKit reconnectCount自动重新连接才会好用 drop_idle_publisher 5s; live on; } # HLS 直播流配置 application hls { live on; record all; record_path /tmp; record_max_size 10485760K; record_unique off; record_append on; hls on; hls_path /tmp; hls_fragment 5s; } } } # HLS 拉流配置(vlc播放 http://127.0.0.1:8080/hls/XXX.m3u8,其中http://127.0.0.1:8080/hls/为下面location的值,XXX为具体推流的配置) http { server { listen 8080; location /hls { types { application /vnd.apple.mpegurl m3u8; video /mp2t ts; } #访问权限开启,否则访问这个地址会报403 autoindex on; #视频流存放地址,与上面的hls_path相对应,这里root和alias的区别可自行百度 alias /tmp; expires -1; add_header Cache-Control no-cache; #防止跨域问题 add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; } } }
FROM tiangolo/nginx-rtmp
COPY nginx.conf /etc/nginx/nginx.conf
docker build -t trc-nginx-rtmp .
docker run -d -p 1935:1935 -p 1900:8080 -v /tmp:/tmp --privileged=true --name trc-nginx-rtmp trc-nginx-rtmp
注意:
特别需要注意/Users/taoruicheng/temp文件夹的权限设置成777。
注意这里面开启了1935推流端口 和 1900拉流端口。
ffmpeg -rtsp_transport tcp -i rtsp://admin:root@11.122.2.143:554 -vcodec copy -f flv -an rtmp://11.122.2.143:1935/hls/abc
(vlc播放地址:http://11.122.2.143:1900/hls/abc.m3u8)
ffmpeg -re -stream_loop -1 -i /Users/taoruicheng/工作资料目录/视频素材/仓xx.mp4 -vcodec copy -acodec copy -f flv rtmp://11.122.2.143:1935/hls/xxx
(vlc播放地址:http://11.122.2.143:1900/hls/xxx.m3u8)
<!DOCTYPE html> <html> <head> <meta charset=utf-8 /> <title>videojs-contrib-hls embed</title> <link href="https://unpkg.com/video.js/dist/video-js.css" rel="stylesheet"> <script src="https://unpkg.com/video.js/dist/video.js"></script> <script src="https://unpkg.com/videojs-contrib-hls/dist/videojs-contrib-hls.js"></script> </head> <body> <h1>Video.js Example Embed</h1> <video id="my_video_1" class="video-js vjs-default-skin" controls preload="auto" width="640" height="268" data-setup='{}'> <source src="http://11.122.2.143:1900/hls/xxx.m3u8" type="application/x-mpegURL"> </video> <script> </script> </body> </html>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。