Trying to use nginx, rtmp & ffmpeg
Added by Jason A over 3 years ago
Hello all,
I am trying to pull a stream and relay it with rtmp. I am running ffmpeg like this
/usr/local/bin/ffmpeg -loglevel fatal -f mpegts -i http://user:password@myurl:9981/stream/channelid/xxxxxxxxxx?profile=mpegts \-c:v libx264 -crf 21 -preset veryfast \-c:a aac -b:a 128k -ac 2 \-f hls -f flv rtmp://localhost:1935/hls/
Checking the tvheadend logs, I see that ffmpeg connects and is doing its job fine
tvheadend[12066]: subscription: 00DD: "HTTP" subscribing on channel "TalkingPictures TV", weight: 100, adapter: "Sony CXD2880 #0 : DVB-T #0", network: "DVB-T Network", mux: "529.833MHz", service: "TalkingPictures TV", profile="mpegts", hostname="x.x.x.x", username="streamer", client="Lavf/59.2.101"
But about 20 seconds later it disconnects
tvheadend[12066]: pass: Live stream: Write failed -- Resource temporarily unavailable
Jun 07 11:32:50 UKLDN-DP-Network tvheadend[12066]: webui: Stop streaming /stream/channelid/1xxxxxxxxx?profile=pass, muxer reported errors
Jun 07 11:32:50 UKLDN-DP-Network tvheadend[12066]: subscription: 00DE: "HTTP" unsubscribing from "TalkingPictures TV", hostname="x.x.x.x", username="streamer", client="Lavf/59.2.101"
TVHeadend is running on a Raspberry Pi 3 with the tuner HAT. I have checked the processes and it does not seem to be under any sort of stress. It's also strange that it is using a "pass" profile and not mpegts that I specifically stated in the ffmpeg command.
Has anyone had any successdoing something similar?
Thanks
Jason
Replies (10)
RE: Trying to use nginx, rtmp & ffmpeg - Added by saen acro over 3 years ago
Read more here
https://tvheadend.org/boards/4/topics/32005
adapt to you need
RE: Trying to use nginx, rtmp & ffmpeg - Added by Jason A over 3 years ago
Thanks for the link.
I tried to adapt the ffmpeg statement for my needs but I am still getting disconnects with the "Resource temporarily unavailable".
RE: Trying to use nginx, rtmp & ffmpeg - Added by saen acro over 3 years ago
What happens if watch stream in paralel?
RE: Trying to use nginx, rtmp & ffmpeg - Added by Jason A over 3 years ago
saen acro wrote:
What happens if watch stream in paralel?
I am pretty sure that this does not answer your question but streaming works fine with any client...it's just ffmpeg that is causing an issue.
RE: Trying to use nginx, rtmp & ffmpeg - Added by saen acro over 3 years ago
Run FFMpeg in terminal with more logs.
Shere you command line to test.
RE: Trying to use nginx, rtmp & ffmpeg - Added by Jason A over 3 years ago
saen acro wrote:
Run FFMpeg in terminal with more logs.
Shere you command line to test.
/usr/local/bin/ffmpeg -reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_delay_max 2 -y -nostdin -hide_banner -loglevel trace -i http://user:myurl:9981/stream/channelid/1654617068?profile=mpegts -vcodec copy -acodec copy -scodec copy -g 60 -fflags +genpts -user_agent HLS_delayer -metadata -f hls -f flv rtmp://localhost:1935/hls/
Gives
Splitting the commandline.
Reading option '-reconnect' ... matched as AVOption 'reconnect' with argument '1'.
Reading option '-reconnect_at_eof' ... matched as AVOption 'reconnect_at_eof' with argument '1'.
Reading option '-reconnect_streamed' ... matched as AVOption 'reconnect_streamed' with argument '1'.
Reading option '-reconnect_delay_max' ... matched as AVOption 'reconnect_delay_max' with argument '2'.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option '-nostdin' ... matched as option 'stdin' (enable or disable interaction on standard input) with argument 0.
Reading option '-hide_banner' ... matched as option 'hide_banner' (do not show program banner) with argument '1'.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'trace'.
Reading option '-i' ... matched as input url with argument 'http://user:pass@myurl:9981/stream/channelid/1654617068?profile=mpegts'.
Reading option '-vcodec' ... matched as option 'vcodec' (force video codec ('copy' to copy stream)) with argument 'copy'.
Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'copy'.
Reading option '-scodec' ... matched as option 'scodec' (force subtitle codec ('copy' to copy stream)) with argument 'copy'.
Reading option '-g' ... matched as AVOption 'g' with argument '60'.
Reading option '-fflags' ... matched as AVOption 'fflags' with argument '+genpts'.
Reading option '-user_agent' ... matched as AVOption 'user_agent' with argument 'HLS_delayer'.
Reading option '-metadata' ... matched as option 'metadata' (add metadata) with argument '-f'.
Reading option 'hls' ... matched as output url.
Reading option '-f' ... matched as option 'f' (force format) with argument 'flv'.
Reading option 'rtmp://localhost:1935/hls/' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option y (overwrite output files) with argument 1.
Applying option nostdin (enable or disable interaction on standard input) with argument 0.
Applying option hide_banner (do not show program banner) with argument 1.
Applying option loglevel (set logging level) with argument trace.
Successfully parsed a group of options.
Parsing a group of options: input url http://user:pass@myurl:9981/stream/channelid/1654617068?profile=mpegts.
Successfully parsed a group of options.
Opening an input file: http://user:pass@myurl:9981/stream/channelid/1654617068?profile=mpegts.
[NULL @ 0x5582c904edc0] Opening 'http://user:pass1@myurl:9981/stream/channelid/1654617068?profile=mpegts' for reading
[http @ 0x5582c904f680] Setting default whitelist 'http,https,tls,rtp,tcp,udp,crypto,httpproxy,data'
[tcp @ 0x5582c9052640] Original list of addresses:
[tcp @ 0x5582c9052640] Address x.x.x.x port 9981
[tcp @ 0x5582c9052640] Interleaved list of addresses:
[tcp @ 0x5582c9052640] Address x.x.x.x port 9981
[tcp @ 0x5582c9052640] Starting connection attempt to x.x.x.x port 9981
[tcp @ 0x5582c9052640] Successfully connected to x.x.x.x port 9981
[http @ 0x5582c904f680] request: GET /stream/channelid/1654617068?profile=mpegts HTTP/1.1
User-Agent: Lavf/59.2.101
Accept: */*
Range: bytes=0-
Connection: close
Host: myurl:9981
Icy-MetaData: 1
[http @ 0x5582c904f680] header='HTTP/1.1 401 Unauthorized'
[http @ 0x5582c904f680] http_code=401
[http @ 0x5582c904f680] header='Server: HTS/tvheadend'
[http @ 0x5582c904f680] header='Cache-Control: no-cache'
[http @ 0x5582c904f680] header='WWW-Authenticate: Digest realm="tvheadend", qop="auth", nonce="562de402fe2f47c5e942a23b41ec791f", opaque="fb2dca4e1741e7afb479c8fdbd85dc87"'
[http @ 0x5582c904f680] header='Connection: Close'
[http @ 0x5582c904f680] header='Content-Type: text/html'
[http @ 0x5582c904f680] header='Content-Length: 432'
[http @ 0x5582c904f680] header=''
[tcp @ 0x5582c9053780] Original list of addresses:
[tcp @ 0x5582c9053780] Address x.x.x.x port 9981
[tcp @ 0x5582c9053780] Interleaved list of addresses:
[tcp @ 0x5582c9053780] Address x.x.x.x port 9981
[tcp @ 0x5582c9053780] Starting connection attempt to x.x.x.x port 9981
[tcp @ 0x5582c9053780] Successfully connected to x.x.x.x port 9981
[http @ 0x5582c904f680] request: GET /stream/channelid/1654617068?profile=mpegts HTTP/1.1
User-Agent: Lavf/59.2.101
Accept: */*
Range: bytes=0-
Connection: close
Host: yurl:9981
Icy-MetaData: 1
Authorization: Digest username="user", realm="tvheadend", nonce="562de402fe2f47c5e942a23b41ec791f", uri="/stream/channelid/1654617068?profile=mpegts", response="d2f5afc22ff01baf9d50e5670c59b8a2", opaque="fb2dca4e1741e7afb479c8fdbd85dc87", qop="auth", cnonce="26c64ff465f45031", nc=00000001
RE: Trying to use nginx, rtmp & ffmpeg - Added by Jason A over 3 years ago
I have some more debug from the TVheadend side, I wonder if the epggrab is stopping the stream?
2021-06-08 20:58:26.150 [ DEBUG]:tbl-pass: pass-eit: -: PID 0012 CC error 1 != 8
2021-06-08 20:58:26.150 [ DEBUG]:tbl-pass: pass-pat: -: PID 0000 CC error 7 != 3
2021-06-08 20:58:26.150 [ DEBUG]:tbl-pass: pass-pmt: -: PID 19C8 CC error 7 != 3
2021-06-08 20:58:26.150 [ DEBUG]:tbl-pass: pass-eit: -: PID 0012 CC error 8 != 5
2021-06-08 20:58:26.150 [ DEBUG]:tbl-pass: pass-pmt: -: PID 19C8 CC error 13 != 8
2021-06-08 20:58:26.150 [ DEBUG]:tbl-pass: pass-pat: -: PID 0000 CC error 14 != 8
2021-06-08 20:58:26.151 [ DEBUG]:tbl-pass: pass-eit: -: PID 0012 CC error 15 != 4
2021-06-08 20:58:26.151 [ DEBUG]:tbl-pass: pass-pat: -: PID 0000 CC error 3 != 15
2021-06-08 20:58:26.151 [ DEBUG]:tbl-pass: pass-pmt: -: PID 19C8 CC error 3 != 15
2021-06-08 20:58:26.151 [ DEBUG]:tbl-pass: pass-sdt: -: PID 0011 CC error 14 != 4
2021-06-08 20:58:27.196 [ DEBUG]:tbl-pass: pass-eit: -: PID 0012 CC error 7 != 6
2021-06-08 20:58:27.196 [ DEBUG]:tbl-pass: pass-pat: -: PID 0000 CC error 9 != 5
2021-06-08 20:58:27.196 [ DEBUG]:tbl-pass: pass-pmt: -: PID 19C8 CC error 9 != 5
2021-06-08 20:58:27.196 [ DEBUG]:tbl-pass: pass-eit: -: PID 0012 CC error 1 != 4
2021-06-08 20:58:27.196 [ DEBUG]:tbl-pass: pass-pat: -: PID 0000 CC error 13 != 10
2021-06-08 20:58:27.196 [ DEBUG]:tbl-pass: pass-pmt: -: PID 19C8 CC error 13 != 10
2021-06-08 20:58:27.197 [ DEBUG]:tbl-pass: pass-eit: -: PID 0012 CC error 11 != 4
2021-06-08 20:58:28.217 [ DEBUG]:tbl-pass: pass-pat: -: PID 0000 CC error 3 != 15
2021-06-08 20:58:28.221 [ INFO]:subscription: 0108: "HTTP" unsubscribing from "BBC ONE HD", hostname="x.x.x.x", username="user", client="Lavf/58.29.100"
2021-06-08 20:58:28.221 [ DEBUG]:mpegts: 545.833MHz in DVB-T Network - close PID 19C8 (6600) [16/0x6a504f40]
2021-06-08 20:58:28.221 [ DEBUG]:mpegts: 545.833MHz in DVB-T Network - close PID 19C8 (6600) [8/0x1ed5c78]
2021-06-08 20:58:28.221 [ DEBUG]:mpegts: 545.833MHz in DVB-T Network - close PID 19C9 (6601) [8/0x1ed5c78]
2021-06-08 20:58:28.221 [ DEBUG]:mpegts: 545.833MHz in DVB-T Network - close PID 19CA (6602) [8/0x1ed5c78]
2021-06-08 20:58:28.221 [ DEBUG]:mpegts: 545.833MHz in DVB-T Network - close PID 19CE (6606) [8/0x1ed5c78]
2021-06-08 20:58:28.221 [ DEBUG]:mpegts: 545.833MHz in DVB-T Network - close PID 19CD (6605) [8/0x1ed5c78]
2021-06-08 20:58:28.221 [ DEBUG]:mpegts: 545.833MHz in DVB-T Network - stopping mux
2021-06-08 20:58:28.222 [ DEBUG]:linuxdvb: Sony CXD2880 #0 : DVB-T #0 - stopping 545.833MHz in DVB-T Network
2021-06-08 20:58:28.228 [ DEBUG]:linuxdvb: Sony CXD2880 #0 : DVB-T #0 - stopped dvr thread
2021-06-08 20:58:28.229 [ DEBUG]:mpegts: 545.833MHz in DVB-T Network - close PID 0000 (0) [20/0x6a510860]
2021-06-08 20:58:28.229 [ DEBUG]:mpegts: 545.833MHz in DVB-T Network - close PID 0001 (1) [16/0x6a511c90]
2021-06-08 20:58:28.229 [ DEBUG]:mpegts: 545.833MHz in DVB-T Network - close PID 0010 (16) [16/0x6a506e80]
2021-06-08 20:58:28.229 [ DEBUG]:mpegts: 545.833MHz in DVB-T Network - close PID 0011 (17) [20/0x6a5082b0]
2021-06-08 20:58:28.229 [ DEBUG]:mpegts: 545.833MHz in DVB-T Network - close PID 0011 (17) [16/0x6a5096e0]
2021-06-08 20:58:28.229 [ DEBUG]:mpegts: 545.833MHz in DVB-T Network - close PID 0012 (18) [20/0x6a50eee8]
2021-06-08 20:58:28.229 [ DEBUG]:epggrab: grab done for 545.833MHz in DVB-T Network (stolen)
RE: Trying to use nginx, rtmp & ffmpeg - Added by Jason A over 3 years ago
If I start an ffmpeg and then a couple of seconds later try and watch a different channel in Kodi, Kodi actually works.
RE: Trying to use nginx, rtmp & ffmpeg - Added by saen acro over 3 years ago
Add user "*" with password "*"
and allow IP access from your network and 127.0.0.1
This will allow unrestricted watching (no user pass needed)
RE: Trying to use nginx, rtmp & ffmpeg - Added by Jason A over 3 years ago
I have found the issue. The TVHeadend box I am connecting to is also running a VPN Server so I can connect as a client and run FFMPEG HTTP requests through the tunnel, if I do that then there seems to be some handshaking going on and the stream works fine after it has settled down. If I connect through <myurl>:9981 (which is public) then there is no handshaking going on for some reason.
I need to think about this...