kaltura / nginx-vod-module

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

Export audio language in HLS for a single audio file in mapped mode #1324

Open SebastienChauvin opened 2 years ago

SebastienChauvin commented 2 years ago

We have a setup where we need to always specify the audio language in HLS.

With vod_hls_force_unmuxed_segments on and


    {
      "clips": [
        {
          "type": "source",
          "path": "a.mp4"
        },
        {
          "type": "source",
          "path": "a.mp4"
        }
      ],
      "withAccessibility": false,
      "language": "fra",
      "label": "Francais"
    },
[...]

we can extract the audio and have the folowing HLS:

#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio0",NAME="default",AUTOSELECT=YES,DEFAULT=YES,CHANNELS="2",URI="index-f1-a1.m3u8"

...video variants
...

With his setup I have the following issue: The audio track does not contain a correct NAME and does not contain a LANGUAGE so my client does not know the language of the main track (would be much easier for statistics) I would expect:

#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio0",NAME="Français",LANGUAGE="fr",AUTOSELECT=NO,DEFAULT=NO,CHANNELS="2",URI="index-f7-a1.m3u8"

...video variants

What works: If I use vod_hls_force_unmuxed_segments off and describe multiple audios, I have correct HLS

#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio0",NAME="Français",LANGUAGE="fr",AUTOSELECT=NO,DEFAULT=NO,CHANNELS="2",URI="index-f7-a1.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio0",NAME="Deutsch",LANGUAGE="de",AUTOSELECT=NO,DEFAULT=NO,CHANNELS="2",URI="index-f8-a1.m3u8"

...video variants

But this does not work for single audio.

Did I miss something ? I do not mind fork / proposing a PR but I am a bit lost here maybe this is an HLS limitation I am not aware of.

erankor commented 2 years ago

You didn't miss anything :) that's the behavior of the module. The initial idea was that if there is a single audio, the user has no choice, and then it doesn't matter what we put there. But we have recently got a request similar to what you wrote here - in Apple TV the audio is shown as 'Unknown' and some people don't like that. I'm not sure if we can just change the behavior, we'll need to run some tests... we may need to add some directive to control it.

SebastienChauvin commented 2 years ago

[...] I'm not sure if we can just change the behavior, we'll need to run some tests... we may need to add some directive to control it.

Thanks a bunch for the reply and knowing that I am not alone helps me !

As said I do not mind trying something on my side, I will start looking at the code but any lead / idea on what to change will be welcome.

erankor commented 2 years ago

You can look for references to the multi_audio flag, e.g. HLS - https://github.com/kaltura/nginx-vod-module/blob/95cdcbd753513e77f94ce666f0cab5b5abcae888/vod/hls/m3u8_builder.c#L989 DASH - https://github.com/kaltura/nginx-vod-module/blob/8e7268a8239eb953c97a91b4668e79e077edd51f/vod/dash/dash_packager.c#L861

This flag is set when multiple audio labels exist in the set, and this is currently the criteria for using the label. You'll probably just need to change these conditions to check for label.len > 0 instead.

SebastienChauvin commented 2 years ago

So I have tried a quick fix on our branch that seems to work fine for our purpose.

I have also started looking into a configuration, something to the tune of:

vod_map_label_language_for_single_audio

  • syntax: vod_map_label_language_for_single_audio on/off
  • default: off
  • context: http, server, location

When enabled the server outputs label and language even when there is only a single audio track When disabled the server outputs label 'default' and no language when there is only a single audio track

But I got stuck in the way the modules are structured: the m3u8_builder only sees the m3u8_config_t conf not the top level one and dash has a similar issue. We could either forward this general config to both m3u8 and dash builders, or rename this multi_audio flag if that's the only point where it is used.

Anyhow, thanks for the help, we seem to have a solution on our fork and I will try to come back to this for a better proposition.