hemisphere/src/overlay/obs/base.py

61 lines
1.4 KiB
Python

import json
from ..filters import FFmpegGraph
class OBSSource:
TYPES = {}
def __init__(self, name='Untitled'):
self.name = name
def load(self, data):
raise NotImplementedError
def to_ffmpeg(self, scene):
raise NotImplementedError
@classmethod
def register(cls, type, c):
cls.TYPES[type] = c
@classmethod
def type(cls, type):
def inner(c):
cls.register(type, c)
return c
return inner
@classmethod
def find_and_load(cls, data):
name = data['name']
type = data['id']
if type not in cls.TYPES:
raise NotImplementedType('unknown type: {}'.format(type))
s = cls.TYPES[type](name)
s.load(data)
return s
class OBSScene:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.sources = {}
self.current_scene = None
self.dimensions = (1280, 720)
def load(self, infile):
data = json.load(infile)
self.current_scene = data['current_scene']
for src in data['sources']:
self.sources[src['name']] = OBSSource.find_and_load(src)
def to_ffmpeg(self, scene=None):
scene = scene or self.current_scene
runners, chains = self.sources[scene].to_ffmpeg(self)
r = FFmpegGraph()
r.extend(chains)
return runners, r