【问题标题】:How to limit youtube-dl on video length when downloading a youtube stream下载 youtube 流时如何限制 youtube-dl 的视频长度
【发布时间】: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


    【解决方案1】:

    这是我 rm 文件 > 20 分钟的方式:

            dictMeta = ydl.extract_info(
            "https://www.youtube.com/watch?v={sID}".format(sID=sID),
            download=False)
    
        # Duration > Max duation ?
        iDuration = dictMeta["duration"]
        if iDuration > iMaxDuration:
            print(
                "[Log] Too long to download, %ds > %ds" %
                (iDuration, iMaxDuration))
            return ""
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-27
      相关资源
      最近更新 更多