RTMP

Nginx RTMP推流

编译选版本nginx-1.20.1,rtmp-module v1.2.0

  • 下载
    1
    2
    3
    wget http://nginx.org/download/nginx-1.20.1.tar.gz
    tar -zxvf nginx-1.20.1.tar.gz
    git clone https://github.com/arut/nginx-rtmp-module.git
  • 编译
    1
    ./configure --add-module=../nginx-rtmp-module
  • 配置
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    rtmp {
    server {
    listen 1935; # 默认的RTMP监听端口
    chunk_size 4096;

    application live {
    live on;
    record off;
    }
    }
    }
  • 推流
    1
    2
    3
    4
    5
    ffmpeg -re -i 123.mp4 -vcodec copy -acodec copy -f flv rtmp://192.168.1.49:1935/live
    # 简易指令
    ffmpeg -i 123.mp4 -f flv rtmp://192.168.1.49:1935/live
    # 推流摄像头
    ffmpeg -f v4l2 -video_size 320x240 -framerate 15 -i /dev/video2 -q 10 -f flv rtmp://127.0.0.1/live/mytest
    -re 参数控制读取 AVpacket 的速度,按照帧率速度读取文件 AVpacket。如果有多个流,以最慢的帧率为准。

-vcodec copy 和 -acodec copy 用于指示 FFmpeg 在转换视频文件时不应重新编码视频和音频流,而是直接复制这些流。这可以提高转换速度,并保持原始质量。

  • 拉流
    1
    ffplay rtmp://192.168.1.49:1935/live

web服务器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 设置http服务器
http {
# 设置日志格式
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

# 设置服务器名和文件根目录
server {
listen 80;
# 服务器名,可不要
server_name localhost;

# 定义请求的根目录
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}

# 处理404页面
error_page 404 /404.html;
location = /40x.html {
}

# 处理500页面
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
-->

请我喝杯咖啡吧~

支付宝
微信