alex-ong / NESTrisOCR

OCR for statistics in NESTris
24 stars 7 forks source link

New stream capture class + startup script to restream twitch streams #53

Closed timotheeg closed 4 years ago

timotheeg commented 4 years ago

TLDR

Sort of half baked feature to allow easy restreaming of twitch streams that follow Stencil.

Half baked but working OK!

Longer story

Should allow a restreamer to host a competition with OCR and a re-renderer, catering for 2 players for now.

PR content:

Local requirement as a restreamer: streamlink, ffmpeg, vlc

Script is invoked as:

python3 -m scripts.restream PLAYER_1_TWITCH_USER_NAME 1

# and for player 2
python3 -m scripts.restream PLAYER_1_TWITCH_USER_NAME 2

Script does:

The VLC servers will be accessible from the following 2 URLs (for player 1 and 2 respectively)

NESTrisOCR will push its game data to port 4001 and 4002 respectively, where a suitable renderer may be listening (like NESTrisStatsUI πŸ˜… .

This allow for a pretty quick restream setup with sample results as folllow:

image

alex-ong commented 4 years ago

It looks good but the json stringreplace is pretty hackerman. Don't worry its a future problem πŸ‘

Could you 1) put restreamer stuff inside scripts/restreamer since it might grow 2) add a small readme.md inside that folder?

timotheeg commented 4 years ago

Could you

  1. put restreamer stuff inside scripts/restreamer since it might grow
  2. add a small readme.md inside that folder?

Sure thing, I reckon only the template config file needs to move to scripts, and I'll add a readme too

alex-ong commented 4 years ago

It's amazing how quickly real programmers work :jealousface:

timotheeg commented 4 years ago

I've added a few commits so far, but I'll finish up setting up the config tonight

timotheeg commented 4 years ago

PR ready. Some highlights:

Tested!

timotheeg commented 4 years ago

K! I think it's ready :)

I can literally be up and running streaming a match in 1 minute now πŸ’ͺ

You can test it too by following these steps:

pre-req: clone NESTrisStatsUI + npm install in it

  1. open 3 terminals windows
  2. In first window, go to NEStrisStatsUI base folder and run node app_competition.js
  3. In a browser tab, open local html file NESTrisStatsUI/public/competition_layout1_ctjc.html
  4. visit https://www.twitch.tv/directory/game/Tetris, and locate 2 twitch players streaming NTSC tetris with stencil with reasonably good stream quality. Note their twitch names down, assumed here as "twitch1" and "twitch2"
  5. In second terminal window, run python3 -m scripts.restream twitch1 1, fine tune when calibrator shows (if needed)
  6. In third terminal window, run python3 -m scripts.restream twitch2 2, fine tune when calibrator shows (if needed) (you can run this in parallel to step 5)
  7. check the browser tab. Booya! competition is ongoing with score differential, simple stats, and crisp pixel-perfect rendering πŸ’ͺ

Now the sad part, a bunch of processes (VLC local servers) run in the background and there's no admin UI to kill them. So when I want to stop the processes, I run this on mac:

killall python python3 python3.8 vlc Python node

I don't know what the equivalent would be in windows πŸ˜…

Last few Notes:

  1. to control the competition interface (player names, number of hearts to Victory), in a separate browser tab, open NESTrisStatsUI/public/competition_admin.html (If you restart the node server, you need to refresh this page, so the websocket connects to the server again)
  2. To stream, in OBS/StreamLabs, set up to stream at 720p, create a new Scene, add a Browser source, make it cover the entire scene at 1280x720, make it load NESTrisStatsUI/public/competition_layout1_ctjc.html (just like the admin UI, if you restart the server, the scene must be refreshed so it connects to the correct node server.
alex-ong commented 4 years ago

Now the sad part, a bunch of processes (VLC local servers) run in the background and there's no admin UI to kill them. So when I want to stop the processes, I run this on mac:

killall python python3 python3.8 vlc Python node

You could use processes.append(StartProcess(args)) as you already have and then have a simple tkinter button that says kill all, which would call process.abort(). Needs minor re-architecting, and wouldnt kill node but should kill vlc/python assuming you started it from here

timotheeg commented 4 years ago

Nice suggestion! I'll open another PR when I have time to do this. Would indeed be a lot nicer if anyone actually uses this for restreaming :)

alex-ong commented 4 years ago

Nice suggestion! I'll open another PR when I have time to do this. Would indeed be a lot nicer if anyone actually uses this for restreaming :)

I think sharky is interested, and i think he's technical enough to command line a few things.

timotheeg commented 4 years ago

Yeah, I had pinged him to ask if he waned to give a try. Now that this is merged, I'll help him set up. Exciting times! :D