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] premature download termination with --live-from-start #2898

Open
6 tasks done
krichbanana opened this issue Feb 26, 2022 · 18 comments
Open
6 tasks done

[youtube] premature download termination with --live-from-start #2898

krichbanana opened this issue Feb 26, 2022 · 18 comments
Labels
bug Bug that is not site-specific

Comments

@krichbanana
Copy link
Contributor

Checklist

  • I'm reporting a bug unrelated to a specific site
  • I've verified that I'm running yt-dlp version 2022.02.04. (update instructions)
  • I've checked that all provided URLs are alive and playable in a browser
  • I've checked that all URLs and arguments with special characters are properly quoted or escaped
  • I've searched the bugtracker for similar issues including closed ones. DO NOT post duplicates
  • I've read the guidelines for opening an issue

Description

(URLs are no longer playable.)
Unfortunately I did not have an HLS download, but no playback issue was noticed in the browser.

Generally speaking, it seems possible for --live-from-start to prematurely terminating the download of each stream, resulting in a truncated or corrupted file.

First download, video lasted longer than the audio, 01:19:23.000 vs 00:52:58.998 (I believe the video is full-length). On playback in mpv, the following warning is logged, at the 53 minute mark:

[lavf] Too many packets in the demuxer packet queues:
[lavf]   video/0: 16054 packets, 157294896 bytes
[lavf]   audio/1: 0 packets, 0 bytes

Seeking beyond that point is considerably slower.

Second download, video and audio downloads terminated even earlier, at 00:43:38:00. The fragments after that point were never downloaded.

I suspect the reworking of --live-from-start may be at fault. It may also be another issue somewhere in the downloader as well, I do not know.

I do know, however, that based on the logs the interruption seems tied to a spontaneous webpage download in the middle of downloading the fragments. Presumably when this happens the stream download is permanently interrupted.

Verbose log

