You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Idea: precache upcoming video to a USB drive so playback survives a bad connection
#2116
Floating an idea before any code. On a spotty connection (or a big remux over so-so wifi), playback stalls whenever the network dips. ExoPlayer only buffers about 50 seconds max ahead in memory (but the reality is that some can't even playback the remux at all without preloading), and a lot of TV boxes don't have much internal storage to spare. Even if they did, killing a 300$ shield sucks. A USB drive is cheap, and free a lot of the time.
Rough idea:
In the server plugin, the admin can turn on "precache to USB storage".
Each device opts in since it needs a drive plugged in. It can set how much should be cached before playback starts.
On the device, you enable it and pick the drive(s) Wholphin can use.
During playback Wholphin downloads ahead of the playhead onto the drive and the player reads from there, so a dropout just eats into the lead instead of stalling. Could even have an optional feature to dynamically change the bitrate based on prefill speed so that its smooth no matter what.
Nothing gets cleared, it works like an NVR: when the drive fills up, the oldest stuff gets overwritten. Side bonus, resuming or rewatching something recent plays straight off the drive.
On the client side this seems to map onto Media3 pretty directly: a disk cache on the drive with least-recently-used eviction (that's the NVR part), plus a background job that keeps writing ahead of the playhead. The cache would need to be keyed by item/media source instead of URL, since stream URLs change every session.
Stuff I'm unsure about:
Can we even write to USB? Android's docs say app-specific external storage doesn't include USB flash drives, and the folder picker is flaky or missing on a lot of TV devices. Some boxes do mount USB as normal storage. Has anyone tested this across devices? If it only works on some, the setting should probably just hide itself where it can't work.
My 2cents - this shouldn't be a blocker, App based permissions allow "File Storage" which should bypass any issues.
How much to cache before starting. I was thinking a fixed percentage, like 3%. That's quick for episodes, slower for movies. But what you actually need depends on your connection vs. the file's bitrate. A 2-hour 20 Mbps movie on a 40 Mbps connection needs almost nothing up front; on 15 Mbps it needs ~30 minutes cached or it'll stall later anyway. Maybe "keep at least X minutes ahead" plus measuring throughput beats a percentage?
Transcoding. I'd heard Jellyfin won't let a client get more than ~120 seconds ahead when transcoding, which made me think the plugin might need to tweak something. From poking at the server source I'm not sure that's true:
Throttling is off by default. When it's on, it pauses ffmpeg once it's more than N seconds (default 180) ahead of the last segment the client downloaded, not the playback position. So a client that keeps pulling segments drags the transcode along instead of getting capped.
What does bite: if you request a segment more than ~24s past where ffmpeg currently is, the server restarts the transcode at that point. So prefetch has to walk forward in order, and can only get as far ahead as the transcode is fast.
So maybe nothing needed server-side, or maybe just a warning in the plugin if throttling is on? Anyone know more? Either way I'd probably start with direct play only.
Drive wear and privacy. At 20 Mbps that's ~9 GB written per hour, which will chew through a cheap thumb drive. And the cached video sits on a drive anyone can unplug. Encrypt it with a key that stays on the device?
Multiple drives. Worth it, or one drive for a first version? Splitting one video across drives means unplugging either one breaks it, so I'd lean toward each item living on one drive.
"Drive must be empty." That was my first thought, but it's probably simpler for Wholphin to own one folder on the drive and never touch anything outside it.
Probably ExoPlayer only to start, MPV would need its own approach.
Would anyone else use this? Mostly curious whether people with flaky internet or remote servers would. I suppose it could also help boxes that had very low RAM ceilings.
AI Disclosure: This post was written with the help of AI. The idea was 100% fleshed out by my brain/hand though and only the word salad is the toaster.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Description
Floating an idea before any code. On a spotty connection (or a big remux over so-so wifi), playback stalls whenever the network dips. ExoPlayer only buffers about 50 seconds max ahead in memory (but the reality is that some can't even playback the remux at all without preloading), and a lot of TV boxes don't have much internal storage to spare. Even if they did, killing a 300$ shield sucks. A USB drive is cheap, and free a lot of the time.
Rough idea:
On the client side this seems to map onto Media3 pretty directly: a disk cache on the drive with least-recently-used eviction (that's the NVR part), plus a background job that keeps writing ahead of the playhead. The cache would need to be keyed by item/media source instead of URL, since stream URLs change every session.
Stuff I'm unsure about:
How much to cache before starting. I was thinking a fixed percentage, like 3%. That's quick for episodes, slower for movies. But what you actually need depends on your connection vs. the file's bitrate. A 2-hour 20 Mbps movie on a 40 Mbps connection needs almost nothing up front; on 15 Mbps it needs ~30 minutes cached or it'll stall later anyway. Maybe "keep at least X minutes ahead" plus measuring throughput beats a percentage?
Transcoding. I'd heard Jellyfin won't let a client get more than ~120 seconds ahead when transcoding, which made me think the plugin might need to tweak something. From poking at the server source I'm not sure that's true:
So maybe nothing needed server-side, or maybe just a warning in the plugin if throttling is on? Anyone know more? Either way I'd probably start with direct play only.
Drive wear and privacy. At 20 Mbps that's ~9 GB written per hour, which will chew through a cheap thumb drive. And the cached video sits on a drive anyone can unplug. Encrypt it with a key that stays on the device?
Multiple drives. Worth it, or one drive for a first version? Splitting one video across drives means unplugging either one breaks it, so I'd lean toward each item living on one drive.
"Drive must be empty." That was my first thought, but it's probably simpler for Wholphin to own one folder on the drive and never touch anything outside it.
Probably ExoPlayer only to start, MPV would need its own approach.
Would anyone else use this? Mostly curious whether people with flaky internet or remote servers would. I suppose it could also help boxes that had very low RAM ceilings.
AI Disclosure: This post was written with the help of AI. The idea was 100% fleshed out by my brain/hand though and only the word salad is the toaster.
All reactions