fotografia:camaras:rtmp_proxy
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
fotografia:camaras:rtmp_proxy [2024/11/05 10:25] – jose | fotografia:camaras:rtmp_proxy [2024/11/10 15:04] (current) – [Configurar proxy RTMP a proxy RTSP] jose | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | 1. Creamos un servidor | + | ====== Servidor |
Fichero nginx.conf | Fichero nginx.conf | ||
< | < | ||
- | worker_processes | + | daemon off; |
+ | |||
+ | error_log /dev/stdout info; | ||
events { | events { | ||
- | worker_connections | + | worker_connections 1024; |
} | } | ||
rtmp { | rtmp { | ||
server { | server { | ||
- | listen 1935; # Puerto para RTMP | + | listen 1935; |
- | chunk_size | + | chunk_size |
- | application | + | application |
live on; | live on; | ||
- | record off; | + | |
+ | exec ffmpeg -i rtmp:// | ||
+ | -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 2500k -f flv -g 30 -r 30 -s 1280x720 -preset superfast -profile:v baseline rtmp:// | ||
+ | -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 1000k -f flv -g 30 -r 30 -s 854x480 -preset superfast -profile:v baseline rtmp:// | ||
+ | -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 750k -f flv -g 30 -r 30 -s 640x360 -preset superfast -profile:v baseline rtmp:// | ||
+ | -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 400k -f flv -g 30 -r 30 -s 426x240 -preset superfast -profile:v baseline rtmp:// | ||
+ | -c:a libfdk_aac -b:a 64k -c:v libx264 -b:v 200k -f flv -g 15 -r 15 -s 426x240 -preset superfast -profile:v baseline rtmp:// | ||
+ | } | ||
+ | |||
+ | application hls { | ||
+ | live on; | ||
+ | hls on; | ||
+ | hls_fragment_naming system; | ||
+ | hls_fragment 5; | ||
+ | hls_playlist_length 10; | ||
+ | hls_path / | ||
+ | hls_nested on; | ||
+ | |||
+ | hls_variant _720p2628kbs BANDWIDTH=2628000, | ||
+ | hls_variant _480p1128kbs BANDWIDTH=1128000, | ||
+ | hls_variant _360p878kbs BANDWIDTH=878000, | ||
+ | hls_variant _240p528kbs BANDWIDTH=528000, | ||
+ | hls_variant _240p264kbs BANDWIDTH=264000, | ||
} | } | ||
} | } | ||
Line 21: | Line 45: | ||
http { | http { | ||
+ | root / | ||
sendfile off; | sendfile off; | ||
tcp_nopush on; | tcp_nopush on; | ||
- | | + | |
- | | + | |
+ | |||
+ | # Uncomment these lines to enable SSL. | ||
+ | # ssl_protocols TLSv1.2 TLSv1.3; | ||
+ | # ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256: | ||
+ | # ssl_prefer_server_ciphers off; | ||
+ | # ssl_session_cache shared: | ||
+ | # ssl_session_timeout 1d; | ||
server { | server { | ||
- | listen | + | listen |
- | location / { | + | |
- | | + | # Uncomment these lines to enable SSL. |
+ | # Update the ssl paths with your own certificate and private key. | ||
+ | |||
+ | # listen 443 ssl; | ||
+ | # ssl_certificate | ||
+ | # ssl_certificate_key / | ||
+ | |||
+ | location /hls { | ||
+ | | ||
+ | application/ | ||
+ | video/mp2t ts; | ||
+ | } | ||
+ | root / | ||
+ | add_header Cache-Control no-cache; | ||
+ | add_header Access-Control-Allow-Origin *; | ||
+ | } | ||
+ | |||
+ | location /live { | ||
+ | alias / | ||
+ | types { | ||
+ | application/ | ||
+ | video/mp2t ts; | ||
+ | } | ||
+ | add_header Cache-Control no-cache; | ||
+ | add_header Access-Control-Allow-Origin *; | ||
+ | } | ||
+ | |||
+ | location /stat { | ||
+ | rtmp_stat all; | ||
+ | rtmp_stat_stylesheet stat.xsl; | ||
+ | } | ||
+ | |||
+ | location /stat.xsl { | ||
+ | root / | ||
+ | } | ||
+ | |||
+ | location / | ||
+ | default_type text/xml; | ||
+ | expires 24h; | ||
} | } | ||
} | } | ||
Line 36: | Line 107: | ||
</ | </ | ||
+ | Ejecutamos docker | ||
+ | < | ||
+ | docker run -d \ | ||
+ | -p 1935:1935 \ | ||
+ | -p 8080:80 \ | ||
+ | -v ~/ | ||
+ | --name rtmp-server \ | ||
+ | alfg/ | ||
+ | </ | ||
+ | ====== Enviar vídeo a RTMP ====== | ||
+ | ffmpeg -re -i video.mp4 -c:v libx264 -preset veryfast -b:v 3000k -maxrate 3000k -bufsize 6000k -c:a aac -ar 44100 -b:a 128k -f flv rtmp:// | ||
+ | |||
+ | ====== Ver vídeo en servidor ====== | ||
+ | http:// | ||
+ | En el directorio / | ||
+ | docker exec -it rtmp-server /bin/sh | ||
+ | / # ls / | ||
+ | test.m3u8 | ||
+ | |||
+ | Podemos crear un player en el servidor, en / | ||
+ | < | ||
+ | < | ||
+ | <html lang=" | ||
+ | < | ||
+ | <meta charset=" | ||
+ | <meta name=" | ||
+ | < | ||
+ | <script src=" | ||
+ | < | ||
+ | body { | ||
+ | display: flex; | ||
+ | align-items: | ||
+ | justify-content: | ||
+ | height: 100vh; | ||
+ | margin: 0; | ||
+ | background-color: | ||
+ | } | ||
+ | video { | ||
+ | width: 80%; | ||
+ | max-width: 800px; | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | <video id=" | ||
+ | < | ||
+ | const video = document.getElementById(' | ||
+ | const videoSrc = ' | ||
+ | |||
+ | if (Hls.isSupported()) { | ||
+ | const hls = new Hls(); | ||
+ | hls.loadSource(videoSrc); | ||
+ | hls.attachMedia(video); | ||
+ | hls.on(Hls.Events.MANIFEST_PARSED, | ||
+ | video.play(); | ||
+ | }); | ||
+ | } else if (video.canPlayType(' | ||
+ | video.src = videoSrc; | ||
+ | video.addEventListener(' | ||
+ | video.play(); | ||
+ | }); | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | ====== Configurar proxy RTMP a proxy RTSP ====== | ||
+ | Con el docker de rtmp no acaba de funcionar. | ||
+ | |||
+ | Pero con este software si. Paramos el docker y descargamos este software:\\ | ||
+ | https:// | ||
+ | |||
+ | Lo descomprimimos y lo ejecutamos: | ||
+ | ./ | ||
+ | < | ||
+ | 2024/11/10 15:58:59 INF MediaMTX v1.9.3 | ||
+ | 2024/11/10 15:58:59 INF configuration loaded from / | ||
+ | 2024/11/10 15:58:59 INF [RTSP] listener opened on :8554 (TCP), :8000 (UDP/RTP), :8001 (UDP/RTCP) | ||
+ | 2024/11/10 15:58:59 INF [RTMP] listener opened on :1935 | ||
+ | 2024/11/10 15:58:59 INF [HLS] listener opened on :8888 | ||
+ | 2024/11/10 15:58:59 INF [WebRTC] listener opened on :8889 (HTTP), :8189 (ICE/UDP) | ||
+ | 2024/11/10 15:58:59 INF [SRT] listener opened on :8890 (UDP) | ||
+ | </ | ||
- | Levanto un servidor | + | Y ahora emitimos el vídeo al servidor |
- | ffmpeg -i rtmp://< | + | ffmpeg |
+ | Y creamos el proxy: | ||
+ | ffmpeg -i rtmp:// | ||
+ | Ahora podemos configurar OBS en la dirección: | ||
+ | rtsp:// | ||
fotografia/camaras/rtmp_proxy.1730802334.txt.gz · Last modified: 2024/11/05 10:25 by jose