'How to download and decrypt HTTP Live Streaming (HLS) videos in iOS?

I want to download M3U8 file chunks (HLS) and store that video (after decrypting it) for later viewing. I have made a demo to play M3U8 file but I want to download video data for later view.



Solution 1:[1]

You can use ffmpeg to download and decode the HTTP-LS stream:

ffmpeg -i http://example.org/playlist.m3u8 -c copy -bsf:a aac_adtstoasc output.mp4

There is an iOS version of ffmpeg available.

Solution 2:[2]

This Perl script is a good fetcher: https://github.com/osklil/hls-fetch

Steps:

wget https://raw.githubusercontent.com/osklil/hls-fetch/master/hls-fetch
chmod +x hls_fetch
./hls_fetch --playlist "THE_URL"

Replace THE_URL with the full URL of your M3U8 playlist (or try other options with --help).

Bonus: If you have missing Perl's JSON module (as I had), simply run sudo cpan JSON.

Solution 3:[3]

There also exists a Chrome extension that makes a whole video from m3u8 chunks, here's the link HLS Video Saver

Solution 4:[4]

Solution 5:[5]

url: https://mnmedias.api.telequebec.tv/m3u8/29880.m3u8

Step-1: ffmpeg -i 'https://mnmedias.api.telequebec.tv/m3u8/29880.m3u8' -vf scale=w=1280:h=720:force_original_aspect_ratio=decrease -c:a aac -ar 48000 -b:a 128k -c:v h264 -profile:v main -crf 20 -g 48 -keyint_min 48 -sc_threshold 0 -b:v 2500k -maxrate 2675k -bufsize 3750k -hls_time 10 -hls_playlist_type vod -hls_segment_filename my_hls_video/720p_%03d.ts my_hls_video/720p.m3u8

Step-2:

-i 'https://mnmedias.api.telequebec.tv/m3u8/29880.m3u8' :=> Set https://mnmedias.api.telequebec.tv/m3u8/29880.m3u8 as the video source source.

-vf "scale=w=1280:h=720:force_original_aspect_ratio=decrease" :=> Scale video to maximum possible within 1280x720 while preserving aspect ratio

-c:a aac -ar 48000 -b:a 128k :=> Set audio codec to AAC with sampling of 48kHz and bitrate of 128k

-c:v h264 :=> Set video codec to be H264 which is the standard codec of HLS segments

-profile:v main :=> Set H264 profile to main - this means support in modern devices read more

-crf 20 :=> Constant Rate Factor, high level factor for overall quality

-g 48 -keyint_min 48 :=> IMPORTANT create key frame (I-frame) every 48 frames (~2 seconds) - will later affect correct slicing of segments and alignment of renditions

-sc_threshold 0 :=> Don't create key frames on scene change - only according to -g

-b:v 2500k -maxrate 2675k -bufsize 3750k :=> Limit video bitrate, these are rendition specific and depends on your content type - read more

-hls_time 4 : :=> Segment target duration in seconds - the actual length is constrained by key frames

-hls_playlist_type vod :=> Sdds the #EXT-X-PLAYLIST-TYPE:VOD tag and keeps all segments in the playlist

-hls_segment_filename beach/720p_%03d.ts :=> - explicitly define segments files names my_hls_video/720p.m3u8 - path of the playlist file - also tells ffmpeg to output HLS (.m3u8)

Solution 6:[6]

I just tried downloading a video from some https .m3u8 file following the tutorial https://www.oneminuteinfo.com/2016/10/download-ts-files-and-convert-to-mp4.html and it worked. None of the Chrome plugins or ffmpeg worked for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 niutech
Solution 2 sequielo
Solution 3
Solution 4 Lijith Vipin
Solution 5 ArunDhwaj IIITH
Solution 6 user18823473