kaltura / nginx-vod-module

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

Use audio from current ABR file #714

Open eTiMaGo opened 7 years ago

eTiMaGo commented 7 years ago

Hi,

Firstly, thanks for this awesome nginx module, I'm having a lot of fun tweaking it just as I need it :)

But a question. I have several video files for ABR, from 360p to 1080p. But each file also have the soundtrack at a different bitrate, i.e. 64kbps mono on 360p, to 256kbps stereo on 1080p

But, when generating a HLS playlist, only the soundtracks from the first file (so, the 64k mono version) are listed.

Is there a way to have sets for audio ABR as well?

erankor commented 7 years ago

The default behavior of the module is to mux each video with the audio of the same file. Most probable cause for the behavior you describe is that the higher bitrate audios are from an incompatible format. If that is the case, the module tries to match the video to whatever it has, which is the low mono audio. If you think the higher audio tracks are valid, please send a sample URL and your nginx.conf

eTiMaGo commented 7 years ago

Hi,

config:

`server { listen 80;

    # vod settings
    vod_mode local;
    vod_last_modified 'Sun, 19 Nov 2000 08:52:00 GMT';
    vod_last_modified_types *;

    # vod caches
    vod_metadata_cache metadata_cache 512m;
    vod_response_cache response_cache 128m;

    # gzip manifests
    gzip on;
    gzip_types application/vnd.apple.mpegurl;

    # file handle caching / aio
    open_file_cache          max=1000 inactive=5m;
    open_file_cache_valid    2m;
    open_file_cache_min_uses 1;
    open_file_cache_errors   on;
    aio on;

    location / {
        root /var/www/html/;
    }

    location /status {

        vod_status;
    }

    location /vodmux/ {
        alias /mnt/ds/;
        vod hls; 

        vod_hls_absolute_master_urls off;
        vod_hls_absolute_index_urls off;
        vod_hls_absolute_iframe_urls off;
        vod_hls_master_file_name_prefix playlist;
        vod_hls_index_file_name_prefix chunklist;

        vod_hls_force_unmuxed_segments on;
        vod_align_segments_to_key_frames on;

        add_header Access-Control-Allow-Headers '*';
        add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
        add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
        add_header Access-Control-Allow-Origin '*';

        expires 100d;
    }

    location /vod/ {
        proxy_pass              http://localhost/vodmux/;
        proxy_set_header        Host $host;
        proxy_cache             STATIC;
        proxy_cache_valid       200  7d;
        proxy_cache_lock        on;
        add_header              X-Cached $upstream_cache_status;

    }               

}

`

As for the URL, I am testing over a local network without access from outside. but this is the layout:

http://10.99.10.28/vod/movie/deathnote1/,360p.mp4,480p.mp4,720p.mp4,1080p.mp4,lang/tha/sub-tha.srt,lang/eng/sub-eng.vtt,.urlset/playlist.m3u8

And the Playlist generated:

