Skip to content

Instantly share code, notes, and snippets.

@ZiTAL
Created May 11, 2024 18:58
Show Gist options
  • Save ZiTAL/b672368f92126cec4756f22a140ca628 to your computer and use it in GitHub Desktop.
Save ZiTAL/b672368f92126cec4756f22a140ca628 to your computer and use it in GitHub Desktop.
nginx rtmp + ffmpeg
# /etc/nginx/modules-available/rtmp.conf
rtmp {
server {
listen 1935;
chunk_size 4096;
allow publish 127.0.0.1;
deny publish all;
application live {
live on;
record off;
hls on;
hls_path /home/projects/rtmp/hls;
hls_fragment 3;
hls_playlist_length 60;
dash on;
dash_path /home/projects/rtmp/dash;
}
}
}
# /etc/nginx/sites-available/rtmp.conf
# include mime.types;
# default_type application/octet-stream;
# sendfile off;
# tcp_nopush on;
# aio off;
# directio 512;
# keepalive_timeout 65;
server {
include /etc/nginx/vhost.conf.d/*.conf;
server_name rtmp.zital.eus rtmp.opi5;
root /home/projects/rtmp;
# This URL provides RTMP statistics in XML
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet /home/projects/rtmp/stat.xsl;
}
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /home/projects/rtmp/;
add_header Cache-Control no-cache;
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
}
location /dash {
types {
application/dash+xml mpd;
video/mp4 mp4;
}
root /home/projects/rtmp/;
add_header Cache-Control no-cache;
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
}
error_log /var/log/nginx/rtmp-error.log;
access_log /var/log/nginx/rtmp-access.log;
}
@ZiTAL
Copy link
Author

ZiTAL commented May 11, 2024

ffmpeg -re -i "/home/projects/twitch-ffmpeg/multimedia/db/001.mp4" -c:v copy -c:a copy -f flv rtmp://localhost/live/stream

@ZiTAL
Copy link
Author

ZiTAL commented May 11, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment