Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconnect if disconnected on network stream. #5793

Closed
shinctl opened this issue May 3, 2018 · 25 comments
Closed

Reconnect if disconnected on network stream. #5793

shinctl opened this issue May 3, 2018 · 25 comments

Comments

@shinctl
Copy link

shinctl commented May 3, 2018

Hello guys,

Is there a command line option on MPV to automatically reconnect to a network stream?

Sometimes I get some network hiccups and the file stops playing, but if I just restart, it continues the playback normally.
I've tried with the "loop" option, but I keep getting unable to seek error.

Thanks.

@shinctl
Copy link
Author

shinctl commented May 3, 2018

Current command line (I've tried lots of cache options also)

mpv --cache-pause-initial=yes --cache-pause=no --cache-default=15360 --cache-initial=256 --demuxer-thread=yes --demuxer-readahead-secs=30 --framedrop=vo --sid=1 -cache-secs=30 URL

@shinctl shinctl changed the title Reconnect it disconnected on network stream. Reconnect if disconnected on network stream. May 3, 2018
@dnmTX
Copy link

dnmTX commented May 3, 2018

@shinctl i've had the same problem when leaving the player paused for longer time and then went away.It's basically server's fault,if you go trough terminal: mpv --h=network-timeout you'll see that is set to 0.000 aka to never expire.To answer your question i personally couldn't find such a command line assuming that if one is implemented would consume too much resources just to continuously checking if the connection is alive.

@shinctl
Copy link
Author

shinctl commented May 10, 2018

Network timeout option does not cover some errors, sadly :(
A option like VLC's "--http-reconnect" would be awesome.

@ghost
Copy link

ghost commented May 10, 2018

There's already reconnection code. You're providing too little information to do anything. This should just be closed.

@shinctl
Copy link
Author

shinctl commented May 10, 2018

If there is, how could I use it? I've tried searching all around the manual @mpv.io, but could not find any reconnect/restart option.
About the error I receive sometimes (Yes, I know it's the streams fault), but a reconnect after this error would be nice.
Error: [ffmpeg] NULL: missing picture in access unit

@shinctl
Copy link
Author

shinctl commented May 12, 2018

ATM mpv uses the "reconnect 1" option from ffmpeg right?
These other flags should help also...

-reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1

@porsager
Copy link

I'm curious if these options solved the disconnect issue for you?

@shinctl
Copy link
Author

shinctl commented Sep 21, 2018

Nope... I just gave up and used another player.

@porsager
Copy link

Oh ok.. Which one if I may ask?

@rudevdr
Copy link

rudevdr commented Oct 8, 2018

@shinctl which other player?

@garoto
Copy link
Contributor

garoto commented Oct 8, 2018

The input.conf line below is merely using mpv properties and the documented syntax listed on the manual:

CTRL+r write-watch-later-config ; show-text "Reloading file..." ; loadfile "${path}"

Granted, in the beggining, I've only found out about these sort of capabilities of input.conf and other mpv facilities because I lurked a lot on this issue tracker, reading every ticket that had a title even remotely interesing.

So yeah, search this issue tracker more.

@ghost
Copy link

ghost commented Nov 9, 2019

Still not clear what this issue is even about. Not a single log, not even a description of ma use case. Closing.

@ghost ghost closed this as completed Nov 9, 2019
@porsager
Copy link

porsager commented Nov 9, 2019

In my case I'm seeing Radio streams just stopping (no audio) without any information. It'll happen after several hours/days playback, and it's very sporadic. I was thinking of setting up a test case that could check for audio activity, and record once it stopped. Then set up multiple players starting some at the same time, and some later to figure out if it's a disconnect from the source causing it, or something for the single player. Either way, it's hard to debug when it occurs with no output, but audio just stops.

I'd be willing to set up test, if you have ideas so we can open the issue again?

@ghost
Copy link

ghost commented Nov 9, 2019

Is that just a mp3/ogg stream (typical web radio)?
Does it show "buffering" on the status line when it gets stuck?
This doesn't sound like disconnection, just being stuck, which I've sometimes observed too.

@porsager
Copy link

porsager commented Nov 9, 2019

Yeah, In my case a regular mp3 cast link like : http://live-icy.gss.dr.dk/A/A05H.mp3.m3u

It's been a while since I looked in to it, so I honestly can't remember about buffering, but I'd love to look at it again since it's a recurring issue for us that we've just "learned to live with".

I'll try to set up a test with some verbose logging the coming week. Do you have any solution for solving the "stuck" situation you've encountered?

@ghost
Copy link

ghost commented Nov 9, 2019

The case I encountered was with HLS, so potentially completely different.

I suspect there's something broken with ffmpeg's network timeout handling.

You can just reopen the stream.

If it's stuck, you may also get some information by dumping the demuxer-cache-state property, or by attaching a debugger and making a back trace on all threads.

@ghost
Copy link

ghost commented Nov 9, 2019

There's also --network-timeout. This may or may not do something. Maybe you can test this by temporarily disconnecting the network cable or so.

ghost pushed a commit that referenced this issue Nov 14, 2019
Until now, we've made FFmpeg use the default network timeout - which is
apparently infinite. I don't know if this was changed at some point,
although it seems likely, as I was sure there was a more useful default.

For most use cases, a smaller timeout is more useful (for example
recording something in the background), so force a timeout of 1 minute.

See: #5793
@ghost
Copy link

ghost commented Nov 14, 2019

It turns out FFmpeg does not set a network timeout by default (anymore?), and since mpv explicitly makes FFmpeg use its default by default, mpv didn't have a timeout either.

I've changed this in git master. Now it uses a 60 second timeout. So instead of getting stuck in "Buffering" for a longer time, it should exit after 1 minute. I had to add a workaround for the cursed RTSP issue (it doesn't set a timeout for RTSP).

Regarding reconnecting, this is tricky too. HTTP normally reconnects, but only if the server accepts range requests. This is because for "static" streams, you want to continue where it left off, instead of starting from the start again.

mp3 web radio (aka icy/shoutcast/etc.) will not accept range requests, so mpv won't reconnect by default. You can force this with --stream-lavf-o=reconnect_streamed=1. I'm hesitant to enable this by default, because sometimes media is delivered without support for range requests, which could lead to very irritating behavior, especially with HLS/DASH.

I don't know if HLS is affected by these changes.

@porsager
Copy link

Uh, great work wm4 ! I've unfortunately been too bogged down by other tasks this week, but once I get to it I'll set up tests with git master and last release! Very interesting!

ghost pushed a commit that referenced this issue Nov 16, 2019
It sometimes happens that HLS streams freeze because the HTTP server is
not responding for a fragment (or something similar, the exact
circumstances are unknown). The --timeout option didn't affect this,
because it's never set on HLS recursive connections (these download the
fragments, while the main connection likely nothing and just wastes a
TCP socket).

Apply an elaborate hack on top of an existing elaborate hack to somehow
get these options set. Of course this could still break easily, but hey,
it's ffmpeg, it can't not try to fuck you over. I'm so fucking sick of
ffmpeg's API bullshit, especially wrt. HLS.

Of course the change is sort of pointless. For HLS, GET requests should
just aggressively retried (because they're not "streamed", they're just
actual files on a CDN), while normal HTTP connections should probably
not be made this fragile (they could be streamed, i.e. they are backed
by some sort of real time encoder, and block if there is no data yet).
The 1 minute default timeout is too high to save playback if this
happens with HLS.

Vaguely related to #5793.
@voidzero
Copy link

Here's an issue I've been having:

A: 00:00:33 / 00:00:39 (82%) Cache: 6.5s/121KB
[ffmpeg] tls: Error in the pull function.
[ffmpeg/demuxer] aac: Packet corrupt (stream = 0, dts = NOPTS).
A: 00:00:39 / 00:00:39 (98%) Cache: 0.3s/4KB
[ffmpeg/audio] aac: Input buffer exhausted before END element found
Error decoding audio.
A: 00:00:39 / 00:00:39 (98%) Cache: 0.0s


Exiting... (End of file)

I'd like mpv to try everything to reconnect on issues like this one. I listen to a lot of talk radio and interruptions suck. This mainly happens on my mobile (mpv with termux) fairly often, maybe due to wifi, I'm not sure.

@alexishuxley
Copy link

alexishuxley commented Jan 19, 2024

I encounter the same problem. Here's the output:

pirohy$ mpv http://live.slovakradio.sk:8000/FM_128.mp3
 (+) Audio --aid=1 (mp3 2ch 44100Hz)
[W][72817.559382] pw.conf      | [          conf.c:  939 try_load_conf()] can't load config client.conf: No such file or directory
[E][72817.559490] pw.conf      | [          conf.c:  963 pw_conf_load_conf_for_context()] can't load default config client.conf: No such file or directory
AO: [pulse] 44100Hz stereo 2ch float
A: 00:00:00 / 00:00:05 (18%) Cache: 4.0s/144KB
File tags:
 icy-title: * Radio_FM * www.radiofm.sk * Baláž & Hubinák *
A: 00:03:27 / 00:03:31 (98%) Cache: 3.7s/131KB
File tags:
 icy-title: The Black Keys - Beautiful People (Stay High)
A: 00:06:07 / 00:06:12 (99%) Cache: 3.9s/139KB
File tags:
 icy-title: Tolstoys - Real
A: 00:09:05 / 00:09:10 (99%) Cache: 3.8s/136KB
File tags:
 icy-title: Eva KOSTOLÁNYIOVÁ, SBOR LUBOMÍRA PÁNKA, Tanecný orchester Slovenského rozhlasu - Leto
A: 00:13:03 / 00:13:08 (99%) Cache: 3.9s/140KB
File tags:
 icy-title: * Radio_FM * www.radiofm.sk * Baláž & Hubinák *
A: 00:15:26 / 00:15:26 (100%) Cache: 0.0s
Audio device underrun detected.
A: 00:15:26 / 00:15:26 (100%) Cache: 0.1s/2KB
[ffmpeg/audio] mp3float: invalid new backstep -1

Exiting... (End of file)
pirohy$ 

During the daytime this error has not occurred, but as evening draws on then it occurs several times per hour, presumably as the server gets more loaded.

This is easy to reproduce so if you'd like more logs just let me know what command line options to add. (I realise this issue is closed, but the problem persists. If you would prefer that I post on another issue, then just let me know which. This seemed the most relevant.)

@guidocella
Copy link
Contributor

You can try the options suggested in #8779 (comment)

@alexishuxley
Copy link

@guidocella : sorry for delay, I wanted to test the suggestions propertly and that took a few days It worked very well for http://live.slovakradio.sk:8000/FM_128.mp3. Thanks very much! But the BBC still drops out with exactly the same symptoms:

damson$ mpv --stream-lavf-o-append=reconnect_on_http_error=4xx,5xx --stream-lavf-o-append=reconnect_delay_max=30 --stream-lavf-o-append=reconnect_streamed=yes --stream-lavf-o-append=reconnect_on_network_error=yes http://as-hls-ww-live.akamaized.net/pool_904/live/ww/bbc_radio_fourfm/bbc_radio_fourfm.isml/bbc_radio_fourfm-audio%3d96000.norewind.m3u8
 (+) Audio --aid=1 (aac 2ch 48000Hz)
[W][78693.176556] pw.conf      | [          conf.c:  939 try_load_conf()] can't load config client.conf: No such file or directory
[E][78693.176605] pw.conf      | [          conf.c:  963 pw_conf_load_conf_for_context()] can't load default config client.conf: No such file or directory
AO: [pulse] 48000Hz stereo 2ch float
A: 00:10:46 / 00:10:46 (100%) Cache: 0.0s

Exiting... (End of file)
damson$

This takes between 5-30 minutes to exit, but the behaviour isn't time-of-day sensitive.

@pcgeek86
Copy link

pcgeek86 commented Aug 2, 2024

This issue is really bothersome ... I wish MPV would automatically reconnect to my security camera's RTSP streams, when they hang. I have to exit and start a new MPV process, and then resize the window again.

Please fix the player so that it automatically reconnects.

@alexishuxley
Copy link

alexishuxley commented Aug 3, 2024 via email

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants