-
-
Save wangyihit/f1c966a9a792f4de250e83dad553c820 to your computer and use it in GitHub Desktop.
Download m3u8 links as mp4 multithreaded to decrease download time
This file contains hidden or 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
# 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