pschatzmann / arduino-audio-tools

Arduino Audio Tools (a powerful Audio library not only for Arduino)
GNU General Public License v3.0
1.36k stars 211 forks source link

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

Open DrewBatchelor opened 1 year ago

DrewBatchelor commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 10 months ago

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

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 commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

https://github.com/frejoel/tsdemux/issues/10

DrewBatchelor commented 10 months ago

@pschatzmann Thank you. Thank you.

pschatzmann commented 10 months ago

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 commented 7 months ago

Hi Phil, I'm not sure which example file this is, is it this one and is it working enough to be useful? https://github.com/pschatzmann/arduino-audio-tools/blob/ae72af696865c42bd3e929953bb36016189529b5/examples/examples-stream/streams-url_mts-hex/streams-url_mts-hex.ino#L12 Thank you

pschatzmann commented 7 months ago

No hls does not work properly yet

FatherMarco1971 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 4 months ago

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 commented 2 months ago

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!