Skip to content

File: ShaderFlow/Server.py

ShaderFlow.Server

Config

Bases: BrokenModel, FrozenHash

Source code in Projects/ShaderFlow/ShaderFlow/Server.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Config(BrokenModel, FrozenHash):
    class VideoSettings(BrokenModel):
        """Mirrors exporting-worthy Scene.main() arguments"""
        width:   Optional[int]   = Field(None, ge=2, le=16384)
        height:  Optional[int]   = Field(None, ge=2, le=16384)
        ratio:   Optional[float] = Field(None, gt=0.0)
        bounds:  Optional[tuple[int, int]] = Field(None)
        scale:   float = Field(1.0,  gt=0.0)
        fps:     float = Field(60.0, gt=0.0)
        quality: float = Field(50.0, ge=0.0, le=100.0)
        ssaa:    float = Field(1.0,  ge=0.0, le=2.0)
        time:    float = Field(10.0, ge=0.0)
        start:   float = Field(0.0,  ge=0.0)
        speed:   float = Field(1.0,  gt=0.0)
        loop:    int   = Field(1,    ge=1)
        batch:   str   = Field("0")
        buffers: int   = Field(2,    ge=1)
        noturbo: bool  = Field(False)
        format:  str   = Field("mp4")

    video: VideoSettings = Field(default_factory=VideoSettings)
    ffmpeg: BrokenFFmpeg = Field(default_factory=BrokenFFmpeg)

VideoSettings

Bases: BrokenModel

Mirrors exporting-worthy Scene.main() arguments

Source code in Projects/ShaderFlow/ShaderFlow/Server.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class VideoSettings(BrokenModel):
    """Mirrors exporting-worthy Scene.main() arguments"""
    width:   Optional[int]   = Field(None, ge=2, le=16384)
    height:  Optional[int]   = Field(None, ge=2, le=16384)
    ratio:   Optional[float] = Field(None, gt=0.0)
    bounds:  Optional[tuple[int, int]] = Field(None)
    scale:   float = Field(1.0,  gt=0.0)
    fps:     float = Field(60.0, gt=0.0)
    quality: float = Field(50.0, ge=0.0, le=100.0)
    ssaa:    float = Field(1.0,  ge=0.0, le=2.0)
    time:    float = Field(10.0, ge=0.0)
    start:   float = Field(0.0,  ge=0.0)
    speed:   float = Field(1.0,  gt=0.0)
    loop:    int   = Field(1,    ge=1)
    batch:   str   = Field("0")
    buffers: int   = Field(2,    ge=1)
    noturbo: bool  = Field(False)
    format:  str   = Field("mp4")
width
width: Optional[int] = Field(None, ge=2, le=16384)
height
height: Optional[int] = Field(None, ge=2, le=16384)
ratio
ratio: Optional[float] = Field(None, gt=0.0)
bounds
bounds: Optional[tuple[int, int]] = Field(None)
scale
scale: float = Field(1.0, gt=0.0)
fps
fps: float = Field(60.0, gt=0.0)
quality
quality: float = Field(50.0, ge=0.0, le=100.0)
ssaa
ssaa: float = Field(1.0, ge=0.0, le=2.0)
time
time: float = Field(10.0, ge=0.0)
start
start: float = Field(0.0, ge=0.0)
speed
speed: float = Field(1.0, gt=0.0)
loop
loop: int = Field(1, ge=1)
batch
batch: str = Field('0')
buffers
buffers: int = Field(2, ge=1)
noturbo
noturbo: bool = Field(False)
format
format: str = Field('mp4')

video

video: VideoSettings = Field(default_factory=VideoSettings)

ffmpeg

ffmpeg: BrokenFFmpeg = Field(default_factory=BrokenFFmpeg)

render

render(self, config: Optional[Config] = None) -> bytes

Render a video file with the current configuration

Source code in Projects/ShaderFlow/ShaderFlow/Server.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def render(self, config: Optional[Config]=None) -> bytes:
    """Render a video file with the current configuration"""
    self.config = (config or self.config)

    try:
        with tempfile.NamedTemporaryFile(
            suffix=("."+self.config.video.format),
            delete=False,
        ) as temp:
            video: bytes = self.main(
                **self.config.video.dict(),
                output=Path(temp.name),
                progress=False
            )[0].read_bytes()
    finally:
        with contextlib.suppress(FileNotFoundError):
            os.unlink(temp.name)

    return video

worker

worker(cls)
Source code in Projects/ShaderFlow/ShaderFlow/Server.py
58
59
60
61
62
63
@classmethod
def worker(cls):
    scene = cls(backend="headless")

    for endurance in itertools.count(1):
        ...