Created
March 25, 2025 00:49
-
-
Save Noxville/f5c731a171cc19da99f501f19251a336 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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