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

youtube-dl often hangs when live stream is ended or paused #12271

Open
Vrihub opened this issue Feb 26, 2017 · 10 comments
Open

youtube-dl often hangs when live stream is ended or paused #12271

Vrihub opened this issue Feb 26, 2017 · 10 comments

Comments

@Vrihub
Copy link
Contributor

@Vrihub Vrihub commented Feb 26, 2017

  • I've verified and I assure that I'm running youtube-dl 2017.02.24.1
  • At least skimmed through README and most notably FAQ and BUGS sections
  • Searched the bugtracker for similar issues including closed ones

What is the purpose of your issue?

  • Bug report (encountered problems with youtube-dl)
  • Site support request (request for adding support for a new site)
  • Feature request (request for a new functionality)
  • Question
  • Other

Description of your issue, suggested solution and other information

Quite often while recording a live stream, when the stream ends, youtube-dl doesn't exit, but hangs for several minutes, then it exits (sometimes correctly renaming the *.part file, sometimes leaving it as is).

The same happens sometimes when the live stream stops for a few seconds, e.g. because of bad network connection at the transmitting or receiving end, and then resumes: youtube hangs and fails to continue writing to the file.

I've experienced these bugs mainly with periscope.tv. I'm not sure if it may affect other sites.

I've tried passing --socket-timeout with a low value, but it doesn't have any effect (BTW, maybe it could be useful to mention the default value (600 secs) in the man page).

Are there any other network parameters in the source code that I can try to tweak?

As a second-best solution, if the bug can't be fixed properly because youtube-dl can't be sure is the stream is actually ended or not, it would be better to change the default behaviour from "when in doubt hang" to "when in doubt exit", so that the user could run youtube-dl inside a while loop through a wrapper script, and have it restart automatically after exiting when the live stream stops.

@Tatsh
Copy link
Contributor

@Tatsh Tatsh commented Mar 14, 2017

If you are getting a bad container, then one way for youtube-dl to fix this is to pass -movflags +faststart.

ffmpeg will correctly finish the file as long as you exit once. If you try to exit forcefully (pressing ^C twice or kill -9, etc) you will have a corrupted file.

@Vrihub
Copy link
Contributor Author

@Vrihub Vrihub commented Mar 24, 2017

Thanks, but the problem is not the corrupted file (I'm already using --hls-use-mpegts to bypass this problem), but the fact that youtube-dl doesn't realise that the upstream has stopped transmitting, and it hangs waiting forever, instead of exiting after a reasonable time.

@soviet-warrior
Copy link

@soviet-warrior soviet-warrior commented May 22, 2017

I'm still experiencing this issue. At the end of the youtube stream it hangs every time. Pressing Ctrl+C once does nothing (even after an 8 hour wait). Pressing Ctrl+C again will force it to stop but that causes the output file to be corrupt. Sometimes I can disconnect my internet and that will cause it to stop properly and produce a working output file but other times it just stays hung.

@bag-man
Copy link

@bag-man bag-man commented Apr 8, 2018

@Tatsh If I hit Ctrl+C twice is my file corrupted and unrecoverable, or can I do something to get it back?

@Tatsh
Copy link
Contributor

@Tatsh Tatsh commented Apr 8, 2018

Most of the time if it's MP4 container you can't. The data required to fix the stream isn't in the file at that time.

@printempw
Copy link

@printempw printempw commented Oct 21, 2018

+1, it's quite annoying.

@Zialus
Copy link

@Zialus Zialus commented Dec 3, 2018

I'm having the same issue.

@davr
Copy link

@davr davr commented May 8, 2020

Same problem here, why is there no way to gracefully stop capturing a live stream without getting a corrupt file??

@davr
Copy link

@davr davr commented May 8, 2020

Apparently you used to be able to press 'q', but they put in a hack that stops that from working because people didn't know how to write scripts: #8252

@mwdiers
Copy link

@mwdiers mwdiers commented Jul 17, 2020

This is definitely still a problem. If a livestream ends while youtube-dl is still attempting to capture it, it is not possible to exit gracefully with a single Ctrl-C. It will never exit, and will never close out the file. The only way to exit is a double-Ctrl-C, which results in an unplayable file.

This just happened to me yesterday.

@nielsmh nielsmh mentioned this issue Aug 22, 2020
5 of 9 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
8 participants
You can’t perform that action at this time.