Rate-limit save downloads so they no longer starve playback
This commit is contained in:
@@ -43,6 +43,11 @@ const PORT = parseInt(process.env.PORT || '3000', 10);
|
|||||||
const APP_VERSION = process.env.APP_VERSION || '1.0.0';
|
const APP_VERSION = process.env.APP_VERSION || '1.0.0';
|
||||||
const YTDLP = process.env.YTDLP_PATH || 'yt-dlp';
|
const YTDLP = process.env.YTDLP_PATH || 'yt-dlp';
|
||||||
const FFMPEG = process.env.FFMPEG_PATH || 'ffmpeg';
|
const FFMPEG = process.env.FFMPEG_PATH || 'ffmpeg';
|
||||||
|
// Cap for server-side SAVE downloads. yt-dlp with -N 4 pinned the homelab's
|
||||||
|
// whole downlink (~7.6 MB/s measured), and since /api/play fetches its own
|
||||||
|
// googlevideo slices over the same link, one long save starved every
|
||||||
|
// concurrent playback (stalled at ~27 s, 11 KB/s). Leave headroom.
|
||||||
|
const DOWNLOAD_RATE = process.env.DOWNLOAD_RATE || '3M';
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// BUILD_TAG — must be DETERMINISTIC across restarts of identical code.
|
// BUILD_TAG — must be DETERMINISTIC across restarts of identical code.
|
||||||
@@ -677,7 +682,7 @@ async function ytdlpDownloadResponse(videoId, fp, formatArgs) {
|
|||||||
`https://www.youtube.com/watch?v=${videoId}`,
|
`https://www.youtube.com/watch?v=${videoId}`,
|
||||||
'--no-warnings', '--no-playlist',
|
'--no-warnings', '--no-playlist',
|
||||||
...formatArgs,
|
...formatArgs,
|
||||||
'-N', '4',
|
'--limit-rate', DOWNLOAD_RATE,
|
||||||
'-o', tmp,
|
'-o', tmp,
|
||||||
]);
|
]);
|
||||||
size = statSync(tmp).size;
|
size = statSync(tmp).size;
|
||||||
@@ -730,7 +735,7 @@ async function ytdlpEditedDownloadResponse(videoId, fp, keep) {
|
|||||||
'--no-warnings', '--no-playlist',
|
'--no-warnings', '--no-playlist',
|
||||||
'-f', 'bv*[height<=720][ext=mp4]+ba[ext=m4a]/bv*[height<=720]+ba/b[ext=mp4]/b',
|
'-f', 'bv*[height<=720][ext=mp4]+ba[ext=m4a]/bv*[height<=720]+ba/b[ext=mp4]/b',
|
||||||
'--merge-output-format', 'mp4',
|
'--merge-output-format', 'mp4',
|
||||||
'-N', '4',
|
'--limit-rate', DOWNLOAD_RATE,
|
||||||
'-o', srcTmp,
|
'-o', srcTmp,
|
||||||
]);
|
]);
|
||||||
// 2) Trim + concat the keep segments into the final custom video.
|
// 2) Trim + concat the keep segments into the final custom video.
|
||||||
|
|||||||
Reference in New Issue
Block a user