You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
4.1 KiB

  1. # Multiple Alternative Audio Tracks
  2. ## General
  3. m3u8 manifests with multiple audio streams will have those streams added to `video.js` in an `AudioTrackList`. The `AudioTrackList` can be accessed using `player.audioTracks()` or `tech.audioTracks()`.
  4. ## Mapping m3u8 metadata to AudioTracks
  5. The mapping between `AudioTrack` and the parsed m3u8 file is fairly straight forward. The table below shows the mapping
  6. | m3u8 | AudioTrack |
  7. |---------|------------|
  8. | label | label |
  9. | lang | language |
  10. | default | enabled |
  11. | ??? | kind |
  12. | ??? | id |
  13. As you can see m3u8's do not have a property for `AudioTrack.id`, which means that we let `video.js` randomly generate the id for `AudioTrack`s. This will have no real impact on any part of the system as we do not use the `id` anywhere.
  14. The other property that does not have a mapping in the m3u8 is `AudioTrack.kind`. It was decided that we would set the `kind` to `main` when `default` is set to `true` and in other cases we set it to `alternative` unless the track has `characteristics` which include `public.accessibility.describes-video`, in which case we set it to `main-desc` (note that this `kind` indicates that the track is a mix of the main track and description, so it can be played *instead* of the main track; a track with kind `description` *only* has the description, not the main track).
  15. Below is a basic example of a mapping
  16. m3u8 layout
  17. ``` JavaScript
  18. {
  19. 'media-group-1': [{
  20. 'audio-track-1': {
  21. default: true,
  22. lang: 'eng'
  23. },
  24. 'audio-track-2': {
  25. default: false,
  26. lang: 'fr'
  27. },
  28. 'audio-track-3': {
  29. default: false,
  30. lang: 'eng',
  31. characteristics: 'public.accessibility.describes-video'
  32. }
  33. }]
  34. }
  35. ```
  36. Corresponding AudioTrackList when media-group-1 is used (before any tracks have been changed)
  37. ``` JavaScript
  38. [{
  39. label: 'audio-tracks-1',
  40. enabled: true,
  41. language: 'eng',
  42. kind: 'main',
  43. id: 'random'
  44. }, {
  45. label: 'audio-tracks-2',
  46. enabled: false,
  47. language: 'fr',
  48. kind: 'alternative',
  49. id: 'random'
  50. }, {
  51. label: 'audio-tracks-3',
  52. enabled: false,
  53. language: 'eng',
  54. kind: 'main-desc',
  55. id: 'random'
  56. }]
  57. ```
  58. ## Startup (how tracks are added and used)
  59. > AudioTrack & AudioTrackList live in video.js
  60. 1. `HLS` creates a `PlaylistController` and watches for the `loadedmetadata` event
  61. 1. `HLS` parses the m3u8 using the `PlaylistController`
  62. 1. `PlaylistController` creates a `PlaylistLoader` for the main m3u8
  63. 1. `PlaylistController` creates `PlaylistLoader`s for every audio playlist
  64. 1. `PlaylistController` creates a `SegmentLoader` for the main m3u8
  65. 1. `PlaylistController` creates a `SegmentLoader` for a potential audio playlist
  66. 1. `HLS` sees the `loadedmetadata` and finds the currently selected MediaGroup and all the metadata
  67. 1. `HLS` removes all `AudioTrack`s from the `AudioTrackList`
  68. 1. `HLS` created `AudioTrack`s for the MediaGroup and adds them to the `AudioTrackList`
  69. 1. `HLS` calls `PlaylistController`s `useAudio` with no arguments (causes it to use the currently enabled audio)
  70. 1. `PlaylistController` turns off the current audio `PlaylistLoader` if it is on
  71. 1. `PlaylistController` maps the `label` to the `PlaylistLoader` containing the audio
  72. 1. `PlaylistController` turns on that `PlaylistLoader` and the Corresponding `SegmentLoader` (main or audio only)
  73. 1. `MediaSource`/`mux.js` determine how to mux
  74. ## How tracks are switched
  75. > AudioTrack & AudioTrackList live in video.js
  76. 1. `HLS` is setup to watch for the `changed` event on the `AudioTrackList`
  77. 1. User selects a new `AudioTrack` from a menu (where only one track can be enabled)
  78. 1. `AudioTrackList` enables the new `Audiotrack` and disables all others
  79. 1. `AudioTrackList` triggers a `changed` event
  80. 1. `HLS` sees the `changed` event and finds the newly enabled `AudioTrack`
  81. 1. `HLS` sends the `label` for the new `AudioTrack` to `PlaylistController`s `useAudio` function
  82. 1. `PlaylistController` turns off the current audio `PlaylistLoader` if it is on
  83. 1. `PlaylistController` maps the `label` to the `PlaylistLoader` containing the audio
  84. 1. `PlaylistController` turns on that `PlaylistLoader` and the Corresponding `SegmentLoader` (main or audio only)
  85. 1. `MediaSource`/`mux.js` determine how to mux