【发布时间】:2016-12-08 21:43:20
【问题描述】:
我正在尝试编写一个小脚本来记录来自 youtube 的实时流。 使用 youtube-dl.download 功能时,它只会继续下载直到流结束,但我想在 20 分钟左右后停止下载。 问题是当我在一段时间后尝试杀死它时,输出已损坏(我使用 mp4 格式),我尝试用 ffmpeg 修复它,但出现“找不到 moov atom”错误。
如何让 youtube-dl(或任何其他工具)录制固定长度的直播流?
这是部分代码:
class recordingThread (threading.Thread):
def __init__(self, threadID, output_location, name, yt_stream, start_time):
threading.Thread.__init__(self)
self.threadID = threadID
self.output = os.path.abspath(output_location)
self.name = name
self.start_time = start_time
self.ydl_opts = {'quiet': True,
'format': 'mp4',
'outtmpl': name+ '%(ext)s',
'sleep_interval': 2
}
self.yt_stream = yt_stream.strip('\'"')
def run(self):
print "Starting %s Thread Recorder - %s" % (self.name, self.start_time)
with youtube_dl.YoutubeDL(self.ydl_opts) as ydl:
self.download_prc = ydl.download([self.yt_stream])
谢谢。
【问题讨论】:
标签: python video ffmpeg video-streaming youtube-dl