ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

Implement multiple audio tracks support for HLS

Open andudo opened this issue 12 years ago • 29 comments

andudo avatar Oct 07 '14 13:10 andudo

Had a quick look at this, and wanted to share my findings.

While it is possible to encode multiple audio streams in the TS, that increases the effective bitrate of the stream, and requires everyone to download every audio streams, even though they only want one (at a time). This is the only way of providing multiple audio tracks for HLS protocol version 3, AFAIK.

The HLS draft version 7, section 8.7. "Variant Playlist with Alternative audio", declares how to in the main playlist specify multiple #EXT-X-MEDIA:TYPE=AUDIO lines pointing to different playlists for different languages. This approach avoids the extra download and was introduced in HLS protocol version 4.

perchrh avatar Oct 08 '14 06:10 perchrh

Naively, could an approach here not simply be to create something along these linkes?

MediaCodecAudioTrackRenderer -> "Multi HLS Sample Source" -> Many HLS Chunk Sources (one for each media (audio) track in the playlist.

May of course be missing something obvious.

nahojkap avatar Feb 25 '15 21:02 nahojkap

Roughly speaking, yes. Although the exact point at which the division happens is TBD. For DASH and SmoothStreaming, we divide at the ChunkSource layer with a MultiTrackChunkSource.

Caveats that may not have occurred are:

  • The fact that there's audio in the primary audio/video stream, as well as in the separate audio tracks, makes wiring things up significantly more complicated than if the only options were the separate audio tracks. I haven't really thought much about what the best way to do this is.
  • When you're downloading audio from a separate source, it's necessary to balance loading of the video and audio to make sure they load at approximately the same rate. You'd probably want to have them share the same underlying buffer pool as well. For DASH and SmoothStreaming, we use a LoadControl to do this.

You're really much better off using DASH or SmoothStreaming if you want multi-audio (you're much better off even if you don't want it, but it becomes even more true if you do). The HLS approach seems pretty bolted on to me, and if you select the non-primary audio track you end up downloading two audio tracks simultaneously, one of which you throw away. That's not exactly a good technical solution.

ojw28 avatar Feb 26 '15 00:02 ojw28

HLS does indeed have quite a few things working against it but with a lot of content being used on multiple platforms, it seems to have managed to dig itself in quite well and is bound to be around for a while.

As for the dual download of audio-tracks - we have in-fact seen TS segments without an audio track entirely (probably to avoid just that - the dual download). Nevertheless, this sort of setup does make wiring up UIs and such to support the various scenarios somewhat a nightmare.

Also, I guess the dual-download would also apply to something like subtitles/closed captions if they are both in the TS segment (as eia 608) and also web-vtt?

nahojkap avatar Feb 26 '15 19:02 nahojkap

@ojw28 How about this strategy for ExoPlayer: implement support for multi-audio in HLS only for the case with separate downloads. The case with multi-audio in one TS is an older solution and has a major drawback, that it increases the effective bitrate of the stream. For these reasons I expect that this case is not as important to most ExoPlayer-HLS users.

@johanlindquist You are right, the subtitle-case is analogous, they can be either in the TS or separate downloads, or both.

perchrh avatar Feb 26 '15 21:02 perchrh

I would be tempted to say +1 to @perchrh suggestion, if playlist contains EXT-X-MEDIA, simply ignore any audio in the TS. If the (video) TS still contains audio data, it could be considered a server issue and should be fixed there by re-encoding the streams?

nahojkap avatar Feb 27 '15 11:02 nahojkap

Any more progress on this end? We're in a position now that we need support for this, so if there's no ExoPlayer support we're going to look into implementing it.

Any pointers for the best way to add support for multi track audio (and subtitles) would be highly appreciated. Also, if this is relevant for the main project, we'd gladly contribute our implementation.

andreimarinescu avatar Jun 02 '15 13:06 andreimarinescu

Just following up on this. Would the discussion in #514 be relevant for HLS as well?

andreimarinescu avatar Jun 04 '15 08:06 andreimarinescu

Posted this by mistake in #514.

Something to bear in mind if using two chunk sources for live HLS (each loading playlists individually), which would the case for multi-audio.

There is a big risk the two will not correctly synchronize audio since the loading of playlists can (and will) happen at different times and under the right circumstances, the player will choose different start segments to start with.

For example:

Video playlist is loaded and contains sequence numbers 5,6,7,8,9,10 - playback will start with 8 Audio playlist is loaded and contains 6,7,8,9,10,11 - playback should start with 8 but code currently will pick 9.

So, there is a need to synchronize this somehow between the chunk sources.

nahojkap avatar Jun 17 '15 10:06 nahojkap

Yes, definitely something to bear in mind. We already have much of what we need to ensure this from our work on DASH. Specifically, LoadControl can be used to ensure that separate tracks load at the same rate (so that we don't end up buffering 10 minutes of audio and 10 seconds of video).

If the media timestamps in the separate streams are aligned properly then synchronization should happen automatically (I'd really hope that this is true). If not, we'll need to do a bit more work to get this right.

ojw28 avatar Jun 17 '15 10:06 ojw28

While the timestamps usually are synchronized (in the playlist), there is still a chance that the playlists could be refreshed in-between loads so there is definitely a need to do the initial sync also using sequence numbers in the playlist (rather than just position in the list).

Also, there is the question I brought up in #552 which could be used to sync the audio/video even closer I believe.

nahojkap avatar Jun 17 '15 11:06 nahojkap

I've noticed that the [e770e5c] should almost finalize this issue. Any help needed here for the final step? Is there a way of setting this up to work with it already? I've done a quick test with the demo app and no audio tracks are detected (seems in line with the commit message for HLS).

andreimarinescu avatar Aug 20 '15 07:08 andreimarinescu

Significant further work is required beyond the change linked to above for HLS. #514 has an update of where we are with multi-track across the various different playback types.

ojw28 avatar Aug 20 '15 11:08 ojw28

Thanks, @ojw28. I had a look over the codebase in the meanwhile and noticed that the HlsPlaylistParser isn't even looking at the AUDIO media tags yet, and I guess there's further work needed with reworking the HlsSampleSource. Thanks anyway for the update!

andreimarinescu avatar Aug 20 '15 12:08 andreimarinescu

@ojw28 Is there any update on this? Trying to play video hosted in Azure Media Services which only have below streams

  • HLS + AES
  • Smooth Streaming + AES

Second cannot be used because ExoPlayer doesn't support AES for Smooth Streaming. On HLS, only video works. Any update would help me a lot.

SachiraChin avatar Nov 17 '15 09:11 SachiraChin

No update, sorry. It's interesting that you have SmoothStreaming+AES streams. Perhaps we should support that case; SmoothStreaming is a much nicer standard than HLS, so it would be a shame to be pushing people to HLS because we support AES there and not for SmoothStreaming. Could you open a separate issue for that, and if possible link to the specification that defines how AES works in SmoothStreaming? Thanks!

ojw28 avatar Nov 17 '15 09:11 ojw28

Created new issue #964. Hope it has enough information. Thanks.

SachiraChin avatar Nov 17 '15 10:11 SachiraChin

Hey Guys, any update or any solution about Multi-Audio HLS support ? thanks in advance.

amed500 avatar Nov 27 '15 15:11 amed500

I have this more or less working locally, but I'm struggling to find test streams to verify that the implementation is correct. Please could anyone interested in this feature provide their streams for testing, either here or to [email protected].

I'm particularly interested in live streams with multiple audio tracks, since I haven't found any examples of this. VOD streams are helpful too. I know Apple provide a test stream with alternate audio, but their alternate track is a constant sound, which means you can't use it to verify that A/V sync is correct!

ojw28 avatar Feb 17 '16 11:02 ojw28

Please could anyone interested in this feature provide their streams for testing, either here or to [email protected].

We are really interested in this kind of functionality. I've sent link to the aforementioned e-mail.

akavrt avatar Feb 19 '16 13:02 akavrt