How to Build an Nginx RTMP Server on Windows and Stream Local Video with FFmpeg
This guide walks through the fundamentals of the RTMP protocol, introduces FFmpeg, shows how to download and configure Nginx‑RTMP on Windows, create the necessary directories, start the server, craft a batch script to push a local video stream, and verify playback with VLC.
RTMP Overview
RTMP (Real‑Time Messaging Protocol) is a streaming protocol originally owned by Adobe. It typically transports FLV or F4V streams over a single TCP channel, carrying both commands and media data.
FFmpeg Overview
FFmpeg is an open‑source suite (LGPL/GPL) that can record, convert, and stream audio‑video. It provides a complete solution for capturing, transcoding, and streaming media.
Download Tools
Download FFmpeg from http://www.ffmpeg.org/ and the Windows build of Nginx‑RTMP from https://github.com/zhongwcool/nginx-rtmp-win64. After extracting, keep the three executable files in the bin directory.
Configure Nginx‑RTMP
The provided nginx.conf already contains an rtmp block. The key directives are: listen 1935; – the port Nginx listens on for RTMP. application live { live on; } – the publishing endpoint.
application hls { live on; hls on; hls_path temp/hls; hls_fragment 8s; }– enables HLS output, stores segments in temp/hls, each fragment lasting 8 seconds.
Full configuration snippet:
#user nobody;
worker_processes 1;
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;
sendfile on;
keepalive_timeout 65;
server {
listen 110;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}After editing, create the directory temp/hls inside the Nginx folder.
Start Nginx
Double‑click nginx.exe. Verify the process in Task Manager or inspect the logs folder for errors.
Prepare FFmpeg and Video
Place the target video (e.g., D:\test\1.mp4) and ffmpeg.exe in the same folder.
Create Streaming Script
Create start.bat with the following command:
ffmpeg.exe -re -i D:\test\1.mp4 -vcodec libx264 -acodec aac -f flv rtmp://127.0.0.1:1935/live/badaoThe command streams the local file to the RTMP URL rtmp://127.0.0.1:1935/live/badao, where 1935 matches the Nginx listen port, live is the application name, and badao is a custom stream key.
Run the batch file by double‑clicking it; FFmpeg will start pushing the video to Nginx.
Test with VLC
Download VLC from https://www.videolan.org/vlc/, open “Media → Open Network Stream”, and enter the same RTMP URL ( rtmp://127.0.0.1:1935/live/badao). VLC should display the streamed video, confirming that the Nginx‑RTMP server and FFmpeg pipeline are working correctly.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
The Dominant Programmer
Resources and tutorials for programmers' advanced learning journey. Advanced tracks in Java, Python, and C#. Blog: https://blog.csdn.net/badao_liumang_qizhi
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
