日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

Windows上搭建Nginx RTMP服务器并使用FFmpeg实现本地视频推流

發布時間:2025/3/19 windows 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Windows上搭建Nginx RTMP服务器并使用FFmpeg实现本地视频推流 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

場景

RTMP

RTMP協議
(1)是流媒體協議。
(2)RTMP協議是 Adobe 的私有協議,未完全公開。
(3)RTMP協議一般傳輸的是 flv,f4v 格式流。
(4)RTMP一般在 TCP 1個通道上傳輸命令和數據。

FFmpeg

FFmpeg是一套可以用來記錄、轉換數字音頻、視頻,并能將其轉化為流的開源計算機程序。

采用LGPL或GPL許可證。它提供了錄制、轉換以及流化音視頻的完整解決方案。

官方ffmpeg下載地址:FFmpeg

下載之后找到bin下的三個exe文件,只需要這幾個即可。

注:

博客:
BADAO_LIUMANG_QIZHI的博客_霸道流氓氣質_CSDN博客
關注公眾號
霸道的程序猿
獲取編程相關電子書、教程推送與免費下載。

實現

1、下載nginx-rtmp-win64并修改配置文件

github地址:GitHub - zhongwcool/nginx-rtmp-win64

下載之后其配置文件已經添加了rtmp的配置

rtmp {server {listen 1935;application live {live on;}application hls {live on;hls on;?hls_path temp/hls;?hls_fragment 8s;?}} }

這里的配置的意思是

listen 代表監聽端口

application live 跟的是推流請求路徑

live on 代表開啟實時

hls on 代表開啟hls

hls_path 代表rtmp推流請求路徑,文件存放路徑

hls_fragment 8s 代表每個TS文件包含5秒的視頻內容

完整配置

#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;application live {live on;}application hls {live on;hls on; hls_path temp/hls; hls_fragment 8s; }} }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 110;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;# }#}}

所以這里需要在nginx目錄下新建temp/hls目錄

2、啟動nginx

然后雙擊nginx.exe,啟動完成后去任務管理器中查看是否啟動成功,如果沒有,則去看logs下的錯誤日志。

3、下載ffmpeg

按照上面下載地址下載ffmpeg,并將視頻和ffmpeg.exe放在同一目錄下

4、編寫啟動腳本實現推流

新建start.bat

ffmpeg.exe -re -i D:\test\1.mp4 -vcodec libx264 -acodec aac -f flv rtmp://127.0.0.1:1935/live/badao

其中D:\test\1.mp4 就是本地視頻的位置

后面1935是上面nginx中配置的端口

live是nginx中配置推流的路徑

badao是這里自定義的推流地址

雙擊bat啟動

5、引流測試

下載VLC

Official download of VLC media player, the best Open Source player - VideoLAN

VLC 是一款自由、開源的跨平臺多媒體播放器及框架,可播放大多數多媒體文件,以及 DVD、音頻 CD、VCD 及各類流媒體協議。

下載之后安裝啟動-文件-打開網絡串流

輸入地址為

rtmp://127.0.0.1:1935/live/badao

效果為

?

總結

以上是生活随笔為你收集整理的Windows上搭建Nginx RTMP服务器并使用FFmpeg实现本地视频推流的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。