美文网首页
直播工作原理

直播工作原理

作者: nzjcnjzx | 来源:发表于2019-04-21 17:43 被阅读0次
  • 直播相关的协议


    直播协议
HLS
RTMP
FLV
  • FLV只有safari的浏览器才支持,其他不支持,

直播源的制作

nginx + ffmpeg

mac 下

  • 安装homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • 下载nginx相关模块
brew tap homebrew/nginx
brew install nginx-full --with-rtmp-module
查看nginx安装的位置
brew info nginx-full
  • 安装ffmpeg
brew install ffmpeg
  • 配置nginx
#user  nobody;
worker_processes 1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections 1024;
}
http {
    include mime.types;
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#    listen       8000;
#    listen       somename:8080;
#    server_name  somename  alias  another.alias;
#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}
# HTTPS server
#
#server {
#    listen       443 ssl;
#    server_name  localhost;
#    ssl_certificate      cert.pem;
#    ssl_certificate_key  cert.key;
#    ssl_session_cache    shared:SSL:1m;
#    ssl_session_timeout  5m;
#    ssl_ciphers  HIGH:!aNULL:!MD5;
#    ssl_prefer_server_ciphers  on;
#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}
    include servers/*;
    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;
#gzip  on;
    server {
        listen 8080;
        server_name localhost;
#charset koi8-r;
#access_log  logs/host.access.log  main;
        location / {
            root html;
            index index.html index.htm;
        }
        location /hls {
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            root /usr/local/var/www;
            add_header Cache-Control no-cache;
        }
        location = /50x.html {
            root html;
        }
#error_page  404              /404.html;
# redirect server error pages to the static page /50x.html
#
        error_page 500 502 503 504  /50x.html;
    }
}
rtmp {
    server {
        listen 1935;
        chunk_size 4000;
# RTMP 直播流配置
        application rtmplive {
            live on;
            max_connections 1024;
        }
# hls 直播流的配置
        application hls {
            live on;
            hls on;
            hls_path /usr/local/var/www/hls;
            hls_fragment 5s;
        }
    }
}

  • 进行推流
推流至RTMP到服务器
ffmpeg -re -i test.mp4 -vcode
生成地址: rtmp://localhost:1935/rtmplive/democ libx264 -vprofile 
baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 rtmp://localhost:1935/rtmplive/demo

推流至HLS到服务器
生成地址: [http://localhost:8080/hls/test.m3u8](http://localhost:8080/hls/test.m3u8)

ffmpeg -re -i /Users/apple/Desktop/ffmepg/story.mp4 -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 rtmp://localhost:1935/hls/demo
  • VLC 下载 用来读取流


    vlc
    vlc

相关文章

网友评论

      本文标题:直播工作原理

      本文链接:https://www.haomeiwen.com/subject/clyjgqtx.html