Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Example for how create a HLS stream m3u8 player #911

Open
DrewBatchelor opened this issue Jul 2, 2023 · 19 comments
Open

Comments

@DrewBatchelor
Copy link

Hi Phil,
Thank you for all the work you have put into making this amazing library, and thank you for generously sharing it.
It is amazing.

I have been using it to make my main kitchen radio, but last month BBC have changed how they stream their internet radio, so mp3 streams are no longer available, only m3u8 like this one:
"http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/ak/bbc_6music.m3u8"

I can see that you have created a HLS player in experiments, which looks like it will solve this problem, but I can't quite work out how to use it.

Would you please share an example that shows how to use this to create a simple streaming music player. Something like the URL player example for playing a m3u8 live stream.

Many thanks

Drew

@pschatzmann
Copy link
Owner

BBC decided to provide the audio as m4a. Unfortunatly I do not have any codec which would support this and information how to parse this is really hard to find.

Any help is appreciated...

@DrewBatchelor
Copy link
Author

DrewBatchelor commented Jul 3, 2023

Hi Phil,
Thank you for the reply, this level of coding is well beyond my understanding,
In searching for a solution, I found 2 possible similar projects that might be of help.

Frank Boesing AudioLibrary on a Teensy looks promising: https://github.com/FrankBoesing/Arduino-Teensy-Codec-lib
"Audiolibrary plugin, plays up to 320 kbps MP3, MP4(AAC), M4A(AAC), AAC-Raw or FLAC in software without external hardware - with only 48MHz."
Frank B described the "*.m4a .... file format is horror :-) ( "ISO14496-14" if anyone wants to study it)"

And Yokohama-Miyazawa on a M5 Stack has and M5HLSPlayer: https://github.com/Yokohama-Miyazawa/M5HLSPlayer
Although I'm not clear if this one is also solving the m4a Problem.

Kind Regards
Drew

@joba-1
Copy link
Contributor

joba-1 commented Jul 3, 2023

3 attempts at any help:

Espressif provides an aac decoder with their ADF: https://github.com/espressif/esp-adf-libs/blob/master/esp_codec/include/codec/aac_decoder.h

m4a is just an envelope for a codec, usually aac. Have not checked for what bbc actually uses.

faad is one open source project that can decode m4a and aac, so probably contains code to study the difference.

@pschatzmann
Copy link
Owner

pschatzmann commented Jul 4, 2023

Yes, I also found franks approach most promising, but I am not sure how reliable it will be. A test file that I donwloaded did not seem to have the same atoms that he was relying on. He also has an easier problem to solve because he can rely on the file API when doing the parsing.

I would expect that the helix aac decoder that I am normally using in my examples works as well.

Currently I am in the hospital,, so do not expect to see any quick progress.

@pschatzmann
Copy link
Owner

pschatzmann commented Sep 10, 2023

Things are not working yet, but to keep things simple, I decided on the following design:

  • HLSStream: provides the stream of raw (encoded) data. Usually with Content-Type: video/MP2T, so this is mpeg-ts (=MTS) format.
  • MTSDecoder: can be used to extract the AAC data using the https://github.com/pschatzmann/arduino-tsdemux library. This can be just forwarded to a AAC decoder to provide pcm data.

A draft implementation of these classes have been committed.

#include "AudioTools.h"
#include "AudioCodecs/CodecMTS.h"
#include "AudioCodecs/CodecAACHelix.h"

I2SStream out; // final output of decoded stream
HLSStream hls_stream("SSID", "password");
MTSDecoder mts;
AACDecoderHelix aac;
EncodedAudioStream aac_stream(&out, &aac); 
EncodedAudioStream mts_stream(&aac_stream, &mts);
StreamCopy copier(mts_stream, hls_stream);

// Arduino Setup
void setup(void) {
  Serial.begin(115200);
  AudioLogger::instance().begin(Serial, AudioLogger::Info);

  out.begin(TX_MODE);
  mts_stream.begin();
  aac_stream.begin();

  hls_stream.begin("http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/nonuk/sbr_vlow/ak/bbc_world_service.m3u8");
}

// Arduino loop  
void loop() {
  copier.copy();
}

@pschatzmann
Copy link
Owner

pschatzmann commented Sep 12, 2023

faad is one open source project that can decode m4a and aac, so probably contains code to study the difference

I just made a test by sending the data directly to FAAD: it can't handle it! I am getting a Decoding error: Channel coupling not yet implemented. So there seems to be no direct path w/o mpeg-ts.

ps.
The memory requirements for FAAD are horrendous!

@pschatzmann
Copy link
Owner

pschatzmann commented Sep 12, 2023

Today I spent some time to investigate why the MTSDecoder above is not working: I am stunned - the same code with the same data on the desktop is working, but on the ESP32 it's not.

This will be difficult to find...

@pschatzmann
Copy link
Owner

frejoel/tsdemux#10

@DrewBatchelor
Copy link
Author

@pschatzmann Thank you. Thank you.

@pschatzmann
Copy link
Owner

pschatzmann commented Sep 13, 2023

The MTSDecoder is working now, but the HLSStream seems to need some rework, to get faster.
I want to avoid to use some FreeRTOS, so that this will work in other environments as well.

@DrewBatchelor
Copy link
Author

Hi Phil, I'm not sure which example file this is, is it this one and is it working enough to be useful?


Thank you

@pschatzmann
Copy link
Owner

No hls does not work properly yet

@FatherMarco1971
Copy link

Phil, my favorite radio use this kind of stream and after many research this is the only solution i've found.
I look forward waiting for a working release.
I'm very sorry my programming capacity are miles away to give any help.
Now i'm compiling the example https://github.com/pschatzmann/arduino-audio-tools/blob/ae72af696865c42bd3e929953bb36016189529b5/examples/examples-stream/streams-url_mts-hex/streams-url_mts-hex.ino#L12
and starting to study it and your library.
Very gratefull for your work

@pschatzmann
Copy link
Owner

HLS is not working (reliably) yet.
I was coming to the conclusion that it will be too slow when using a simple sequential approach.

@FatherMarco1971
Copy link

I see the example running and receiving TS file without any sound.
I rellay hope you can dedicate some time to make it work and I repeat i'm very sorry the matter is mile further to my capability to help.
May all two esp32 cores in parallel can do the work but i understand is a big work to do

@pschatzmann
Copy link
Owner

pschatzmann commented Feb 13, 2024

The example sends the output to the display! So there can not be any sound...
It might be no problem on an ESP32, but then the solution is not portable any more and will not run on other procesors!

@FatherMarco1971
Copy link

The example sends the output to the display! So there can not be any sound...
Yes i'm trying to stream it i2s just to try it and study. But anyway you say the result it will be not good enough

I see your point regarding portability.

@lidense
Copy link

lidense commented Mar 13, 2024

Did you try this code:
https://github.com/Yokohama-Miyazawa/M5HLSPlayer
It seems to have all you need for HLS streaming with esp32?

@z-l-p
Copy link

z-l-p commented Apr 28, 2024

I am also very interested in HLS streams (mainly because BBC discontinued their Icecast MP3 streams). A quick note: Aside from issues of portability, the M5HLSPlayer repo also seems quite broken and hasn't had any commits in a year. HLS is a tough one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants