Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Download m3u8 playlist with ffmpeg - step by step download script (ffmpeg binary required)
# Author : Wang Poh Peng
# Description : Use FFMPEG to download videos into mkv or mp4 format
NC='\033[0m' # No Color
command -v ffmpeg >/dev/null 2>&1 || { echo >&2 "${RED}ffmpeg is required for the script to download video stream. Run \`brew install ffmpeg\` if you are on Homebrew"; exit 1; }
echo "${GREEN}Enter m3u8 file url endpoint:${NC}"
echo "${GREEN}Enter video file name to be saved as including extension eg. video1.mp4${NC}"
ffmpeg -user_agent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/601.7.8 (KHTML, like Gecko) Version/9.1.3 Safari/537.86.7" -i $ENDPOINT -c copy $FILENAME
echo "${CYAN}The video file is saved at $PWD/$FILENAME"
echo "${NC} Resetting Terminal Font Color..."

This comment has been minimized.

Copy link

@rstecca rstecca commented May 11, 2020

Didn't work for me but the cause was that I was targeting the wrong m3u8 file. I looked into it (it's a text file) and found the correct ts files and downloaded them. It's frustrating because sometimes audio is on a separate playlist so you have to do the same for that.
I then assembled with ffmpeg -i HLS_AUDIO_160_K.ts -i HLS_540.ts -c:v copy -shortest OUT.mp4
or ffmpeg -i HLS_AUDIO.ts -i HLS_VIDEO.ts -c:v libx264 -pix_fmt yuv420p -shortest OUT.mp4 for extra compatibility with common messaging apps.


This comment has been minimized.

Copy link
Owner Author

@thepoppingone thepoppingone commented May 11, 2020

Oh! Thanks for the feedback! I was just using this to download videos from streaming sites mostly, but you are right I did encounter some issues where the audio was on a separate playlist! (btw, how did you stumble upon my gist?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.