Last active
February 27, 2023 14:32
-
-
Save thepoppingone/d99a10e61d82d743a43eb2db02ca8963 to your computer and use it in GitHub Desktop.
Download m3u8 playlist with ffmpeg - step by step download script (ffmpeg binary required)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Author : Wang Poh Peng | |
# Description : Use FFMPEG to download videos into mkv or mp4 format | |
RED='\033[1;31m' | |
NC='\033[0m' # No Color | |
GREEN='\033[0;32m' | |
CYAN='\033[0;36m' | |
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}" | |
read ENDPOINT | |
echo "${GREEN}Enter video file name to be saved as including extension eg. video1.mp4${NC}" | |
read FILENAME | |
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..." |
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?)
@thepoppingone me directly from google. Thanks! :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.