# First download
date; ytdlp -v --write-thumbnail --write-description --write-info-json  --live-from-start --wait-for-video=2-3 -N4 J5c7fJOMeXk; date
Sat Feb 26 02:00:06 AM EST 2022
[debug] Command-line config: ['-v', '--write-thumbnail', '--write-description', '--write-info-json', '--live-from-start', '--wait-for-video=2-3', '-N4', 'J5c7fJOMeXk']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, err utf-8, pref UTF-8
[debug] yt-dlp version 2022.02.04 [c1653e9ef] (source)
[debug] Lazy loading extractors is disabled
[debug] Plugins: ['SamplePluginIE', 'SamplePluginPP']
[debug] Git HEAD: f0734e119
[debug] Python version 3.10.2 (CPython 64bit) - Linux-5.15.25-1-lts-x86_64-with-glibc2.35
[debug] exe versions: ffmpeg 5.0 (setts), ffprobe 5.0, rtmpdump 2.4
[debug] Optional libraries: Cryptodome, mutagen, sqlite, websockets
[debug] Proxy map: {}
[debug] [youtube] Extracting URL: J5c7fJOMeXk
[youtube] J5c7fJOMeXk: Downloading webpage
[youtube] J5c7fJOMeXk: Downloading android player API JSON
WARNING: [youtube] This live event will begin in 15 minutes.
[wait] Waiting for 00:00:03 - Press Ctrl+C to try now
[wait] Wait period ended; Re-extracting data                 
[debug] [youtube] Extracting URL: J5c7fJOMeXk
[youtube] J5c7fJOMeXk: Downloading webpage
[youtube] J5c7fJOMeXk: Downloading android player API JSON
WARNING: [youtube] This live event will begin in 15 minutes.
[wait] Waiting for 00:00:03 - Press Ctrl+C to try now
[wait] Wait period ended; Re-extracting data                 
<cut...>
[youtube] J5c7fJOMeXk: Downloading webpage
[youtube] J5c7fJOMeXk: Downloading android player API JSON
WARNING: [youtube] This live event will begin in a few moments.
WARNING: Release time of video is not known
[wait] Waiting for 00:00:02 - Press Ctrl+C to try now
[wait] Wait period ended; Re-extracting data                 
[debug] [youtube] Extracting URL: J5c7fJOMeXk
[youtube] J5c7fJOMeXk: Downloading webpage
[youtube] J5c7fJOMeXk: Downloading android player API JSON
WARNING: [youtube] This live event will begin in a few moments.
WARNING: Release time of video is not known
[wait] Waiting for 00:00:02 - Press Ctrl+C to try now
[wait] Wait period ended; Re-extracting data                 
[debug] [youtube] Extracting URL: J5c7fJOMeXk
[youtube] J5c7fJOMeXk: Downloading webpage
[youtube] J5c7fJOMeXk: Downloading android player API JSON
[youtube] J5c7fJOMeXk: Downloading MPD manifest
[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, codec:vp9.2, lang, proto
[debug] Formats sorted by: hasvid, ie_pref, quality, res, fps, hdr:12(7), source, vcodec:vp9.2(10), acodec, lang, proto, filesize, fs_approx, tbr, vbr, abr, asr, vext, aext, hasaud, id
[debug] Default format spec: best/bestvideo+bestaudio
[info] J5c7fJOMeXk: Downloading 1 format(s): 299+140
[info] Writing video description to: 【KARAOKE】Off COLLAB(Fauna, Mumei, Ina, Kronii) IKZ [J5c7fJOMeXk].description
[info] Downloading video thumbnail 46 ...
[info] Writing video thumbnail 46 to: 【KARAOKE】Off COLLAB(Fauna, Mumei, Ina, Kronii) IKZ [J5c7fJOMeXk].webp
[info] Writing video metadata as JSON to: 【KARAOKE】Off COLLAB(Fauna, Mumei, Ina, Kronii) IKZ [J5c7fJOMeXk].info.json
[debug] Invoking downloader on "https://manifest.googlevideo.com/api/manifest/dash/expire/1645881617/ei/sdQZYtmOJeOA2LYPtcufyA8/ip/<IP_ADDR>/id/J5c7fJOMeXk.1/source/yt_live_broadcast/requiressl/yes/hfr/1/as/fmp4_audio_clear%2Cwebm_audio_clear%2Cwebm2_audio_clear%2Cfmp4_sd_hd_clear%2Cwebm2_sd_hd_clear/vprv/1/pacing/0/itag_bl/376%2C377%2C384%2C385%2C612%2C613%2C617%2C619%2C623%2C628%2C655%2C656%2C660%2C662%2C666%2C671/keepalive/yes/fexp/24001373%2C24007246/itag/0/playlist_type/LIVE/sparams/expire%2Cei%2Cip%2Cid%2Csource%2Crequiressl%2Chfr%2Cas%2Cvprv%2Citag%2Cplaylist_type/sig/AOq0QJ8wRAIgfR6yUNDocKcpqwWm3rXlVaUPRJzTOQAGbQC4M880p44CIBEZWRSHiK-oMYi-c5d4BsaJnZd48LBQU1DZLJNPB83D", "https://manifest.googlevideo.com/api/manifest/dash/expire/1645881617/ei/sdQZYtmOJeOA2LYPtcufyA8/ip/<IP_ADDR>/id/J5c7fJOMeXk.1/source/yt_live_broadcast/requiressl/yes/hfr/1/as/fmp4_audio_clear%2Cwebm_audio_clear%2Cwebm2_audio_clear%2Cfmp4_sd_hd_clear%2Cwebm2_sd_hd_clear/vprv/1/pacing/0/itag_bl/376%2C377%2C384%2C385%2C612%2C613%2C617%2C619%2C623%2C628%2C655%2C656%2C660%2C662%2C666%2C671/keepalive/yes/fexp/24001373%2C24007246/itag/0/playlist_type/LIVE/sparams/expire%2Cei%2Cip%2Cid%2Csource%2Crequiressl%2Chfr%2Cas%2Cvprv%2Citag%2Cplaylist_type/sig/AOq0QJ8wRAIgfR6yUNDocKcpqwWm3rXlVaUPRJzTOQAGbQC4M880p44CIBEZWRSHiK-oMYi-c5d4BsaJnZd48LBQU1DZLJNPB83D"
[dashsegments] Total fragments: unknown (live)
[download] Destination: 【KARAOKE】Off COLLAB(Fauna, Mumei, Ina, Kronii) IKZ [J5c7fJOMeXk].f299.mp4
[dashsegments] Total fragments: unknown (live)
[download] Destination: 【KARAOKE】Off COLLAB(Fauna, Mumei, Ina, Kronii) IKZ [J5c7fJOMeXk].f140.mp4
WARNING: The download speed shown is only of one thread. This is a known issue and patches are welcome
WARNING: The download speed shown is only of one thread. This is a known issue and patches are welcome
[download] 1.60GiB at  1.62MiB/s (52:53) (frag 3177)[youtube] J5c7fJOMeXk: Downloading webpage
[download] 1.60GiB at  2.59MiB/s (52:53) (frag 3179)
[download] 65.68MiB at 147.60KiB/s (52:53) (frag 3179)[youtube] J5c7fJOMeXk: Downloading android player API JSON
[youtube] J5c7fJOMeXk: Downloading MPD manifest
[download] 2.43GiB at  2.59MiB/s (01:19:19) (frag 4763)[download] Got server HTTP error: The read operation timed out. Retrying (attempt 1 of 10) ...
[youtube] J5c7fJOMeXk: Downloading webpage
[youtube] J5c7fJOMeXk: Downloading android player API JSON
[youtube] J5c7fJOMeXk: Downloading m3u8 information
[youtube] J5c7fJOMeXk: Downloading MPD manifest
[youtube] J5c7fJOMeXk: Downloading m3u8 information
[youtube] J5c7fJOMeXk: Downloading MPD manifest
[download] Got server HTTP error: HTTP Error 502: Bad Gateway. Retrying (attempt 2 of 10) ...
[download] Got server HTTP error: IncompleteRead(227304 bytes read). Retrying fragment 4764 (attempt 1 of 10) ...
[download] Got server HTTP error: HTTP Error 404: Not Found. Retrying fragment 4764 (attempt 2 of 10) ...
[download] Got server HTTP error: HTTP Error 503: Service Unavailable. Retrying (attempt 1 of 10) ...
[download] 2.43GiB at  5.30KiB/s (01:20:31) (frag 4763)[download] Got server HTTP error: The read operation timed out. Retrying (attempt 2 of 10) ...
[download] Got server HTTP error: HTTP Error 404: Not Found. Retrying fragment 4764 (attempt 3 of 10) ...
[download] 2.43GiB at  3.99KiB/s (01:21:10) (frag 4763)[download] Got server HTTP error: The read operation timed out. Retrying (attempt 1 of 10) ...
[download] Got server HTTP error: HTTP Error 404: Not Found. Retrying fragment 4764 (attempt 4 of 10) ...
[download] 2.43GiB at  3.50KiB/s (01:21:34) (frag 4763)[download] Got server HTTP error: The read operation timed out. Retrying (attempt 1 of 10) ...
[download] Got server HTTP error: HTTP Error 503: Service Unavailable. Retrying (attempt 2 of 10) ...
[download] Got server HTTP error: IncompleteRead(1000 bytes read). Retrying fragment 4764 (attempt 5 of 10) ...
[download] Got server HTTP error: IncompleteRead(1000 bytes read). Retrying fragment 4764 (attempt 6 of 10) ...
[download] Got server HTTP error: The read operation timed out. Retrying (attempt 1 of 10) ...
[download] Got server HTTP error: HTTP Error 503: Service Unavailable. Retrying (attempt 2 of 10) ...
[download] Got server HTTP error: The read operation timed out. Retrying (attempt 3 of 10) ...
[download] Got server HTTP error: HTTP Error 404: Not Found. Retrying fragment 4764 (attempt 7 of 10) ...
[download] Got server HTTP error: The read operation timed out. Retrying (attempt 1 of 10) ...
[download] Got server HTTP error: HTTP Error 503: Service Unavailable. Retrying (attempt 2 of 10) ...
[download] Got server HTTP error: The read operation timed out. Retrying (attempt 3 of 10) ...
[download] Got server HTTP error: HTTP Error 404: Not Found. Retrying fragment 4764 (attempt 8 of 10) ...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 4764 (attempt 9 of 10) ...
[download] Got server HTTP error: HTTP Error 404: Not Found. Retrying fragment 4764 (attempt 10 of 10) ...
[download] fragment not found; Skipping fragment 4764 ...
[download] 100% of 2.43GiB in 01:24:24

[Merger] Merging formats into "【KARAOKE】Off COLLAB(Fauna, Mumei, Ina, Kronii) IKZ [J5c7fJOMeXk].mp4"
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i 'file:【KARAOKE】Off COLLAB(Fauna, Mumei, Ina, Kronii) IKZ [J5c7fJOMeXk].f299.mp4' -i 'file:【KARAOKE】Off COLLAB(Fauna, Mumei, Ina, Kronii) IKZ [J5c7fJOMeXk].f140.mp4' -c copy -map 0:v:0 -map 1:a:0 -movflags +faststart 'file:【KARAOKE】Off COLLAB(Fauna, Mumei, Ina, Kronii) IKZ [J5c7fJOMeXk].temp.mp4'
Deleting original file 【KARAOKE】Off COLLAB(Fauna, Mumei, Ina, Kronii) IKZ [J5c7fJOMeXk].f140.mp4 (pass -k to keep)
Deleting original file 【KARAOKE】Off COLLAB(Fauna, Mumei, Ina, Kronii) IKZ [J5c7fJOMeXk].f299.mp4 (pass -k to keep)
Sat Feb 26 03:44:55 AM EST 2022


# download 2, started late
date; ytdlp -v --write-thumbnail --write-description --write-info-json  --live-from-start --wait-for-video=2-3 -N4 --keep-fragments J5c7fJOMeXk;date
Sat Feb 26 02:47:58 AM EST 2022
[debug] Command-line config: ['-v', '--write-thumbnail', '--write-description', '--write-info-json', '--live-from-start', '--wait-for-video=2-3', '-N4', '--keep-fragments', 'J5c7fJOMeXk']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, err utf-8, pref UTF-8
[debug] yt-dlp version 2022.02.04 [c1653e9ef] (source)
[debug] Lazy loading extractors is disabled
[debug] Plugins: ['SamplePluginIE', 'SamplePluginPP']
[debug] Git HEAD: f0734e119
[debug] Python version 3.10.2 (CPython 64bit) - Linux-5.15.25-1-lts-x86_64-with-glibc2.35
[debug] exe versions: ffmpeg 5.0 (setts), ffprobe 5.0, rtmpdump 2.4
[debug] Optional libraries: Cryptodome, mutagen, sqlite, websockets
[debug] Proxy map: {}
[debug] [youtube] Extracting URL: J5c7fJOMeXk
[youtube] J5c7fJOMeXk: Downloading webpage
[youtube] J5c7fJOMeXk: Downloading android player API JSON
[youtube] J5c7fJOMeXk: Downloading MPD manifest
[youtube] J5c7fJOMeXk: Downloading MPD manifest
[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, codec:vp9.2, lang, proto
[debug] Formats sorted by: hasvid, ie_pref, quality, res, fps, hdr:12(7), source, vcodec:vp9.2(10), acodec, lang, proto, filesize, fs_approx, tbr, vbr, abr, asr, vext, aext, hasaud, id
[debug] Default format spec: best/bestvideo+bestaudio
[info] J5c7fJOMeXk: Downloading 1 format(s): 299+140
[info] Writing video description to: 【KARAOKE】Off COLLAB(Fauna, Mumei, Ina, Kronii) IKZ [J5c7fJOMeXk].description
[info] Downloading video thumbnail 46 ...
[info] Writing video thumbnail 46 to: 【KARAOKE】Off COLLAB(Fauna, Mumei, Ina, Kronii) IKZ [J5c7fJOMeXk].webp
[info] Writing video metadata as JSON to: 【KARAOKE】Off COLLAB(Fauna, Mumei, Ina, Kronii) IKZ [J5c7fJOMeXk].info.json
[debug] Invoking downloader on "https://manifest.googlevideo.com/api/manifest/dash/expire/1645883280/ei/MNsZYs7SOM-T2LYPvYe78A4/ip/<IP_ADDR>/id/J5c7fJOMeXk.1/source/yt_live_broadcast/requiressl/yes/hfr/1/as/fmp4_audio_clear%2Cwebm_audio_clear%2Cwebm2_audio_clear%2Cfmp4_sd_hd_clear%2Cwebm2_sd_hd_clear/vprv/1/pacing/0/itag_bl/376%2C377%2C384%2C385%2C612%2C613%2C617%2C619%2C623%2C628%2C655%2C656%2C660%2C662%2C666%2C671/keepalive/yes/fexp/24001373%2C24007246/itag/0/playlist_type/LIVE/sparams/expire%2Cei%2Cip%2Cid%2Csource%2Crequiressl%2Chfr%2Cas%2Cvprv%2Citag%2Cplaylist_type/sig/AOq0QJ8wRQIhAKoe926iCe39_YhUkoRbQG1XMuW-Anh26o2epLvoUXLvAiBhg_iObCdPsStDTZ-KHX7IxPMGkjVzB31WSD7tNfIhpQ%3D%3D", "https://manifest.googlevideo.com/api/manifest/dash/expire/1645883280/ei/MNsZYs7SOM-T2LYPvYe78A4/ip/<IP_ADDR>/id/J5c7fJOMeXk.1/source/yt_live_broadcast/requiressl/yes/hfr/1/as/fmp4_audio_clear%2Cwebm_audio_clear%2Cwebm2_audio_clear%2Cfmp4_sd_hd_clear%2Cwebm2_sd_hd_clear/vprv/1/pacing/0/itag_bl/376%2C377%2C384%2C385%2C612%2C613%2C617%2C619%2C623%2C628%2C655%2C656%2C660%2C662%2C666%2C671/keepalive/yes/fexp/24001373%2C24007246/itag/0/playlist_type/LIVE/sparams/expire%2Cei%2Cip%2Cid%2Csource%2Crequiressl%2Chfr%2Cas%2Cvprv%2Citag%2Cplaylist_type/sig/AOq0QJ8wRQIhAKoe926iCe39_YhUkoRbQG1XMuW-Anh26o2epLvoUXLvAiBhg_iObCdPsStDTZ-KHX7IxPMGkjVzB31WSD7tNfIhpQ%3D%3D"
[dashsegments] Total fragments: unknown (live)
[download] Destination: 【KARAOKE】Off COLLAB(Fauna, Mumei, Ina, Kronii) IKZ [J5c7fJOMeXk].f299.mp4
[dashsegments] Total fragments: unknown (live)
[download] Destination: 【KARAOKE】Off COLLAB(Fauna, Mumei, Ina, Kronii) IKZ [J5c7fJOMeXk].f140.mp4
WARNING: The download speed shown is only of one thread. This is a known issue and patches are welcome
WARNING: The download speed shown is only of one thread. This is a known issue and patches are welcome
[download] 1.30GiB at 379.93KiB/s (15:48) (frag 2608)[youtube] J5c7fJOMeXk: Downloading webpage
[download] 1.30GiB at  2.67MiB/s (15:49) (frag 2610)
[download] 1.30GiB at  2.09MiB/s (15:49) (frag 2611)[youtube] J5c7fJOMeXk: Downloading MPD manifest
[youtube] J5c7fJOMeXk: Downloading MPD manifestg 2617)
[download] 100% of 1.30GiB in 15:52
[download] 100% of 54.09MiB in 15:51
[Merger] Merging formats into "【KARAOKE】Off COLLAB(Fauna, Mumei, Ina, Kronii) IKZ [J5c7fJOMeXk].mp4"
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i 'file:【KARAOKE】Off COLLAB(Fauna, Mumei, Ina, Kronii) IKZ [J5c7fJOMeXk].f299.mp4' -i 'file:【KARAOKE】Off COLLAB(Fauna, Mumei, Ina, Kronii) IKZ [J5c7fJOMeXk].f140.mp4' -c copy -map 0:v:0 -map 1:a:0 -movflags +faststart 'file:【KARAOKE】Off COLLAB(Fauna, Mumei, Ina, Kronii) IKZ [J5c7fJOMeXk].temp.mp4'
Deleting original file 【KARAOKE】Off COLLAB(Fauna, Mumei, Ina, Kronii) IKZ [J5c7fJOMeXk].f140.mp4 (pass -k to keep)
Deleting original file 【KARAOKE】Off COLLAB(Fauna, Mumei, Ina, Kronii) IKZ [J5c7fJOMeXk].f299.mp4 (pass -k to keep)
Sat Feb 26 03:04:06 AM EST 2022
@krichbanana krichbanana added bug Bug that is not site-specific triage Untriaged issue labels Feb 26, 2022
@Lesmiscore
Copy link
Contributor

Lesmiscore commented Feb 26, 2022

-N with more than 2 may get rejected by YouTube because of too many requests. It shouldn't be used for --live-from-start.

For the second attempt, was the live ended at the middle of download (in other words, was count of fragments grown rapidly)? It's still strange though.

memo to myself: run live for more than 1hs and start dl, then stop live after few mins of dl

@Lesmiscore Lesmiscore removed the triage Untriaged issue label Feb 26, 2022
@krichbanana
Copy link
Contributor Author

I use -N4 because I believed fragment downloads were throttled, is this not the case? I wanted the download to catch up before the stream ended.

The last valid fragment should have been 4763. I'm not sure what you mean with "was count of fragments grown rapidly"? On disk, only up to fragment 2618 was downloaded for each format stream, for the second download. Based on ctimes, both format streams were caught up to the live after fragment 2235.

As a side note, I'm curious as to why all the fragments on disk have the same mtime, as it seems like the fragment files on disk had their mtime set to the stream's start time. The final outfit file notably does not have the same mtime; it appears to be the time the download actually ended.

@Lesmiscore
Copy link
Contributor

Lesmiscore commented Feb 27, 2022

--live-from-start for YouTube has 2 phases; first to chase, next to follow. "was count of fragments grown rapidly" is the former.
It's hard to reproduce every single situations since there's too many thing to happen, and we can't expect streamers to trigger selected situations. I'll have to start livestreams to test.

I don't know about mtime thing.

@krichbanana
Copy link
Contributor Author

It may have been an untrapped URLError or OSError; with the updated HttpFD after #3065 the downloader caught an error from one of the stream downloads when my host roamed from an unresponsive router (AP):

...
[youtube] Saving request to None_https_-_manifest.googlevideo.com_api_manifest_dash_expire_1647985160_ei_qO05Yu6MA9uQ2LYP7L2liAI_ip_<IP_ADDR>_id_W_ncMSb255Y.1_source_yt_live_broadcast_requiressl_yes_hfr_1_as_fmp4_audio_clear%2Cwe_9005e9d487614fadeb34cde4e2d2ff86.dump
[youtube] Saving request to None_https_-_manifest.googlevideo.com_api_manifest_dash_expire_1647985160_ei_qO05Yu6MA9uQ2LYP7L2liAI_ip_<IP_ADDR>_id_W_ncMSb255Y.1_source_yt_live_broadcast_requiressl_yes_hfr_1_as_fmp4_audio_clear%2Cwe_9005e9d487614fadeb34cde4e2d2ff86.dump
[download] 2.44GiB at  9.85MiB/s (14:08) (frag 4761)[download] Got server HTTP error: <urlopen error [Errno 101] Network is unreachable>. Retrying (attempt 1 of 30) ...
[download] 6.12GiB at 729.64KiB/s (01:35:50) (frag 11791)[download] Got server HTTP error: IncompleteRead(70148 bytes read). Retrying (attempt 1 of 30) ...
[download] 7.02GiB at 108.89KiB/s (02:04:25) (frag 13502)[download] Got server HTTP error: IncompleteRead(6141 bytes read). Retrying (attempt 1 of 30) ...
[download] 7.50GiB at  1.41MiB/s (02:19:47) (frag 14428)
[download] 298.11MiB at 27.45KiB/s (02:19:47) (frag 14428)

Presumably before this would just kill one of the streams and leave the other stream to download by itself if it didn't end up aborting the whole download.

Initially I thought this would be caught by replacing HTTPError with URLError in fragment.py, but a closer look reveals it to be handled by HttpFD, so there may be nothing to fix anymore.

@pukkandan
Copy link
Member

@Lesmiscore You were to one who triaged this. Were you able to reproduce the issue?

@Lesmiscore

This comment was marked as outdated.

@pukkandan
Copy link
Member

#3065 likely fixed this. Can be reopened if anyone can reproduce

@pukkandan pukkandan added the cant-reproduce The issue cannot be reliably reproduced label Mar 28, 2022
@krichbanana
Copy link
Contributor Author

I can still reproduce this; in my case it was on a YouTube stream where the stream is lagging. I added some local debugging info to try and hunt down why, although I still lack a complete picture.

First off, the streams "die" (stop generating) on their own volition, when no_fragment_score is incremented past 30. is_live is still True. It's possible for just one of the streams to die if the error (which caused a read timeout) was very brief.

When the fragment download fails, the MPD manifest is refetched via _extract_mpd_formats_and_subtitles. Upon doing so, the list of available formats can change:

[youtube] Format availability changed! Current: ['139', '140', '133', '134', '135', '160', '136', '137', '242', '243', '244', '278', '247', '248']; lost ['299', '298']; gained ['248', '247', '242', '244', '243', '278']
[youtube] Format availability changed! Current: ['139', '140', '133', '134', '135', '160', '136', '137']; lost ['243', '244', '248', '278', '242', '247']; gained []
(debug message is mine)

There is a brief period (up to 10 seconds?) right when a livestream actually ends where all the formats may disappear before the stream no longer is live. Due to self-throttling for the manifest download this brief period could be missed. When the formats can be refreshed, new formats will appear:

[youtube] Format availability changed! Current: ['91', '92', '93', '94', '300', '301', '139', '140', '133', '134', '135', '160', '298', '299', '136', '137']; lost []; gained ['94', '91', '301', '300', '92', '93']
(as a side note, formats 300 and 301 do not appear to be listed in the extractor; they seem to be combined 720p/1080p HLS streams that are only available until the video is converted to vp9)


I believe the throttling on refresh_manifest may be causing no_fragment_score to increment rapidly (beyond the 30 threshold) and causing the stream download to stop.
My suggestions:

  • As long as is_live is true, we do not exit the stream (don't increment no_fragment_score). Errors should be assumed to be transient (except HTTP 403 maybe).
  • We should notify if a stream has died so that we aren't downloading just the video or audio without the user realizing.
  • We should not abort downloading if the format disappears or the manifest fails to download; YouTube often throws HTTP 502/503 errors which go away after a few seconds. A retry with exponential backoff I believe would be appropriate here.
  • The manifest should possibly be checked more often (with reduced/no throttle on error), but the throttle itself needs to stay. I'm not very sure about this part, since I don't know the exact reason for the 5 second throttle; I think to avoid simultaneous requests caused by concurrency?

I likely made a few mistakes; feel free to point them out.

@devmaxxing
Copy link

Hello, I ran into a similar issue where the download resumes as normal after a transient error, however the final video is truncated. Reproduction steps:

  1. run yt-dlp with --live-from-start on a youtube live stream
  2. after download begins, disconnect internet connection and then reconnect after error/retry messages start showing up
  3. wait for stream to end

@KamelittaOida
Copy link

I'm fairly certain this has to do with portrait vs landscape streams.

portrait:

F:\incoming\ffmpeg-4.0-win32-static\a aswerga2>yt-dlp -f 135+140 https://www.youtube.com/channel/UCOitAEYleeHZKt-npA0muww/live --live-from-start -r 266666 --force-overwrites -v
[debug] Command-line config: ['-f', '135+140', 'https://www.youtube.com/channel/UCOitAEYleeHZKt-npA0muww/live', '--live-from-start', '-r', '266666', '--force-overwrites', '-v']
[debug] Encodings: locale cp1252, fs utf-8, pref cp1252, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version [email protected] from yt-dlp/yt-dlp-nightly-builds [974d44403] (win_exe)
[debug] Python 3.8.10 (CPython AMD64 64bit) - Windows-10-10.0.19045-SP0 (OpenSSL 1.1.1k  25 Mar 2021)
[debug] exe versions: ffmpeg 2023-12-23-git-f5f414d9c4-essentials_build-www.gyan.dev (setts), ffprobe 2023-12-23-git-f5f414d9c4-essentials_build-www.gyan.dev
[debug] Optional libraries: Cryptodome-3.20.0, brotli-1.1.0, certifi-2024.02.02, mutagen-1.47.0, requests-2.31.0, sqlite3-3.35.5, urllib3-2.2.0, websockets-12.0
[debug] Proxy map: {}
[debug] Request Handlers: urllib, requests, websockets
[debug] Loaded 1833 extractors
[youtube:tab] Extracting URL: https://www.youtube.com/channel/UCOitAEYleeHZKt-npA0muww/live
[youtube:tab] UCOitAEYleeHZKt-npA0muww/live: Downloading webpage
[youtube] Extracting URL: https://www.youtube.com/watch?v=8Zf6S_59wpM
[youtube] 8Zf6S_59wpM: Downloading webpage
[youtube] 8Zf6S_59wpM: Downloading ios player API JSON
[youtube] 8Zf6S_59wpM: Downloading android player API JSON
[youtube] 8Zf6S_59wpM: Downloading MPD manifest
[youtube] 8Zf6S_59wpM: Downloading MPD manifest
[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, vcodec:vp9.2, channels, acodec, lang, proto
[debug] Formats sorted by: hasvid, ie_pref, quality, res, fps, hdr:12(7), source, vcodec:vp9.2(10), channels, acodec, lang, proto, size, br, asr, vext, aext, hasaud, id
[info] 8Zf6S_59wpM: Downloading 1 format(s): 135+140
[debug] Invoking dashsegments downloader on "https://manifest.googlevideo.com/api/manifest/dash/expire/1708247798/ei/lnbRZYTtBN_Ii9oPmN6TmAQ/ip/2a02%3A8388%3A8cc2%3A1b00%3A291b%3A1cd8%3A220b
%3Ab2ac/id/8Zf6S_59wpM.1/source/yt_live_broadcast/requiressl/yes/xpc/EgVo2aDSNQ%3D%3D/as/fmp4_audio_clear%2Cwebm_audio_clear%2Cwebm2_audio_clear%2Cfmp4_sd_hd_clear%2Cwebm2_sd_hd_clear/manife
st_duration/6/spc/UWF9f96kR0ite9idXFHvxFWQBbmJHYBzbtsvxzK6HiZiJac/vprv/1/pacing/0/itag_bl/376%2C377%2C384%2C385%2C612%2C613%2C617%2C619%2C623%2C628%2C655%2C656%2C660%2C662%2C666%2C671/keepal
ive/yes/fexp/24007246/itag/0/playlist_type/DVR/sparams/expire%2Cei%2Cip%2Cid%2Csource%2Crequiressl%2Cxpc%2Cas%2Cmanifest_duration%2Cspc%2Cvprv%2Citag%2Cplaylist_type/sig/AJfQdSswRgIhAKRyXxyy
hgE8fiQ0cdOr4rd-mtOKv-co4qO_vO-Jl7vcAiEA_5xmofjr7U6JEgbzt7LCsGq7BktGutBv0iePTe8Dy8U%3D", "https://manifest.googlevideo.com/api/manifest/dash/expire/1708247798/ei/lnbRZYTtBN_Ii9oPmN6TmAQ/ip/2
a02%3A8388%3A8cc2%3A1b00%3A291b%3A1cd8%3A220b%3Ab2ac/id/8Zf6S_59wpM.1/source/yt_live_broadcast/requiressl/yes/xpc/EgVo2aDSNQ%3D%3D/as/fmp4_audio_clear%2Cwebm_audio_clear%2Cwebm2_audio_clear%
2Cfmp4_sd_hd_clear%2Cwebm2_sd_hd_clear/manifest_duration/6/spc/UWF9f96kR0ite9idXFHvxFWQBbmJHYBzbtsvxzK6HiZiJac/vprv/1/pacing/0/itag_bl/376%2C377%2C384%2C385%2C612%2C613%2C617%2C619%2C623%2C6
28%2C655%2C656%2C660%2C662%2C666%2C671/keepalive/yes/fexp/24007246/itag/0/playlist_type/DVR/sparams/expire%2Cei%2Cip%2Cid%2Csource%2Crequiressl%2Cxpc%2Cas%2Cmanifest_duration%2Cspc%2Cvprv%2C
itag%2Cplaylist_type/sig/AJfQdSswRgIhAKRyXxyyhgE8fiQ0cdOr4rd-mtOKv-co4qO_vO-Jl7vcAiEA_5xmofjr7U6JEgbzt7LCsGq7BktGutBv0iePTe8Dy8U%3D"
[dashsegments] Total fragments: unknown (live)
[download] Destination: Welcome All here💕👍Meet new friends [8Zf6S_59wpM].f135.mp4
[debug] File locking is not supported. Proceeding without locking
[dashsegments] Total fragments: unknown (live)
[download] Destination: Welcome All here💕👍Meet new friends [8Zf6S_59wpM].f140.mp4
[debug] [youtube] [8Zf6S_59wpM] Generating fragments for format 135
[debug] [youtube] [8Zf6S_59wpM] Generating fragments for format 140
[download]  119.50MiB at  173.11KiB/s (00:14:35) (frag 763/1060)[youtube] 8Zf6S_59wpM: Downloading webpage
[download]  119.56MiB at  156.45KiB/s (00:14:35) (frag 763/1060)[youtube] 8Zf6S_59wpM: Downloading ios player API JSON
[download]  119.63MiB at  161.01KiB/s (00:14:35) (frag 763/1060)[youtube] 8Zf6S_59wpM: Downloading android player API JSON
[youtube] 8Zf6S_59wpM: Downloading MPD manifest
[youtube] 8Zf6S_59wpM: Downloading MPD manifest
[download]  133.79MiB at  183.88KiB/s (00:15:51) (frag 809/1060)
[download] 100% of  122.75MiB in 00:14:36 at 143.37KiB/s

landscape:

F:\incoming\ffmpeg-4.0-win32-static\a aswerga>yt-dlp -f 135+140 https://www.youtube.com/channel/UCCiEKK4835FTejF4ogW4P-A/live --live-from-start -r 266666 --force-overwrites -v
[debug] Command-line config: ['-f', '135+140', 'https://www.youtube.com/channel/UCCiEKK4835FTejF4ogW4P-A/live', '--live-from-start', '-r', '266666', '--force-overwrites', '-v']
[debug] Encodings: locale cp1252, fs utf-8, pref cp1252, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version [email protected] from yt-dlp/yt-dlp-nightly-builds [974d44403] (win_exe)
[debug] Python 3.8.10 (CPython AMD64 64bit) - Windows-10-10.0.19045-SP0 (OpenSSL 1.1.1k  25 Mar 2021)
[debug] exe versions: ffmpeg 2023-12-23-git-f5f414d9c4-essentials_build-www.gyan.dev (setts), ffprobe 2023-12-23-git-f5f414d9c4-essentials_build-www.gyan.dev
[debug] Optional libraries: Cryptodome-3.20.0, brotli-1.1.0, certifi-2024.02.02, mutagen-1.47.0, requests-2.31.0, sqlite3-3.35.5, urllib3-2.2.0, websockets-12.0
[debug] Proxy map: {}
[debug] Request Handlers: urllib, requests, websockets
[debug] Loaded 1833 extractors
[youtube:tab] Extracting URL: https://www.youtube.com/channel/UCCiEKK4835FTejF4ogW4P-A/live
[youtube:tab] UCCiEKK4835FTejF4ogW4P-A/live: Downloading webpage
[youtube] Extracting URL: https://www.youtube.com/watch?v=cz1FvQqs2Qw
[youtube] cz1FvQqs2Qw: Downloading webpage
[youtube] cz1FvQqs2Qw: Downloading ios player API JSON
[youtube] cz1FvQqs2Qw: Downloading android player API JSON
[youtube] cz1FvQqs2Qw: Downloading MPD manifest
[youtube] cz1FvQqs2Qw: Downloading MPD manifest
[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, vcodec:vp9.2, channels, acodec, lang, proto
[debug] Formats sorted by: hasvid, ie_pref, quality, res, fps, hdr:12(7), source, vcodec:vp9.2(10), channels, acodec, lang, proto, size, br, asr, vext, aext, hasaud, id
[info] cz1FvQqs2Qw: Downloading 1 format(s): 135+140
[debug] Invoking dashsegments downloader on "https://manifest.googlevideo.com/api/manifest/dash/expire/1708247446/ei/NnXRZZSAFYb31gKuqrLQDA/ip/2a02%3A8388%3A8cc2%3A1b00%3A291b%3A1cd8%3A220b%
3Ab2ac/id/cz1FvQqs2Qw.1/source/yt_live_broadcast/requiressl/yes/xpc/EgVo2aDSNQ%3D%3D/hfr/1/as/fmp4_audio_clear%2Cwebm_audio_clear%2Cwebm2_audio_clear%2Cfmp4_sd_hd_clear%2Cwebm2_sd_hd_clear/s
pc/UWF9fzsu1v0HqwOvNCYrXj24M7bxvkYvnDD6Yns836vmOuE/vprv/1/pacing/0/itag_bl/376%2C377%2C384%2C385%2C612%2C613%2C617%2C619%2C623%2C628%2C655%2C656%2C660%2C662%2C666%2C671/keepalive/yes/fexp/24
007246/itag/0/playlist_type/DVR/sparams/expire%2Cei%2Cip%2Cid%2Csource%2Crequiressl%2Cxpc%2Chfr%2Cas%2Cspc%2Cvprv%2Citag%2Cplaylist_type/sig/AJfQdSswRgIhAOdcZZI1wY-fdCoNtrgK6cg0kSTr5JaojFEBx
EW2f1IvAiEA3x41tdDES651GPIiHk-_fKDG4pMGg9vyFul2A2LKOBs%3D", "https://manifest.googlevideo.com/api/manifest/dash/expire/1708247446/ei/NnXRZZSAFYb31gKuqrLQDA/ip/2a02%3A8388%3A8cc2%3A1b00%3A291
b%3A1cd8%3A220b%3Ab2ac/id/cz1FvQqs2Qw.1/source/yt_live_broadcast/requiressl/yes/xpc/EgVo2aDSNQ%3D%3D/hfr/1/as/fmp4_audio_clear%2Cwebm_audio_clear%2Cwebm2_audio_clear%2Cfmp4_sd_hd_clear%2Cweb
m2_sd_hd_clear/spc/UWF9fzsu1v0HqwOvNCYrXj24M7bxvkYvnDD6Yns836vmOuE/vprv/1/pacing/0/itag_bl/376%2C377%2C384%2C385%2C612%2C613%2C617%2C619%2C623%2C628%2C655%2C656%2C660%2C662%2C666%2C671/keepa
live/yes/fexp/24007246/itag/0/playlist_type/DVR/sparams/expire%2Cei%2Cip%2Cid%2Csource%2Crequiressl%2Cxpc%2Chfr%2Cas%2Cspc%2Cvprv%2Citag%2Cplaylist_type/sig/AJfQdSswRgIhAOdcZZI1wY-fdCoNtrgK6
cg0kSTr5JaojFEBxEW2f1IvAiEA3x41tdDES651GPIiHk-_fKDG4pMGg9vyFul2A2LKOBs%3D"
[dashsegments] Total fragments: unknown (live)
[download] Destination: SATURDAY NIGHT CHAOS | GTA 5 RP [cz1FvQqs2Qw].f135.mp4
[debug] File locking is not supported. Proceeding without locking
[dashsegments] Total fragments: unknown (live)
[download] Destination: SATURDAY NIGHT CHAOS | GTA 5 RP [cz1FvQqs2Qw].f140.mp4
[debug] [youtube] [cz1FvQqs2Qw] Generating fragments for format 135
[debug] [youtube] [cz1FvQqs2Qw] Generating fragments for format 140
[download]   39.74MiB at  219.89KiB/s (00:03:29) (frag 220/3022)
[download]   37.62MiB at  196.51KiB/s (00:03:33) (frag 932/3022)[download] Got error: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the r
[download]  266.76MiB at  248.91KiB/s (00:22:04) (frag 1323/3022)
[download]  148.66MiB at  190.89KiB/s (00:22:03) (frag 3684/3684)

landscape updated fragments a few times already.

@krichbanana
Copy link
Contributor Author

I highly doubt that to be the case, and if it is, then it's an unrelated issue. Perhaps the relative popularity of the stream is causing YT to hiccup.

On this topic, I've recently discovered that if a stream is experiencing difficulties (say, OBS issues/crashes), then the timestamp can restart (as evidenced by the 't' of stats for nerds). Additionally, it's possible for formats to disappear and change (changed FPS? format? resolution?). Either of those cases will cause the current active download to fail to reload and eventually end the download. If you happen to have --keep-fragments, then restarting the stream download will erroneously reuse the downloaded fragments when it chases up to the current point again, which will result in missing part of the stream. This could theoretically be detectable and addressable, but it would be a lot of managing logic (complexity) for rather little gain.

If the stream goes offline temporarily, obviously yt-dlp doesn't like that, but that is another way for it to end "prematurely".

I haven't checked the download logic (or this issue) in ages so I don't really know what's happening anymore, but a retry sleep for everything helps for some of the more common issues (internet flickers, transient resolver issues). Other issues, you just have to keep an active eye on it.

@KamelittaOida
Copy link

KamelittaOida commented Feb 18, 2024

2024.02.18.2.mp4

sorry for the low bit rate. I forgot to set the quality for desktop. I don't want to redo it again :S <3
(github doesn't allow more than 10 MB anyway)

maybe we're talking about two different issues here then I will open a separate issue, if issue worthy.
I'm actually piggy-backing off the issue #9097

at the start you can see the audio portion is at 673 then it jumps to 762 until it catches up to the live stream.

that's two for two from my side already, no interruptions this time. it catches up to the audio part and it stops the audio, continues the video.

I wouldn't be surprised if original poster's stream from #9097 is a portrait one too.

@KamelittaOida
Copy link

KamelittaOida commented Feb 20, 2024

https://gofile.io/d/ywl4VD bit rate again too low. thought it was going to be enough.
(sorry with the rename freeze, I blanked there for a bit. haven't renamed in the console for a bit now)

is there any workaround for this?

How do I rename the output file without overwriting the fragments?

would I need to use batch for this somehow or can this be done within yt-dlp: to keep the fragments but keep overwriting the merge file in order to keep downloading it re-using the fragments.

can't use %(autonumber)s cause it will name the fragments too right?

@krichbanana
Copy link
Contributor Author

would I need to use batch for this somehow or can this be done within yt-dlp: to keep the fragments but keep overwriting the merge file in order to keep downloading it re-using the fragments.

frankly speaking, in bash this is what I do. I poll live_status after yt-dlp exits and if still live, try again, after I mv the old format files out of the way. On a minor note, if YT starts counting fragments from 1 again then using keep-fragments will be trouble, but honestly that case isn't very common.

You could try the advice listed in the comment here: #9043 (comment)

Your specific issue seems to be:
[youtube] YouTube said: ERROR - Precondition check failed.
[youtube] HTTP Error 400: Bad Request. Retrying (1/3)...

It seems to occur when page reextraction is triggered, and from downloading the refreshed android player JSON, if I'm not mistaken.

This does seem to be a new error. "Precondtion check" personally makes me think it may be related to cache or timestamping, likely internally on YouTube's end. If I'm not mistaken, format 135 is a 2K resolution? The download might be slowing the audio download (format 140) down. I noticed you didn't have any -N (parallels) flag in your second video. YouTube throttles DASH formats (a known issue), you may want to provide -N4 or greater to allow the downloads to catch up faster.

@KamelittaOida
Copy link

On a minor note, if YT starts counting fragments from 1 again then using keep-fragments will be trouble, but honestly that case isn't very common.

ok sorry for noob question. I'm not following. how do I continue then my download if I already have a merged file aka .m4a/.mp4 (from the fragments, because it starts merging after the fail), I don't somehow delete it and don't keep fragments? or: how do I not start from frag 1 or what's the opposite of fragment 1 method?

to my understanding ffmpeg won't even be able to create a file without --force-overwrites (which also rewrites fragments).
To complicate matters further with fragments, since you wouldn't be able to use %(title)s because if that changes, fragments will get ignored because yt-dlp will start creating new fragments because the fragment file names have changed.

That's why I'd like to plead to please look into portrait streams. This wouldn't be necessary if the download wasn't being discarded for whatever reason (if it's something you can fix on yt-dlp's end, considering landscape doesn't have this problem).

Your specific issue seems to be:
This does seem to be a new error. "Precondtion check" personally makes me think it may be related to cache or timestamping, likely internally on YouTube's end.

.... it was another portrait stream. Only happens in portrait. I invite you to find portrait streams with your mobile and try to download even one media stream (audio/video).
sometimes (1 of 10) it works, more often it doesn't.

The download might be slowing the audio download (format 140) down. I

doesn't matter if single or dual media streams.

format 135 is a 2K resolution?

it's low. 480 or so.
image

I guess the most feasible workaround for now is not to use --live-from-start.
because as of now I don't know how to fetch and compare file names in batch/bash. I can't make a separate folder for downloads only because if that channel happens to have more streams when i'm AFK, RIP the .mp4 files.

I will try -N4

@rattailgamer
Copy link

I have an interesting thing I just found out. I had/have the same problems. Since I have a bunch of old laptops laying around and a mac mini besides my Pc I decided to run some tests having them all run on the same stream with some different settings (all with --live-from-start) and see if I find something that works. long story short all Windows PCs constantly failed while on mac it worked and I have repeated it for 4 streams now. Successfully got the stream in a .mkv 1440p60 with audio and everything working everytime.
so somethings seems to be different with it and makes it work. I'm fairly sure it will be the same for linux, but I will give it a try in the next couple of days when I find time. I have no clue what the reason is, but maybe one of the smart people hear can figure out the problem with windows with that info. :)

@bashonly
Copy link
Member

@rattailgamer how did you install yt-dlp on each of the machines? could you show the output of yt-dlp -v (no URL) for each of them? (and note which ones failed vs. succeeded)

@rattailgamer
Copy link

@bashonly I have installed it via a gui to save time (Tartube) and their guide for each. While Tartube is gives out the full output including debugging mode unfortunately I can't enter commands manually or at least I haven't figured it out. But once I find time next week I will try to re do it all via ytdlp directly and send the logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug that is not site-specific
Projects
Status: youtube livestream
Development

No branches or pull requests

7 participants