ffmpeg+nginx 推送mp4、搭建flv服务

ffmpeg+nginx 搭建flv服务

      • 说明
        • 1. ffmpeg推送mp4
        • 2. nginx配置文件
        • 3. 客户端从nginx拉flv的流
        • 4. 附录: flv播放器

说明

  • 目的: 搭建flv服务、方便测试

1. ffmpeg推送mp4

  • ffmpeg -re -i "xxx.mp4" -acodec aac -ar 32000 -vcodec copy -f flv "rtmp://nginx所在的ip:20935/flvlive/a"

2. nginx配置文件

  • 2.1示例
worker_processes  1;
events {
    worker_connections  1024;
}
# 添加RTMP服务
rtmp {
    out_queue           4096;
    out_cork            8;
    max_streams         4096;
    #timeout             15s;
    drop_idle_publisher 30s;

    log_interval 5s;
    log_size     1m; #buffer size used by log module to log in access.log
    server {
        listen 20935; # 监听端口
        # chunk_size 4000;
        application flvlive {
            live on;
            gop_cache off;
            wait_key on;
            interleave off;
        }
    }
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    #access_log  logs/access.log  main;

    server {
        listen       9995; # 监听端口

        #从系统时间中正则匹配出年月日
        if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") {
            set $date $1$2$3;
        }

        # 日期记录日志
        access_log  logs/$date.host.access.log;

        location /flvlive{
            flv_live on;
            chunked_transfer_encoding on;
            add_header Cache-Control no-cache;
            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Headers X-Requested-With;
            add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
        }

        location / {
            root html;
        }
    }
}

  • 2.2 启动
# 进入到nginx根目录
nginx.exe -c conf/nginx.conf

3. 客户端从nginx拉flv的流

  • http的链接 http://nginx的ip:9995/flvlive?port=20935&app=flvlive&stream=a&1.flv

4. 附录: flv播放器

  • https://github.com/bilibili/flv.js

你可能感兴趣的:(软件,nginx,nginx,音视频,运维)