commit 9f29be868acffe53d7853fc1724cc5a95abe3bde
parent b244a530071d5ce672475c14f0889eacec4ff288
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sun, 4 Oct 2026 16:17:31 -0400
common: video_720 tries split pairs before single-file rungs
Split H.264 at 720, then at 480, then any codec split at or under 720, then
the single-file rungs at or under 720, then the last resort. A 720p VP9 pair
now wins over a 360p single-file mp4. clipFormatSelector is unchanged byte
for byte; both are built from shared split / single-file rung helpers.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
2 files changed, 41 insertions(+), 18 deletions(-)
diff --git a/common/ytdlp/downloadFormat.test.ts b/common/ytdlp/downloadFormat.test.ts
@@ -23,19 +23,27 @@ const CLIP_720 =
"bv*[ext=mp4][height<=720]+ba[ext=m4a]/" +
"b[ext=mp4][height<=720]/" +
"b[height<=720]";
-const CLIP_480 = CLIP_720.replaceAll("720", "480");
test("clipFormatSelector is the selector umtool uses, and the old import path still serves it", () => {
assert.equal(clipFormatSelector(720), CLIP_720);
assert.equal(reexported, clipFormatSelector);
});
-test("video_720: the H.264 720 rungs, the 480 rungs, any codec at or under 720, then the last resort", () => {
+test("video_720: split H.264 at 720, then 480, then any codec split ≤720, then single-file ≤720, then the last resort", () => {
assert.equal(VIDEO_720_PRESET, "video_720");
assert.ok(isDownloadFormatPreset("video_720"));
assert.ok(DOWNLOAD_FORMAT_PRESETS.includes("video_720"));
assert.equal(DOWNLOAD_FORMAT_LABELS.video_720, "Video 720p (H.264, for clips/editing)");
- const expected = `${CLIP_720}/${CLIP_480}/bv*[height<=720]+ba/b[height<=720]/bv*+ba/b`;
+ const expected = [
+ "bv*[vcodec^=avc1][height<=720]+ba[acodec^=mp4a]",
+ "bv*[ext=mp4][height<=720]+ba[ext=m4a]",
+ "bv*[vcodec^=avc1][height<=480]+ba[acodec^=mp4a]",
+ "bv*[ext=mp4][height<=480]+ba[ext=m4a]",
+ "bv*[height<=720]+ba",
+ "b[ext=mp4][height<=720]",
+ "b[height<=720]",
+ "bv*+ba/b",
+ ].join("/");
assert.equal(resolveDownloadFormatSelector("video_720", null), expected);
// An explicit preset ignores the platform, as every explicit preset does.
assert.equal(resolveDownloadFormatSelector("video_720", "odysee"), expected);
diff --git a/common/ytdlp/downloadFormat.ts b/common/ytdlp/downloadFormat.ts
@@ -56,28 +56,38 @@ export const DOWNLOAD_FORMAT_LABELS: Record<DownloadFormatPreset, string> = {
// that fetched must be the same file, or the two caches diverge.
//
// Lives here (not in fetchWindowManaged.ts, which re-exports it) because the
-// "video_720" preset below is built from it, and a persist must not import the
-// clip-window fetch to learn a selector.
+// "video_720" preset below is built from its rungs, and a persist must not
+// import the clip-window fetch to learn a selector.
export function clipFormatSelector(maxHeight: number): string {
+ return [...clipSplitRungs(maxHeight), ...clipSingleFileRungs(maxHeight)].join(
+ "/",
+ );
+}
+
+// The clip selector's two halves. SPLIT: separate H.264 video + AAC audio
+// streams, merged. SINGLE-FILE: one file carrying both (mp4 first). Split
+// first, because a single-file format at these heights is often a low rung
+// (YouTube's 360p mp4).
+function clipSplitRungs(maxHeight: number): string[] {
return [
`bv*[vcodec^=avc1][height<=${maxHeight}]+ba[acodec^=mp4a]`,
`bv*[ext=mp4][height<=${maxHeight}]+ba[ext=m4a]`,
- `b[ext=mp4][height<=${maxHeight}]`,
- `b[height<=${maxHeight}]`,
- ].join("/");
+ ];
+}
+
+function clipSingleFileRungs(maxHeight: number): string[] {
+ return [`b[ext=mp4][height<=${maxHeight}]`, `b[height<=${maxHeight}]`];
}
// The height "video_720" asks for, and the rung it falls back to.
export const VIDEO_720_MAX_HEIGHT = 720;
export const VIDEO_720_FALLBACK_HEIGHT = 480;
-// The codec-agnostic rungs of "video_720", after the H.264 ones: a source
-// whose only video at or under 720p is VP9 or AV1 still lands at or under 720p
-// rather than falling through to the best (possibly 4K) file.
-export const VIDEO_720_ANY_CODEC_RUNGS = [
- `bv*[height<=${VIDEO_720_MAX_HEIGHT}]+ba`,
- `b[height<=${VIDEO_720_MAX_HEIGHT}]`,
-] as const;
+// The codec-agnostic split rung of "video_720", after the H.264 split ones: a
+// source whose only video at or under 720p is VP9 or AV1 still lands at or
+// under 720p, at its best such height — not on a 360p single-file mp4, and not
+// on the best (possibly 4K) file.
+export const VIDEO_720_ANY_CODEC_RUNG = `bv*[height<=${VIDEO_720_MAX_HEIGHT}]+ba`;
// The last rung of "video_720": anything at all. Reached only when the source
// has nothing at or under 720p, so a file above 720p is possible — the
@@ -103,10 +113,15 @@ export function resolveDownloadFormatSelector(
case "bestvideo_audio":
return ORIGINAL_SOURCE_FORMAT_SELECTOR;
case "video_720":
+ // NOT clipFormatSelector(720) whole: its single-file rungs would take a
+ // 360p mp4 before a 720p VP9 split pair is ever tried. Split H.264 at
+ // 720, then at 480, then any codec split at or under 720, then the
+ // single-file rungs, then anything (logged).
return [
- clipFormatSelector(VIDEO_720_MAX_HEIGHT),
- clipFormatSelector(VIDEO_720_FALLBACK_HEIGHT),
- ...VIDEO_720_ANY_CODEC_RUNGS,
+ ...clipSplitRungs(VIDEO_720_MAX_HEIGHT),
+ ...clipSplitRungs(VIDEO_720_FALLBACK_HEIGHT),
+ VIDEO_720_ANY_CODEC_RUNG,
+ ...clipSingleFileRungs(VIDEO_720_MAX_HEIGHT),
LAST_RESORT_FORMAT_SELECTOR,
].join("/");
case "auto":