I want to treanscode RTSP to RTMP to HLS using ffmpeg and nginx_rtmp_module.
But HLS files(.m3u8, .ts) do not created.
I'm testing on Docker(amazonlinux image).
I can access and play rtmp://localhost:1935/live/camera1 by VLC Player, but can not access http://localhost:8088/live/camera1.m3u8.
docker run command:
docker run -it -p 8088:8088 -p 1935:1935 -v $(pwd):/tmp/share amazonlinux bash
nginx.conf:
user root;
worker_processes 1;
error_log /var/log/nginx/error.log debug;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1935;
access_log /var/log/nginx/rtmp_access.log;
application live {
live on;
hls on;
hls_path /usr/local/nginx/html/hls;
hls_fragment 5s;
hls_type live;
hls_nested on;
}
}
}
http {
server {
listen 8088;
location / {
root /usr/local/nginx/html/;
}
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
text/html html;
}
alias /usr/local/nginx/html/hls;
}
}
}
ffmpeg command: (using sample video rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov)
nohup /root/ffmpeg_sources/ffmpeg/ffmpeg -i "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov" -f flv -s 320x240 -an "rtmp://localhost:1935/live/camera1" </dev/null &
ffmpeg version:
bash-4.2# /root/ffmpeg_sources/ffmpeg/ffmpeg -version
ffmpeg version N-90214-gdd3f1e3 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-11)
configuration: --prefix=/root/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --extra-libs=-lpthread --extra-libs=-lm --bindir=/root/bin --enable-gpl --enable-libx264 --enable-nonfree
libavutil 56. 8.100 / 56. 8.100
libavcodec 58. 13.102 / 58. 13.102
libavformat 58. 10.100 / 58. 10.100
libavdevice 58. 2.100 / 58. 2.100
libavfilter 7. 12.100 / 7. 12.100
libswscale 5. 0.102 / 5. 0.102
libswresample 3. 0.101 / 3. 0.101
libpostproc 55. 0.100 / 55. 0.100
nginx version: nginx version: nginx/1.13.9
nginx_rtmp_module version: nginx-rtmp-module-1.2.1
and directory permission:
bash-4.2# pwd
/usr/local/nginx/html
bash-4.2# ls -l
total 48
-rw-r--r-- 1 root root 537 Mar 5 07:24 50x.html
drwxrwxrwx 2 root root 4096 Mar 6 04:46 hls
-rw-r--r-- 1 root root 612 Mar 5 07:24 index.html
-rw------- 1 root root 36262 Mar 6 04:46 nohup.out
Help...
I Solved myself.
I found Incoming stream must be in H264/AAC. written in README.
So, I add -vcodec libx264 into the ffmpeg command:
nohup /root/ffmpeg_sources/ffmpeg/ffmpeg -stream_loop -1 -i "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov" -vcodec libx264 -f flv -s 320x240 -an "rtmp://localhost:1935/live/camera1" </dev/null &
Related
docker run --rm --net=host -v $PWD/default.conf:/etc/nginx/conf.d/default.conf nginx
2019/05/12 17:02:49 [emerg] 1#1: host not found in upstream "tickethub.service.consul" in /etc/nginx/conf.d/default.conf:10
nginx: [emerg] host not found in upstream "tickethub.service.consul" in /etc/nginx/conf.d/default.conf:10
While dig shows the DNS record correctly:
dig #127.0.0.1 -p 8600 tickethub.service.consul
; <<>> DiG 9.12.3-P1 <<>> #127.0.0.1 -p 8600 tickethub.service.consul
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57394
;; flags: qr aa rd; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 4
;; WARNING: recursion requested but not available
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;tickethub.service.consul. IN A
;; ANSWER SECTION:
tickethub.service.consul. 0 IN A 172.23.0.6
tickethub.service.consul. 0 IN A 172.23.0.5
tickethub.service.consul. 0 IN A 172.23.0.7
;; ADDITIONAL SECTION:
tickethub.service.consul. 0 IN TXT "consul-network-segment="
tickethub.service.consul. 0 IN TXT "consul-network-segment="
tickethub.service.consul. 0 IN TXT "consul-network-segment="
;; Query time: 0 msec
;; SERVER: 127.0.0.1#8600(127.0.0.1)
;; WHEN: Sun May 12 16:58:54 GMT 2019
;; MSG SIZE rcvd: 209
And my nginx config:
server {
listen 80;
server_name localhost;
location / {
resolver 127.0.0.1:8600;
proxy_pass http://tickethub.service.consul;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
What may be the issue?
This worked when I explicitly set the DNS on the docker container to 127.0.0.1 which means Nginx is probably trying to resolve it WITHOUT using the resolver specified argh...
I think I also had to change the DNS port to 53 instead of the explicit 8600
Or something...
Probably a bunch of nginx bugs...
mic drop
It worked when I set the proxy_pass using a variable:
location / {
resolver consul;
set $endpoint tickethub.service.consul;
proxy_pass http://$endpoint/;
}
I have a tested code I did in a "bash" file. It works perfect on shell. I change only params to get it to work with nginx rtmp module, but ffmpeg says always and understandable error. This is the code:
exec_push ffmpeg -re -y -i rtmp://localhost:1935/live/$name \
-c:v libx264 -c:a aac \
-g 24 -keyint_min 24 -preset veryfast -tune zerolatency -movflags +faststart -vsync passthrough \
-filter_complex '[0:v]format=pix_fmts=yuv420p,split=3[in1][in2][in3];[in1]scale=320:-2[320x];[in2]scale=640:-2[HQ640x];[in3]scale=1280:-2[HD1280x];[0:a]aresample=44100[audio]' \
-map '[320x]' -profile:v baseline -level 3.0 -crf 31 -maxrate 170k -bufsize 170k -f mp4 rtmp://localhost:1935/rtmp_hls/$name_320x \
-map '[HQ640x]' -profile:v baseline -level 3.1 -crf 25 -maxrate 1000k -bufsize 1000k -f mp4 rtmp://localhost:1935/rtmp_hls/$name_HQ640x \
-map '[HD1280x]' -profile:v main -level 3.1 -crf 19 -maxrate 4000k -bufsize 4000k -f mp4 rtmp://localhost:1935/rtmp_hls/$name_HD1280x \
-map '[audio]' -b 128k -f mp4 rtmp://localhost:1935/rtmp_hls/$name_audio 2>>/var/www/html/ffmpeg-live-output-$name.log;
And this is the error launched by mmpeg
ffmpeg version 3.2.4-1~bpo8+1 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.9.2 (Debian 4.9.2-10)
configuration: --prefix=/usr --extra-version='1~bpo8+1' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --disable-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 34.101 / 55. 34.101
libavcodec 57. 64.101 / 57. 64.101
libavformat 57. 56.101 / 57. 56.101
libavdevice 57. 1.100 / 57. 1.100
libavfilter 6. 65.100 / 6. 65.100
libavresample 3. 1. 0 / 3. 1. 0
libswscale 4. 2.100 / 4. 2.100
libswresample 2. 3.100 / 2. 3.100
libpostproc 54. 1.100 / 54. 1.100
[flv # 0x55e430547740] video stream discovered after head already parsed
[flv # 0x55e430547740] audio stream discovered after head already parsed
Input #0, flv, from 'rtmp://localhost:1935/live/directo':
Metadata:
Server : NGINX RTMP (github.com/sergey-dryabzhinsky/nginx-rtmp-module)
displayWidth : 1280
displayHeight : 720
fps : 24
profile :
level :
Duration: 00:00:00.00, start: 26.023000, bitrate: N/A
Stream #0:0: Video: h264 (Constrained Baseline), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 24.42 fps, 24 tbr, 1k tbn, 48 tbc
Stream #0:1: Audio: aac (LC), 44100 Hz, mono, fltp
[NULL # 0x55e4305e0b40] Unable to find a suitable output format for '
'
: Invalid argument
Does anyone could help me?
Thank you
There's no need for line breaks \. Nginx usess regular expressions to parse the configuration:
exec_push ffmpeg line 1
line 2
...
line n;
I am trying to stream a video using nginx-rtmp with rtmp protocol.
I created a index.html and embedded on it JWPlayer with the rtmp url.
On localhost, I can play the video from the browser but from another computer in same local network when I tried same thing ( open the index.html in the browser the url is http://172.16.40.162:8080 ) I get an error message.
But when I try with vlc (the rtmp url : rtmp://172.16.40.162/vod/test) it worked.
Here the code of index.html
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>VoD Example</title>
<script src="http://jwpsrv.com/library/s7iNvOAyEeSMdQ4AfQhyIQ.js"></script>
</head>
<body>
<div id='videotest'></div>
<script type='text/javascript'>
jwplayer('videotest').setup({
file: 'rtmp://localhost/vod/test',
width: '50%',
aspectratio: '16:9'
});
</script>
</body>
</html>
the nginx.conf
#user nobody;
worker_processes 1;
error_log logs/error.log debug;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8080;
server_name localhost;
# rtmp stat
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
# you can move stat.xsl to a different location
root /usr/local/nginx/html;
}
# rtmp control
location /control {
rtmp_control all;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
rtmp {
server {
listen 1935;
notify_method get;
chunk_size 8192;
application vod {
allow play all;
wait_video on;
play /var/www/Videos;
push rtmp://localhost/vod/test;
}
}
}
I get these messages on :
acces.log
172.16.40.148 - - [16/Apr/2015:13:08:33 +0100] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0"
172.16.40.148 [16/Apr/2015:13:19:29 +0100] PLAY "vod" "test" "" - 382 3660906 "" "LNX 9,0,124,2" (1m 58s)
127.0.0.1 [16/Apr/2015:13:51:47 +0100] PLAY "vod" "test" "" - 483 3669724 "http://172.16.40.162:8080/" "LNX 11,2,202,457" (1m 50s)
error.log
2015/04/16 13:07:06 [notice] 3771#0: using the "epoll" event method
2015/04/16 13:07:06 [notice] 3771#0: nginx/1.5.0
2015/04/16 13:07:06 [notice] 3771#0: built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
2015/04/16 13:07:06 [notice] 3771#0: OS: Linux 2.6.32-504.12.2.el6.x86_64
2015/04/16 13:07:06 [notice] 3771#0: getrlimit(RLIMIT_NOFILE): 1024:4096
2015/04/16 13:07:06 [notice] 3772#0: start worker processes
2015/04/16 13:07:06 [notice] 3772#0: start worker process 3773
2015/04/16 13:08:41 [info] 3773#0: *3 client closed connection while waiting for request, client: 172.16.40.148, server: 0.0.0.0:8080
Information about the video I use (I executed ffmpeg -i test.flv)
Input #0, flv, from 'test.flv':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42isom
encoder : Lavf56.30.100
Duration: 00:01:50.03, start: 0.060000, bitrate: 270 kb/s
Stream #0:0: Video: h264 (High), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 30.30 fps, 30 tbr, 1k tbn, 60 tbc
Stream #0:1: Audio: mp3, 22050 Hz, stereo, s16p, 64 kb/s
In index.html replace file: 'rtmp://localhost/vod/test' with file: 'rtmp://172.16.40.162/vod/test'.
The JWPlayer Flash will request that URL from the client machine. Using localhost will obviously not work since it looks for the stream on the same computer.
Configuration of Nginx:
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:3030;
}
uWSGI FasterRouter
uwsgi --fastrouter 127.0.0.1:3030 --fastrouter-subscription-server 127.0.0.1:3131 -M
uWSGI web-app instance
uwsgi -M --subscribe-to 127.0.0.1:3131:/ --file server.py --http :8080
then HTTP GET [server ip]:80/ no response
HTTP GET [server ip]:8080/ got response
Configuration of Nginx:
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:3030;
}
uwsgi -M --file server.py -s 127.0.0.1:3030
then HTTP GET [server ip]:80/ Got response
Do as follows. Worked. Thanks roberto for help.
Configuration of Nginx:
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:3030;
}
uWSGI FasterRouter
uwsgi --fastrouter 127.0.0.1:3030 --fastrouter-subscription-server 127.0.0.1:3131 -M
uWSGI web-app instance
uwsgi -M --subscribe-to 127.0.0.1:3131:[server_ip] --file server.py -s 127.0.0.1:3232
Console output
[uwsgi-subscription for pid 18957] new pool: [server_ip] (hash key: 22902)
[uwsgi-subscription for pid 18957] [server_ip] => new node: 127.0.0.1:3232
then HTTP GET [server ip]:80/ GOT response
I am trying to get nginx to server some static files. I put in what I believe should be the proper directive to alias the url, but nginx is refusing to server the page. My server.conf is as follows:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm index.php;
# Make site accessible from server.fqdn.suffix
server_name server.fqdn.suffix;
location /static/ {
autoindex on;
alias /usr/share/nginx/html/poindexter/inspire/static/;
}
# Include the basic h5bp config set
include /etc/nginx/h5bp/basic.conf;
}
I assumed that this would redirect to the /usr/share/nginx/html/poindexter/inspire/static/ directory. And for the autoindex it seems to work. But when you click on a file it generates a 404 error. I took an strace and sure enough, it is not honoring the alias.
[pid 2542] <... epoll_wait resumed> {{EPOLLIN, {u32=1822502928, u64=139901792235536}}}, 512, 4294967295) = 1
[pid 2542] accept4(10, {sa_family=AF_INET, sin_port=htons(37845), sin_addr=inet_addr("198.55.232.86")}, [16], SOCK_NONBLOCK) = 24
[pid 2542] epoll_ctl(21, EPOLL_CTL_ADD, 24, {EPOLLIN|EPOLLET, {u32=1822503697, u64=139901792236305}}) = 0
[pid 2542] epoll_wait(21, {{EPOLLIN, {u32=1822503697, u64=139901792236305}}}, 512, 10000) = 1
[pid 2542] recvfrom(24, "GET /static/css/bootstrap.min.cs"..., 1024, 0, NULL, NULL) = 772
[pid 2542] open("/usr/share/nginx/html/static/css/bootstrap.min.css", O_RDONLY|O_NONBLOCK) = -1 ENOENT (No such file or directory)
[pid 2542] write(8, "2014/03/05 21:59:23 [error] 2542"..., 328) = 328
[pid 2542] writev(24, [{"HTTP/1.1 404 Not Found\r\nServer: "..., 172}, {"<html>\r\n<head><title>404 Not Fou"..., 116}, {"<hr><center>nginx</center>\r\n</bo"..., 46}], 3) = 334
[pid 2542] setsockopt(24, SOL_TCP, TCP_NODELAY, [1], 4) = 0
[pid 2542] recvfrom(24, 0x14e9240, 1024, 0, 0, 0) = -1 EAGAIN (Resource temporarily unavailable
I would really appreciate any help I could get. I am very stuck.
I see several way to fix this.
1
Just add symlink from /usr/share/nginx/html/static/ to /usr/share/nginx/html/poindexter/inspire/static/ and remove alias directive. It something like aliasing on file system level.
location /static/ {
autoindex on;
}
2
Remove location ~* \.(?:css|js)$ { block.
3
Use rewrite (this solution make use the fact you static directory in inside your root)
location ^~ /static/ {
autoindex on;
rewrite ^(.+)$ /poindexter/inspire$1;
}