Browse Source

brower: add chroma keying for transparency for now

master
Shiz 1 year ago
parent
commit
ab96c7e4b4
1 changed files with 7 additions and 4 deletions
  1. +7
    -4
      src/overlay/obs/browser.py

+ 7
- 4
src/overlay/obs/browser.py View File

@ -14,13 +14,14 @@ from .base import OBSSource
class BrowserCapturer:
def __init__(self, url, outfile, dimensions, rate=10):
def __init__(self, url, outfile, dimensions, bg_color='#00ff00', rate=25):
self.chromium = Chromium()
self.url = url
self.frame = b''
self.outfile = outfile
self.dimensions = dimensions
self.rate = rate
self.bg_color = int(bg_color[1:3], 16), int(bg_color[3:5], 16), int(bg_color[5:7], 16), int(bg_color[7:9] or 'ff', 16)
def run(self):
trio.run(self.do_run, restrict_keyboard_interrupt_to_checkpoints=True)
@ -37,7 +38,7 @@ class BrowserCapturer:
width=self.dimensions[0], height=self.dimensions[1],
device_scale_factor=1.0, mobile=False
)
await emulation.set_default_background_color_override(dom.RGBA(0, 0, 0, 0))
await emulation.set_default_background_color_override(dom.RGBA(*self.bg_color))
# Navigate to the website.
async with sess.wait_for(page.LoadEventFired):
@ -68,6 +69,7 @@ class OBSBrowserSource(OBSSource):
self.height = 720
self.audio = False
self.tempdir = tempfile.mkdtemp()
self.bg_color = '#3BBD1E'
def __del__(self):
shutil.rmtree(self.tempdir, ignore_errors=True)
@ -86,9 +88,10 @@ class OBSBrowserSource(OBSSource):
def to_ffmpeg(self, scene):
fifo_path = os.path.join(self.tempdir, 'frame.bin')
os.mkfifo(fifo_path)
print(self.width, self.height)
runner = BrowserCapturer(self.url, fifo_path, dimensions=(self.width, self.height))
runner = BrowserCapturer(self.url, fifo_path, dimensions=(self.width, self.height), bg_color=self.bg_color)
return [FFmpegChain(
FFmpegFilter('colorkey', color='0x' + self.bg_color[1:], similarity=0.3, blend=0.2),
inputs=[FFmpegInput(fifo_path, f='image2pipe', framerate=runner.rate, follow=1, probesize=8192)],
runners=[runner.run]
)]

Loading…
Cancel
Save