Windows10环境下 Nginx+ffmpeg自搭服务器制作RTMP直播流

Windows10环境下 Nginx+ffmpeg自搭服务器制作RTMP直播流

学习笔记

所需条件:

  1. nginx-rtmp-module(带rtmp模块) ,链接:https://link.jianshu.com/?t=http%3A%2F%2Fnginx-win.ecsds.eu%2Fdownload%2Fnginx%201.7.11.3%20Gryphon.zip

  2. ffmpeg,链接:https://pan.baidu.com/s/1XItEYzDjpGrkAUinBwQTUw
    提取码:o0fg

  3. VLC播放器https://www.videolan.org/

安装nginx
1、下载后,直接解压到自己想解压的地方,然后进入conf文件夹,修改nginx.conf的配置(如果没有的话则自己创建):

#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;
    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       8888;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            root   html;
            index  index.html index.htm;
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
    # 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;
    #    }
    #}

}
rtmp_auto_push on;
rtmp {
    server {
        listen 1935;
        application myapp {
            live on;
        }       
    }
}

#主要上上面这两段rtmp模块代码,在代码的最后加上一个rtmp模块

2、然后,启动nginx,nginx命令:
启动:strat nginx
关闭:nginx -s stop
重启:nginx -s reload
注意:修改完配置必须重启
注意:如果出现错误,说nginx.pid不存在,则要在logs目录下创建nginx.pid,error.log不存在则创建error.log

3、启动后,发现命令行并没有什么显示,这时打开localhost:8888,看到nginx的页面就发现nginx已经启动
注意:端口号在nginx.conf的LISTEN配置

安装ffmpeg
1、解压到自己喜欢的地方
2、添加电脑环境变量,这样就可以全局使用ffmpeg命令,进入环境变量PATH,进行编辑,加入如:D:/ffmpeg/bin,即可
3、测试是否成功,cmd命令行下输入ffmpeg即可查看
在这里插入图片描述
安装VLC
到官网下载即可(用于播放流直播)

进行推流
进入一个具有测试视频test.mp4的文件夹,在cmd命令行下进行推流,
ffmpeg -re -i test.mp4 -vcodec libx264 -acodec aac -f flv rtmp://localhost:1935/myapp/pc

解释:
1、myapp为application的名字,由nginx的conf中定义
2、pc自定义,由推流方确定,组成一个地址rtmp://localhost:1935/myapp/pc
3、-vcodec libx264 代表264视频编码
4、-acodec aac -f flv 代表aac音频编码

扫描二维码关注公众号,回复: 4393594 查看本文章

查看直播源
在VLC的媒体/打开网络串流/网络,输入推流的地址:rtmp://localhost:1935/myapp/pc,就可以看到直播啦

这篇博客主要用来记录自己的笔记,还有给一些需要参考的人提供下,互相学习,如有不对或者不好的地方,大家可以提出批评和建议,o(∩_∩)o

最后感谢提供参考的博客和博主
Silence潇湘夜雨
https://www.jianshu.com/p/59b558bac8a7

猜你喜欢

转载自blog.csdn.net/qq_40816360/article/details/83999836
今日推荐