flavioribeiro / nginx-audio-track-for-hls-module

:sound: Nginx module that generates audio track for HTTP Live Streaming (HLS) streams on the fly.
GNU General Public License v3.0
136 stars 17 forks source link

Controlling segment names in mapped mode, or how to use a cache in practice? #34

Closed wrosecrans closed 4 years ago

wrosecrans commented 4 years ago

So, I've got a bunch of video files, and I want to use mapped mode to dynamically make playlists that the user can play. This much I basically have working. A snippet of nginx access log doing a little test where I have two MP4 files in the JSON platlist basically looks like

"GET /api/1/manifest.mpd HTTP/1.1" "GET /api/1/init-c1-v1-x3.mp4 HTTP/1.1" "GET /api/1/init-c1-a1-x3.mp4 HTTP/1.1" "GET /api/1/fragment-1-v1-x3.m4s HTTP/1.1" "GET /api/1/fragment-1-a1-x3.m4s HTTP/1.1" "GET /api/1/fragment-2-v1-x3.m4s HTTP/1.1" "GET /api/1/fragment-2-a1-x3.m4s HTTP/1.1" "GET /api/1/init-c2-v1-x3.mp4 HTTP/1.1" "GET /api/1/init-c2-a1-x3.mp4 HTTP/1.1" "GET /api/1/fragment-3-v1-x3.m4s HTTP/1.1" "GET /api/1/fragment-3-a1-x3.m4s HTTP/1.1" "GET /api/1/fragment-4-v1-x3.m4s HTTP/1.1" "GET /api/1/fragment-4-a1-x3.m4s HTTP/1.1"

All of the segments that the client downloads are accessed through the API path, and they aren't named based on the source file. So, imagine I have something like

10 "intro" clips, 2 actual shows, 10 ads, and 10 ending clips annoyingly asking you to share like and subscribe and sign up for my patreon and whatnot. So, 32 total video files. Each time a user wants to watch one of my two shows, I randomly generate a playlist so they'll see a different assembly of intro/outro/ad with the show every time they watch it, etc.

How on earth do you actually stick a caching CDN in front of that? I only have two actual shows, but since they are accessed through some dynamic playlist service, the exact same segments will have different URL's, and the CDN won't have any way to dedupe it. Each URL variation will only be watched once, with a cache hitrate of zero, even if the underlying shows are very popular.

So, Wat do? If I have 10,000 views, I want to cache 32 video files worth of content, not 40,000.

wrosecrans commented 4 years ago

And, whoops. I posted this question in the wrong repository. I meant to post it in the kaltura/nginx-vod-module repository. Looks like I mixed up my tabs when posting. Sorry about that & please ignore.

flavioribeiro commented 4 years ago

all good!