fotografia:camaras:rtmp_proxy
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| fotografia:camaras:rtmp_proxy [2024/11/05 10:18] – created jose | fotografia:camaras:rtmp_proxy [2024/11/10 15:04] (current) – [Configurar proxy RTMP a proxy RTSP] jose | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | Levanto un servidor | + | ====== Servidor |
| - | | + | Fichero nginx.conf |
| + | <code> | ||
| + | daemon off; | ||
| + | error_log /dev/stdout info; | ||
| + | |||
| + | events { | ||
| + | worker_connections 1024; | ||
| + | } | ||
| + | |||
| + | rtmp { | ||
| + | server { | ||
| + | listen 1935; | ||
| + | chunk_size 4000; | ||
| + | |||
| + | application stream { | ||
| + | live on; | ||
| + | |||
| + | 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, | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | http { | ||
| + | root / | ||
| + | sendfile off; | ||
| + | tcp_nopush on; | ||
| + | server_tokens off; | ||
| + | access_log /dev/stdout combined; | ||
| + | |||
| + | # 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 { | ||
| + | listen 80; | ||
| + | |||
| + | # 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 { | ||
| + | types { | ||
| + | application/ | ||
| + | video/mp2t ts; | ||
| + | } | ||
| + | root /opt/data; | ||
| + | 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; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | </ | ||
| + | |||
| + | 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) | ||
| + | </ | ||
| + | |||
| + | Y ahora emitimos el vídeo al servidor 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:// | ||
| + | |||
| + | Y creamos el proxy: | ||
| + | ffmpeg -i rtmp:// | ||
| + | Ahora podemos configurar OBS en la dirección: | ||
| + | rtsp:// | ||
fotografia/camaras/rtmp_proxy.1730801883.txt.gz · Last modified: by jose
