Converting and downloading M3U8 file — with bash script
M3U8 files are the basis for the HTTP Live Streaming (HLS) format originally developed by Apple to stream video and radio to iOS devices,
Convert M3U8 to mp4
In order to convert files with ffmpeg, download it and install — on mac — with brew — https://formulae.brew.sh/formula/ffmpeg.
Example of ready to use script:
downlaod_video.sh
#!/bin/bashvideos_source=("https://cdn.mysite.com/videos/38dfbf5a-01fe-45b6-84ba-8aa33b6ae686/20210723150727-stream.m3u8" "https://cdn.mysite.com/videos/f71bf533-c0fc-42d1-a4df-f17e3ff0c98a/20210701144247-stream.m3u8")for str in ${videos_source[@]}; doout_name=`basename $str | cut -d- -f1`.mp4if test -f "$out_name"; thenout_name="$out_name"_1.mp4fiecho $out_nameffmpeg -i $str -acodec copy -bsf:a aac_adtstoasc -vcodec copy ./$out_namedone
Run script
Substitute videos_source with real data and run:
-> ./downlaod_video.sh
Troubleshooting
You may need to run chmod u+x to give permission to run script. In terminal use command:
➜ chmod u+x downlaod_video.sh
Check permissions:
➜ la downlaod_video.sh
-rwxr--r-- 1 user1 staff 0B Jun 28 11:20 downlaod_video.sh