推荐一个下载流式媒体的开源库

在浏览器中用F12打开调试,找到网络一页,刷新页面,找到.M3U8的请求,并找到相关的引用项,比如

罗小黑战记2:https://www.66ss.org/e/DownSys/play/?classid=20&id=27261&pathid1=0&bf=0

里面的选项就是:

python 复制代码
M3U8_URL = "https://vip.dytt-cine.com/20251024/59985_d292974a/3000k/hls/mixed.m3u8"
OUTPUT = "output.mp4"

HEADERS = {
    "User-Agent": "Mozilla/5.0",
    # 如果你的合法资源需要 Referer / Cookie,可加
    "Referer": "https://vip.dytt-cine.com/share/d292974a12895cb3f54966cfc83576a8",
    # "Cookie": "session=xxxx",
}

如果使用ffmpeg下载,代码如下:

python 复制代码
import subprocess

M3U8_URL = "https://vip.dytt-cine.com/20251024/59985_d292974a/3000k/hls/mixed.m3u8"
OUTPUT = "output.mp4"

HEADERS = {
    "User-Agent": "Mozilla/5.0",
    # 如果你的合法资源需要 Referer / Cookie,可加
    "Referer": "https://vip.dytt-cine.com/share/d292974a12895cb3f54966cfc83576a8",
    # "Cookie": "session=xxxx",
}

def build_header_args(headers: dict):
    # ffmpeg 需要把 header 拼成字符串
    header_str = ""
    for k, v in headers.items():
        header_str += f"{k}: {v}\r\n"
    return header_str

cmd = [
    "ffmpeg",
    "-y",
    "-headers", build_header_args(HEADERS),
    "-i", M3U8_URL,
    "-c", "copy",
    "-bsf:a", "aac_adtstoasc",
    OUTPUT,
]

print("Running ffmpeg...")
subprocess.run(cmd, check=True)
print("Done:", OUTPUT)

但是这个东西实在是太慢了,

目前有开源的项目直接做了这个:

https://github.com/nilaoda/N_m3u8DL-RE

主页有详细的参数说明,那么一个命令行执行就可以了:

bash 复制代码
./N_m3u8DL-RE "https://vip.dytt-cine.com/20251024/59985_d292974a/3000k/hls/mixed.m3u8" --thread-count 6 --auto-select --binary-merge --save-name output --header "User-Agent:Mozilla/5.0" --header "Referer:https://vip.dytt-cine.com/share/d292974a12895cb3f54966cfc83576a8"

速度比ffmpeg快,而且输出更加清晰。

相关推荐
德育处主任Pro2 天前
『NAS』有时候能用的视频娱乐媒体中心-Stremio
娱乐·媒体
通信大师2 天前
富媒体短信 RCS 系统技术全解析:从传统短信到下一代消息通信平台
5g·媒体·核心网·信令
marteker2 天前
IAB致力于实现可互操作的媒体测量标准化
搜索引擎·百度·媒体
橙露2 天前
移动端前端适配:Rem、VW/VH 与媒体查询的综合应用指南
前端·媒体
Echo_NGC22373 天前
【FFmpeg使用指南】Part 1:核心架构与媒体流处理
ffmpeg·音视频·媒体·视频
微尘hjx3 天前
【Gstreamer 应用程序开发手册 01】关于GSTREAMER
linux·音视频·媒体
Web3VentureView3 天前
目标:覆盖全网主流公链,SYNBO 正式开启公链生态媒体合作矩阵计划
大数据·网络·人工智能·区块链·媒体·加密货币
2501_947694185 天前
易直聘・让求职更简单
媒体
颢珂智库Haokir Insights5 天前
可以将媒体项目自动转换成iPod支持的标准应用推荐
python·媒体
2501_947694185 天前
易直聘:求职避坑优选
媒体