运维类 - ffmpeg + nginx + vlc 搭建 rtmp 视频流服务

1.资源包下载地址:https://pan.baidu.com/s/1CjXIRBghH4BbjQXIk9rTyA

2.解压:nginx-1.7.11.3-stream.zip 到合适位置,使用cmd进入解压后的目录,运行命令:

nginx.exe -c conf\nginx-win-rtmp.conf

3.解压 ffmpeg.zip 放到合适位置,将加压后的bin目录加入到环境变量:

4.打开cmd,想nginx推流:

ffmpeg -re -i D:\installed\ffmpeg\orange.mp4 -vcodec libx264 -acodec aac -f flv rtmp://127.0.0.1:1935/live/home

 5.解压 VLCmediaplayerX64.zip ,打开播放器,点击【媒体】>>【打开网络串流】,将推流地址填进去,点击在点击【播放】

 6.注意:播放的时候,需要确保ffmpeg正在推流,否则就没有内容可以播放:

7.发布hls流完整的配置:

#user  nobody;
# multiple workers works !
worker_processes  2;
events {
    worker_connections  8192;
}

rtmp {
    server {
        listen 1935;
        chunk_size 4000;
        application live {
            live on;
            hls on;
            hls_path D:/installed/nginx-1.7.11.3-stream/video/hls;
            hls_fragment 5s;
            # 保存视频
            recorder rec1{
                record all;
                record_unique on;
                record_path D:/installed/nginx-1.7.11.3-stream/video/record;
                record_suffix -%Y-%m-%d-%H_%M_%S.mp4;
            }
        }
    }
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        off;

    server_names_hash_bucket_size 128;

    ## Start: Timeouts ##
    client_body_timeout   10;
    client_header_timeout 10;
    keepalive_timeout     30;
    send_timeout          10;
    keepalive_requests    10;
    ## End: Timeouts ##

    server {
        listen       80;
        server_name  localhost;
		
        location / {
            root   D:/installed/nginx-1.7.11.3-stream/video;
            index  index.html index.htm;
        }
		
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
		
        location /stat.xsl {
            root nginx-rtmp-module/;
        }
		
        location /control {
            rtmp_control all;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

 8.HTML5播放视频示例:

<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title>HTML5播放视频</title>
</head>
<body>

<video width="352" height="288" controls>
    <source src="http://192.168.1.106/hls/home.m3u8" type="application/vnd.apple.mpegurl">
    浏览器不支持 video 标签。
</video>

</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值