Repository: yt-dlp
Issue: Feature to save periodically for a long live stream
Labels: enhancement,triage

### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

- [X] I understand that I will be **blocked** if I *intentionally* remove or skip any mandatory\* field

### Checklist

- [X] I'm requesting a feature unrelated to a specific site
- [X] I've looked through the [README](https://github.com/yt-dlp/yt-dlp#readme)
- [X] I've verified that I have **updated yt-dlp to nightly or master** ([update instructions](https://github.com/yt-dlp/yt-dlp#update-channels))
- [X] I've searched [known issues](https://github.com/yt-dlp/yt-dlp/issues/3766) and the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)

### Provide a description that is worded well enough to be understood

I couldn't find any feature or parameters that allow yt-dlp to save periodically for a long live stream. Sometimes, the long live stream breaks with a sequence of errors like the follow that end up with yt-dlp hanging in the console:
```
Unable to read from socket
Writing encrypted data to socket failed
Failed to send close message
keepalive request failed for <url> with error: 'I/O error' when opening url, retrying with new connection
PES packet size mismatch
Packet corrupt
```
I had to enter CTRL+C twice during the above error to exit, after which I get the following error:
```
Error writing trailer of file:<file name>: Immediate exit requested
```
The above set of errors occur usually when a live stream runs for several hours and ends up being several gigabytes. Other miscellaneous errors might occur that destroys part of or the entirety of a long live stream. In my experience, if the live stream is 5 hours long, most of the 5 hour recording is usually lost. I am wondering if it is possible to add a feature to save a live stream periodically, such as:
```
yt-dlp <URL> -SaveEvery 3600
```
The above would time the execution of yt-dlp downloads and attempt to stop the downloading after 3600 seconds and save to a file. Then it should resume downloading from the same URL. Is such a feature possible? I was attempting to write a wrapper script replicating this feature suggestion in PowerShell, but this requires kicking off yt-dlp as a PowerShell job, but PowerShell jobs doesn't work well with yt-dlp as the [download] and [FixupM3u8] processes doesn't seem to run to completion at the end of a live stream because PowerShell seems to kill the yt-dlp process outright. It's also not clear to me how to properly terminate yt-dlp programmatically, since it seems to be designed around manual console usage and is stopped via CTRL+C. Therefore, this feature would be more reliable if yt-dlp implemented the feature pointed out above.

### Provide verbose output that clearly demonstrates the problem

- [ ] Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
- [ ] If using API, add `'verbose': True` to `YoutubeDL` params instead
- [ ] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

_No response_