我正在尝试用以下代码在python中使用youtube-dl API保存实况流。因为它是一个连续的实况流,所以视频没有结束,所以我使用hls-use-mpegts
作为一种定期读取视频进行处理的方式,该标志使.mp4.part
文件可播放。
尽管hls-use-mpegts
选项可以很好地与命令行配合使用,但如下所示:
youtube-dl -f worst <some URL> --retries infinite --continue --hls-use-mpegts
它似乎不适用于此代码。我没有看到任何错误,也没有看到以mpegts格式保存的文件。我的选项设置是否正确?
ydl_opts = {
'format': 'worst',
'retries': 99,
'continue': True,
'hls-use-mpegts': True
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
发布于 2021-09-24 11:02:29
这是因为(很抱歉这么说)文档在某种程度上是好的&见鬼*同时。我发现在Python中要使用的每个开关/cli-options都必须将- (dash)替换为___ (子dash)。
解决方案
在您的案例中,hls_use_mpegts是解决方案。
为什么?
在这里阅读/探索:https://github.com/ytdl-org/youtube-dl/blob/5208ae92fc3e2916cdccae45c6b9a516be3d5796/youtube_dl/downloader/common.py#L50和这里:https://github.com/ytdl-org/youtube-dl/blob/5208ae92fc3e2916cdccae45c6b9a516be3d5796/youtube_dl/__init__.py#L428
或者像我通常做的那样浏览:https://github.com/ytdl-org/youtube-dl/search?q=hls_use_mpegts%3A (幸运的是GitHub在这方面做得很好,你不需要下载src代码就可以搜索到它)
另外,使用yt-dl很有趣,谢谢他们!
https://stackoverflow.com/questions/66731065
复制相似问题