Tag: livestream

  • pylivecap – 擷取 YouTube 直播影片 frame 並且存成圖片

    pylivecap – 擷取 YouTube 直播影片 frame 並且存成圖片

    pylivecap 是一個用來擷取直播中影片的 frame,並且存成圖片的 Python package。解決目前沒有「只擷取直播目前畫面」程式的狀況。 目前的作法是透過 streamlink 獲得畫面,傳到 ffmpeg 解出一個 frame 來,透過 Python 整理成單一的 API 來使用。主要架構非常簡單,就是下面這樣: def capture(url, output, quality=VideoQuality.BEST): livestream = [ ‘streamlink’, ‘-O’, url, quality.value ] ffmpeg = [ ‘ffmpeg’, ‘-y’, # Force overwrite ‘-i’, ‘-‘, ‘-f’, ‘image2’, ‘-vframes’, ‘1’, output ] p1 = subprocess.Popen(livestream, stderr=subprocess.DEVNULL, stdout=subprocess.PIPE) p2 = subprocess.Popen(ffmpeg, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdin=p1.stdout) p1.stdout.close() p2.communicate() 這邊很可恥的用了…