Linux,  网络相关

centos下nginx部署rtmp中转服务

yum git gcc pcre-devel openssl-devel
git clone https://github.com/arut/nginx-rtmp-module.git
tar -zxf nginx-1.12.2.tar.gz

wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar -zxf nginx-1.12.2.tar.gz
cd nginx-1.12.2
./configure --prefix=/usr/local/nginx  --add-module=../nginx-rtmp-module  --with-http_ssl_module  --with-debug --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid
make && make install

vi /etc/nginx/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;
}

rtmp {

    server {

        listen 1935;  #监听的端口

        chunk_size 4096;

        application live {  #rtmp推流请求路径
            live on;
            hls on;
            hls_path /usr/local/nginx/html/live;
            hls_fragment 5s;
            idle_streams off;
            wait_key on;
        }

        application movie {  #rtmp推流请求路径
            live on;
            hls on;
            hls_path /usr/local/nginx/html/movie;
            hls_fragment 5s;
            idle_streams off;
            wait_key on;
        }


    }
}

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       8880;
        server_name  localhost;


        location / {
            root   html;
            index  index.html index.htm;
        }

        location /live {
            # Serve HLS fragments
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            root /usr/local/nginx/html;
            add_header Cache-Control no-cache;
        }

        location /movie {
            # Serve HLS fragments
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            root /usr/local/nginx/html;
            add_header Cache-Control no-cache;
        }


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

    }

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        location /hls {
            # Serve HLS fragments
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            root /usr/local/nginx/html;
            add_header Cache-Control no-cache;
        }

        #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;
    #    }
    #}

}
====================================================================

mkdir /usr/local/nginx/html/live ####创建nginx配置文件中指向的目录
chown -R nginx:nginx /usr/local/nginx/html/live


ffmpeg -re -i G:/大圣归来.mkv -vcodec libx264 -s 1080*720 -vf  "[in]drawtext=fontfile=/Windows/Fonts/simhei.ttf:x=w*0.6*sin(t)*sin(t):y=20:fontcolor=white:fontsize=60:text='%{localtime\:%Y\\\-%m\\\-%d}' ,drawtext=fontfile=/Windows/Fonts/simhei.ttf:x=w*0.7*sin(t)*sin(t):y=90:fontcolor=white:fontsize=60:text='%{localtime\:%H\\\:%M\\\:%S\}',drawtext=fontfile=/Windows/Fonts/simhei.ttf:x=w*0.8*sin(t)*sin(t):y=160:fontcolor=white:fontsize=60:text="搜索12345"[out]"  -f flv rtmp://192.168.1.111/oflaDemo/live

ffmpeg -re -i G:/大圣归来.mkv -vcodec libx264 -s 1080*720 -vf  "[in]drawtext=fontfile=/Windows/Fonts/simhei.ttf:x=w*0.6*sin(t)*sin(t):y=20:fontcolor=white:fontsize=60:text='%{localtime\:%Y\\\-%m\\\-%d}' ,drawtext=fontfile=/Windows/Fonts/simhei.ttf:x=w*0.7*sin(t)*sin(t):y=90:fontcolor=white:fontsize=60:text='%{localtime\:%H\\\:%M\\\:%S\}',drawtext=fontfile=/Windows/Fonts/simhei.ttf:x=w*0.8*sin(t)*sin(t):y=160:fontcolor=white:fontsize=60:text="搜索12345"[out]"  -f flv rtmp://192.168.1.111/oflaDemo/live


列出我们本机的设备:ffmpeg -list_devices true -f dshow -i dummy

.\ffmpeg -r 25 -f dshow -s 640*480 -i video="WebCam SC-10HDD12636N":audio="麦克风 (Realtek High Definition Au" -vcodec libx264 -b:v 600k -preset:v ultrafast -acodec aac -ab 128k -f flv rtmp://192.168.0.143/live/stream

.\ffmpeg -f dshow -s 640*480 -i video="WebCam SC-10HDD12636N":audio="麦克风 (Realtek High Definition Au" -vcodec libx264 -acodec aac -preset:v ultrafast -tune:v zerolatency -f flv rtmp://192.168.0.143/live/stream

ffmpeg -f dshow -i video="WebCam SC-10HDD12636N":audio="麦克风 (Realtek High Definition Au" -vcodec libx264 -acodec aac -preset:v ultrafast -tune:v zerolatency -f rtsp rtsp://127.0.0.1/live.sdp

ffmpeg -f dshow -i video="WebCam SC-10HDD12636N" -s 640x360 -vcodec libx264 -b:v 1000k -ab 128k -f flv rtmp://192.168.0.143/live/stream


常用推流
ffmpeg -re -i \[BD影视分享bd-film.co\]的士速递5.Taxi.5.2018.BD720P.法语中字.mp4 -r 23 -b:v 1500K -vcodec libx264 -s 1280*720 -acodec aac -vf "[in]drawtext=fontfile=simhei.ttf:x=w*sin(t/5)*0.8:y=20:fontcolor=white:fontsize=30:text='此视频仅供流媒体推流测试使用%{localtime\:%Y\\\-%m\\\-%d %H\\\\\:%M\\\\\:%S}'[out]" -f flv rtmp://122.225.124.66:19355/movie/movie

留言