How to download a video from an M3U8 file

Mahavir picture Mahavir · Apr 26, 2015 · Viewed 60.5k times · Source

I have an M3U8 file saved locally.

I want to download the video file from the above file. I have googled a lot and found the M3U8 parser. But it didn’t help me.

I have attempted to download the video using the following code, but it always returned nil.

 NSString *str = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"1" ofType:@"m3u8"] encoding:NSUTF8StringEncoding error:nil];
 M3U8SegmentInfoList *list=   [M3U8Parser m3u8SegmentInfoListFromPlanString:str baseURL:[NSURL URLWithString:@"http://hls.ted.com/talks/2238.m3u8?sponsor=Ripple"]];
    NSLog(@"%@",list);

How can I download this video?

Answer

Endre picture Endre · Jul 4, 2020

It's easy-peasy with VLC. Most steps are obvious, and you only need to do one trick.

  1. Testing: Copy the URL of the M3U8 file.
  2. Open VLC and hit Ctrl/Cmd + N, paste it there. If VLC plays it then you're almost there.
  3. Now download the M3U8 file.
  4. Here's the trick: It lacks the original URL of the TS segments so you have to paste it before the segments' names. E.g. seg-1-v1-a1.tshttp://videosource.site/seg-1-v1-a1.ts, it's in the URL where you downloaded the M3U8 file. Use even Notepad/TextEdit and their Replace function, or paste the URL manually to every filenames. (In this case, the string seg is a common sample so you can use it in the Replace function.)
  5. Now you have a "net-compliant" M3U8 file, you can add it to VLC. If VLC plays it then you're almost there.
  6. In VLC, click File menuConvert/Stream…
  7. Drag and Drop the M3U8 file as the media source.
  8. Customize profile: Encapsulation: MP4/MOV, Video and Audio: "Keep original …". Apply…
  9. Specify the output filename.
  10. Click to Save as File.

VLC will remux the file into an M4V file. It should be playable locally. (M4V files can be renamed to MP4, they're actually MP4 files.)

Convert & Stream Keep original video/audio track