10

I need to parse an m3u8 media file, which is a playlist, and download the actual media content.
As per my understanding, the following are the process involved:

  • Parse the m3u8 file and get the '.TS' chunks
  • Once all the chunks has been retrieved, merge as a single file
  • Convert the merged TS file to mp4 format.

Unfortunately, I couldn't find any lib/module to perform the above-mentioned steps. Can anyone provide a better approach or working sample to process and download the m3u8 file?

Any help is much appreciated.

Nizam
  • 5,698
  • 9
  • 45
  • 57
  • You got the approach 100% correct. What is the question? – szatmary Jan 25 '17 at 04:51
  • What if I have all chunks with the same name, only byterange differs. For example: hls_a256K.ts #EXTINF:10.054245, #EXT-X-BYTERANGE:367164@363780 hls_a256K.ts #EXTINF:10.077455, #EXT-X-BYTERANGE:365096@730944 How can I download these two chunks if their names equals? I know that they contain different byte chunks of the audiotrack, but I can not form proper http requests from this – Denys Lobur Apr 09 '19 at 13:32

2 Answers2

4

Here is my solution: https://github.com/nichucs/HLS2MP4 With 3 simple java classes, you can do this.

Disadvantage of the previous one is, it has around 20MB size.

Nizam
  • 5,698
  • 9
  • 45
  • 57
  • How to get user desire bitrate? by default it will choose max – Tara May 15 '18 at 13:30
  • You can modify the code, given that its in Java. Take a look at the PlaylistDownloader.java - and in the FetchPlaylist AsyncTask, you will find what you are looking for in the doInBackground method. You can then ask the app to choose the appropriate bandwidth and download that - you will have to do some additional parsing, but shouldn't be too difficult - if you run into problems, just let me know and I'll try to assist. – shabbirh Jun 26 '18 at 22:58
1

You got the steps correct. But this will include a huge effort to implement on your own. Better to go for some available libraries.

I got a great one here with sample project: https://github.com/nichucs/ffmpeg-android-java-master Original repo: http://writingminds.github.io/ffmpeg-android-java/

Shadow
  • 76
  • 5
  • Actually, that one is my repo, the sample project. I found the library sometime before. But thanks for your response :) – Nizam Mar 20 '17 at 10:35