1、首先下载ffmpeg软件
链接:https://pan.baidu.com/s/1-YjQqPq22Y5qc6AD4zODrg
提取码:sith
或者:https://ffmpeg.org/download.html
2、下载后解压,将文件夹数据放到对应的目录中,然后将这个路径设置到环境变量的path中
如图:
在cmd中输入ffmpeg,出现如下既操作成功,如图:
3、相关python的脚本:
import subprocess
def download_m3u8(url, output_file):
ffmpeg_cmd = f'ffmpeg -protocol_whitelist "file,http,https,tcp,tls" -i "{url}" -c copy "{output_file}"'
subprocess.call(ffmpeg_cmd, shell=True)
print(ffmpeg_cmd)
2023-07-28 start:
# This is a sample Python script.
import subprocess
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
def print_hi(name):
import subprocess
m3u8_url = "https://example.com/encrypted_video.m3u8"
key_url = "https://example.com/key.key"
output_filename = "output.mp4"
subprocess.call(['ffmpeg', '-i', m3u8_url, '-c', 'copy', '-bsf:a', 'aac_adtstoasc', '-hls_key_info_file',
'<(echo "' + key_url + ' ' + 'keyfile.key")', output_filename])
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
m3u8_url = "fdsafds"
output_filename = "gfdgfsdgfd.mp4"
subprocess.call(['ffmpeg', '-i', m3u8_url, '-c', 'copy', output_filename])
print_hi('PyCharm')
import requests
import urllib
m3u8_url = "https://example.com/video.m3u8"
output_directory = "output/"
response = requests.get(m3u8_url)
lines = response.text.strip().split('\n')
ts_urls = [line for line in lines if line.endswith('.ts')]
for i, ts_url in enumerate(ts_urls):
output_filename = f"{i}.ts"
output_path = output_directory + output_filename
urllib.request.urlretrieve(ts_url, output_path)
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
end