Skip to content

Instantly share code, notes, and snippets.

@Noxville
Created March 25, 2025 00:49
Show Gist options
  • Save Noxville/f5c731a171cc19da99f501f19251a336 to your computer and use it in GitHub Desktop.
Save Noxville/f5c731a171cc19da99f501f19251a336 to your computer and use it in GitHub Desktop.
import cv2
import math
import streamlink
def get_stream(tw_acc='arteezy'):
session = streamlink.Streamlink()
session.set_option('twitch-disable-ads', True)
session.set_option('http-headers', {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
'AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/111.0.0.0 Safari/537.36'})
streams = session.streams(f"http://twitch.tv/{tw_acc}")
stream = streams['best']
return stream.to_url()
def save_frames(stream_obj):
FRAME_RATE_PROP_IDX = 5
capture_device = cv2.VideoCapture(stream_obj)
frame_rate = capture_device.get(FRAME_RATE_PROP_IDX)
frame_count = 0
while capture_device.isOpened():
frame_id = capture_device.get(1)
ret, frame = capture_device.read()
if not ret:
return
if frame_id % math.floor(frame_rate * 5) == 0:
#print(frame_rate, frame_id, frame_count)
filename = "./frames/frame%d.jpg" % frame_count
frame_count += 1
cv2.imwrite(filename, frame)
capture_device.release()
if __name__ == '__main__':
tw_stream = get_stream(tw_acc='grubby')
save_frames(tw_stream)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment