下载ffmpeg
直接点击https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.zip
设置环境变量:将bin目录设置成环境变量:E:\ffmpeg\ffmpeg-6.0-essentials_build\ffmpeg-6.0-essentials_build\bin
终端查看,ffmpeg –version
查看摄像头名称: ffmpeg -list_devices true -f dshow -i dummy
名字为“。。。。 camera”
下载nginx
下载链接: http://nginx-win.ecsds.eu/download/nginx 1.7.11.3 Gryphon.zip
下载nginx-rtmp-module模块,在nginx目录中使用git指令 git clone https://github.com/arut/nginx-rtmp-module/
配置config文件: conf\nginx-win-rtmp.conf 内容如下:
worker_processes 2;
events {
worker_connections 8192;
}
rtmp {
server {
listen 1935;
chunk_size 4000;
application live {
live on;
record all;
record_path /tmp/av;
record_max_size 1K;
record_unique on;
allow publish 127.0.0.1;
deny publish all;
}
}
}
http {
include mime.types;
default_type application/octet-stream;
sendfile off;
server_names_hash_bucket_size 128;
client_body_timeout 10;
client_header_timeout 10;
keepalive_timeout 30;
send_timeout 10;
keepalive_requests 10;
server {
listen 80;
server_name localhost;
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root nginx-rtmp-module/;
}
location /control {
rtmp_control all;
}
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
浏览器输入http://localhost 出现 Welcome to nginx!就完成了。
python实现ffmpge的rtsp和rtmp推流拉流
# 本地摄像头推流
import queue
import threading
import cv2
import subprocess as sp
# 自行设置,url为推送的服务器地址
rtmpUrl = "rtmp://localhost:1935/live/test"
cap = cv2.VideoCapture(0)
fps = int(cap.get(cv2.CAP_PROP_FPS))
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
# ffmpeg command
command = ['ffmpeg',
'-y',
'-f', 'rawvideo',
'-vcodec', 'rawvideo',
'-pix_fmt', 'bgr24',
'-s', "{}x{}".format(width, height),
'-r', str(fps),
'-i', '-',
'-c:v', 'libx264',
'-pix_fmt', 'yuv420p',
'-preset', 'ultrafast',
'-f', 'flv',
rtmpUrl]
# 设置管道
p = sp.Popen(command, stdin=sp.PIPE)
while True:
ret, frame = cap.read()
p.stdin.write(frame.tostring())
如果报错找不到文件就
ffmpeg写成绝对路径
推送的视频延迟大概5秒
拉视频流:ffplay rtsp://127.0.0.1:554/stream
该文介绍了如何下载并配置FFmpeg,设置环境变量,以及使用nginx和nginx-rtmp-module搭建RTMP服务器。通过Python实现从本地摄像头推流到服务器,并展示了拉流命令。还提到了推流时可能出现的延迟问题。
7086

被折叠的 条评论
为什么被折叠?



