kaltura / nginx-vod-module

NGINX-based MP4 Repackager
GNU Affero General Public License v3.0
2k stars 439 forks source link

unmuxed cmaf hls trun version #1547

Open kidoubled opened 1 month ago

kidoubled commented 1 month ago

using unmuxed cmaf in hls, getting a trun version of 0. I believe I've deduced this is leveraging the dash packager, and if I can set the media_set->version >=2, i'd get trun version 1. https://github.com/kaltura/nginx-vod-module/blob/26f06877b0f2a2336e59cda93a3de18d7b23a3e2/vod/dash/dash_packager.c#L1889

I think this could be sourced from the submodule_context->request params, when in mapped mode, but after that, I lose the path. https://github.com/kaltura/nginx-vod-module/blob/master/ngx_http_vod_module.c#L5286

hoping I'm on the right track, and that someone can help me with the rest. Thanks in advance

kidoubled commented 3 weeks ago

I found the version parsing from the filename https://github.com/kaltura/nginx-vod-module/blob/master/ngx_http_vod_request_parse.c#L522

which is set here for dash: https://github.com/kaltura/nginx-vod-module/blob/26f06877b0f2a2336e59cda93a3de18d7b23a3e2/vod/dash/dash_packager.c#L373 but I can't see how this would be set for unmuxed hls

kidoubled commented 3 weeks ago

@erankor would checking for track count =1 and adding a -x3 in one of these locations be a good solution to how to get unmixed cmaf hls to use trun version 1 with signed pts delay? https://github.com/kaltura/nginx-vod-module/blob/master/vod/manifest_utils.c#L399 https://github.com/kaltura/nginx-vod-module/blob/master/vod/hls/m3u8_builder.c#L206

alternatively, perhaps I could get away with using a sub_filter to turn .m4s into -x3.m4s?

kidoubled commented 3 weeks ago

testing the subfilter approach using a config similar to this:

location /cmaf/hls/ {
            vod hls;
            vod_hls_force_unmuxed_segments on;
            vod_hls_container_format fmp4;

            sub_filter '.m4s' '-x3.m4s';
            sub_filter_once off;
            sub_filter_types application/vnd.apple.mpegurl;
        }

which seems to be working. I'd be interested to know if there's a better approach.

erankor commented 2 weeks ago

Hi @kidoubled, out of curiosity, why do you care if it's version 0 or 1? The URL version (-x3) was added for backward compatibility - at some point I changed the trun version from 0 to 1, but I wanted it to affect only new streams - so that the player won't get a mix of version 0 & version 1. Btw, I implemented a solution similar to your solution here - https://github.com/kaltura/nginx-vod-module/issues/985#issuecomment-492524615

erankor commented 2 weeks ago

In our live packager (a more recent project, using some of the code initially written here), I'm always using version 1 for video - https://github.com/kaltura/media-framework/blob/master/nginx-pckg-module/src/media/mp4/mp4_muxer.c#L316

kidoubled commented 2 weeks ago

@erankor some newer players don't work well with version 0 / without the signed pts delay... always using version 1 for video makes a great deal of sense these days, and I can see that would occur with almost all modes of operation within the packager, except unmuxed hls, because that ends up using the dash packager code, but without adding the -x3 modifier to the uris. I'll plan to use the subfilter, but would be open to working on a PR if you had thoughts about the best way to address. Is the "right way" to fix this removing the legacy backwards compatibility at this point?

Also, I had noticed https://github.com/kaltura/nginx-vod-module/issues/985#issuecomment-492524615 and used it as inspiration for my approach above. Thanks for the project and all the community support over the years.