axiomatic-systems / Bento4

Full-featured MP4 format, MPEG DASH, HLS, CMAF SDK and tools
http://www.bento4.com
2k stars 482 forks source link

HLS audio group for different quality videos (e.g. stereo for low quality video, surround for high quality video) #519

Open st1ng2 opened 4 years ago

st1ng2 commented 4 years ago

Is audio grouping for video feature implemented? If yes, give an example please, I can not find (or understand) from the documentation. I am looking for command, that allows grouping of DASH/HLS audio for different quality videos. EXAMPLE HLS

EXT-X-MEDIA:TYPE=AUDIO,URI="audio/en_high/en_high.m3u8",GROUP-ID="surround",LANGUAGE="en",NAME="English",AUTOSELECT=YES,CHANNELS="6"

EXT-X-MEDIA:TYPE=AUDIO,URI="audio/ru_high/ru_high.m3u8",GROUP-ID="surround",LANGUAGE="ru",NAME="Русский",DEFAULT=YES,AUTOSELECT=YES,CHANNELS="6"

EXT-X-MEDIA:TYPE=AUDIO,URI="audio/en_low/en_low.m3u8",GROUP-ID="stereo",LANGUAGE="en",NAME="English",AUTOSELECT=YES,CHANNELS="2"

EXT-X-MEDIA:TYPE=AUDIO,URI="audio/ru_low/ru_low.m3u8",GROUP-ID="stereo",LANGUAGE="ru",NAME="Русский",DEFAULT=YES,AUTOSELECT=YES,CHANNELS="2"

EXT-X-STREAM-INF:BANDWIDTH=3514211,AVERAGE-BANDWIDTH=1930570,CODECS="avc1.640020,mp4a.40.2",RESOLUTION=1280x536,FRAME-RATE=23.976,AUDIO="surround",SUBTITLES="subs"

video/hd/hd.m3u8

EXT-X-STREAM-INF:BANDWIDTH=1883250,AVERAGE-BANDWIDTH=954387,CODECS="avc1.64001e,mp4a.40.2",RESOLUTION=721x302,FRAME-RATE=23.976,AUDIO="stereo",SUBTITLES="subs"

video/sd/sd.m3u8

barbibulle commented 4 years ago

Sorry, the documentation for this isn't really there yet (it is something I need to fix urgently!). But what you want may be possible in some form. If you want multiple audio groups, you need to use the label feature. For each audio input, you can set a label value, using the [+label=xxx] prefix to your input audio file (from a command shell, don't forget to quote your command line arguments, because the special characters in the prefix will confuse your shell otherwise). Audio tracks with the same label will be kept together, even if they have the same language (by default, only one track per language is kept). But I realize that's not exactly what you're looking for, since in your case you want different audio groups for different bitrates. That may be a bit odd, as I'm not sure how the player would behave if it started with one bitrate, and its associated audio group, then switch to a different bitrate that had a different audio group, in the case where the audio groups didn't have exactly the same sets of audio tracks... I'll look into the spec a bit more to see if there are any restrictions for this. Depending on what I find, I may add some option to support this type of advanced mapping.

st1ng2 commented 4 years ago

Thanks for the answer. I think feature I am asking is an important aspect of HLS. For example if you want create HLS or DASH videos with different resolutions, you probably want different quality audio also. Because you can't put 4K HDR video with low quality stereo audio or conversely you can't put 5.1 high quality audio for low quality video. I can't say about other players, but I think most good web players support it. For example player I am using already supports (PlayerJS). FFmpeg also can output HLS with multi language audio groups for different quality resolution videos using -var_stream_map command. Here you can see another example of m3u8 file with multi language audio group https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8 Spec: https://tools.ietf.org/html/rfc8216#section-4.3.4.1.1 Thanks for attention.