`#EXTM3U

EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio0",LANGUAGE="en",NAME="English",AUTOSELECT=YES,DEFAULT=YES,CHANNELS="1",URI="chunklist-f1-a1.m3u8"

EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio0",LANGUAGE="th",NAME="ภาษาไทย",AUTOSELECT=NO,DEFAULT=NO,CHANNELS="1",URI="chunklist-f1-a2.m3u8"

EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio0",LANGUAGE="ja",NAME="日本語",AUTOSELECT=NO,DEFAULT=NO,CHANNELS="1",URI="chunklist-f1-a3.m3u8"

EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs0",LANGUAGE="th",NAME="ภาษาไทย",AUTOSELECT=YES,DEFAULT=YES,URI="chunklist-f5.m3u8"

EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs0",LANGUAGE="en",NAME="English",AUTOSELECT=NO,DEFAULT=NO,URI="chunklist-f6.m3u8"

EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=377318,RESOLUTION=640x360,FRAME-RATE=23.974,CODECS="avc1.42c01f,mp4a.40.2",AUDIO="audio0",SUBTITLES="subs0"

chunklist-f1-v1.m3u8

EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=540533,RESOLUTION=852x480,FRAME-RATE=23.974,CODECS="avc1.42c028,mp4a.40.2",AUDIO="audio0",SUBTITLES="subs0"

chunklist-f2-v1.m3u8

EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1027272,RESOLUTION=1280x720,FRAME-RATE=23.974,CODECS="avc1.4d4032,mp4a.40.2",AUDIO="audio0",SUBTITLES="subs0"

chunklist-f3-v1.m3u8

EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=3577413,RESOLUTION=1920x1080,FRAME-RATE=23.974,CODECS="avc1.640033,mp4a.40.2",AUDIO="audio0",SUBTITLES="subs0"

chunklist-f4-v1.m3u8

EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=24383,RESOLUTION=640x360,CODECS="avc1.42c01f",URI="iframes-f1-v1.m3u8"

EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=36549,RESOLUTION=852x480,CODECS="avc1.42c028",URI="iframes-f2-v1.m3u8"

EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=87608,RESOLUTION=1280x720,CODECS="avc1.4d4032",URI="iframes-f3-v1.m3u8"

EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=251350,RESOLUTION=1920x1080,CODECS="avc1.640033",URI="iframes-f4-v1.m3u8"`

erankor commented 7 years ago

Ah, you didn't mention it was multilingual... I don't think HLS supports adaptive audio in this case, so you get one audio per language. However, the module does output multiple audio sets if you have multiple audio codecs (e.g. AAC, AC-3, EAC-3), but I'm quite sure the device does not switch between such sets during playback - it either supports EAC-3 and uses it or it doesn't.

eTiMaGo commented 7 years ago

Ah, my bad!

But from what I understand, it is a supported feature. From Flowplayer's hls.js docs:

audioABR | false | If multiple audio groups are present the hlsjs engine will load only one by default, regardless of the current video level. If this option is set to true the corresponding audio track will be loaded on level switch.

which links to this section of the HLS draft specs: https://tools.ietf.org/html/draft-pantos-http-live-streaming-23#section-4.3.4.1.1

specifically:

A Playlist MAY contain multiple Groups of the same TYPE in order to provide multiple encodings of that media type. If it does so, each Group of the same TYPE MUST have the same set of members, and each corresponding member MUST have identical attributes with the exception of the URI and CHANNELS attributes.

erankor commented 7 years ago

I never saw such a manifest in Apple's samples, I think by 'encodings' they may have referred only to the use case of multiple audio codecs. I sent them a question about this now. But anyway, this feature is currently not supported.

eTiMaGo commented 7 years ago

Understood, just one for the "wishlist" :)

erankor commented 7 years ago

Just to update this thread that I got the below response from Apple -

Got a question – is it possible to have multiple audio bitrates as well as alternative audio renditions in the same manifest? I saw the Apple advanced sample that has multiple audio groups – AAC, AC-3 & EAC-3, but the question is whether it’s ok to have, let’s say, an audio group for AAC 64kbps, one for AAC 128kbps etc.?

Yes. You do need to fill out the entire (two-dimensional, in this case, but it can be three-dimensional with multiple codecs) ladder. That is to say that there must be a group per bitrate, and each group in each bitrate must have a complete set of members.

Will an Apple device switch between such groups adaptively during playback or will it select one of them when playback starts?

Yes. What you need to do is associate each audio bitrate group with one or more Variant Streams (EXT-X-STREAM-INF tags). So for instance, your 64 kbps HE-AAC group might go with the 400 kbps and 800 kbps video variants, and the 128 kbps AAC-LC group might go with all the higher video variants. When the player switches from, say, the 400 kbps tier to the 2 Mbps tier, it will also switch from 64 kbps audio to 128 kbps audio.

I will leave this issue open, but don't think we'll be implementing this feature in the near future.

eTiMaGo commented 7 years ago

Cool, thanks for the update, will you post here when this is implemented?

erankor commented 7 years ago

Yes, but as I wrote above, probably won't happen soon