Skip to content

Instantly share code, notes, and snippets.

@SophieShears
Last active February 16, 2025 02:21
Show Gist options
  • Save SophieShears/edb3a1ef773629ae8bf0fa3eb2fdd679 to your computer and use it in GitHub Desktop.
Save SophieShears/edb3a1ef773629ae8bf0fa3eb2fdd679 to your computer and use it in GitHub Desktop.
Download m3u8 links as mp4 multithreaded to decrease download time
# pip install m3u8_To_MP4
# Code to download m3u8 links as mp4 files
import m3u8_To_MP4
import os
def dl_m3u8(url, directory, filename):
# Note directory should be the filepath to save the file ex: '/home/username/bin'
# Directory can be a relative or absolute path
# Filename should end with an .mp4 ex: 'test.mp4'
try:
m3u8_To_MP4.multithread_download(
url,
mp4_file_dir=directory,
mp4_file_name=filename
)
except Exception as e:
print(e)
# Test it works
# Create directory for testing
directory = 'test_output'
if not os.path.isdir(directory):
os.mkdir(directory)
url = 'https://stream.mux.com/h43EE02LZDlp01iwlqZsoKqNdu0234OagSG.m3u8'
filepath = 'output.mp4'
dl_m3u8(url, directory, filepath)
# Should create a 'test_output' directory in the active directory
# Then produce an mp4 called 'output.mp4' there
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment