Python API
The two main entry points mirror the render and video CLI commands and take the same configuration objects.
1from pathlib import Path
2from svgsequencevideo import RenderConfig, renderSvg
3
4renderSvg(Path("drawing.svg"), RenderConfig(outputDir=Path("build"), width=1920))
1from svgsequencevideo import ProjectConfig, VideoConfig, buildVideo
2
3config = ProjectConfig(video=VideoConfig(revealDuration=15.0, weights={"Foreground": 2.0}))
4buildVideo(config)
Configuration
- class svgsequencevideo.RenderConfig(outputDir=PosixPath('output'), width=None, height=None, inkscapePath=None, force=False, resume=False)
- class svgsequencevideo.VideoConfig(cacheDir=None, outputFile=PosixPath('output.mp4'), heuristic=HeuristicType.COMPLEX, weights=<factory>, revealDuration=20.0, finalFrameDuration=5.0, backgroundColor='#d5d5d5', ffmpegPath=None)
- class svgsequencevideo.ProjectConfig(render=<factory>, video=<factory>)
Rendering
- svgsequencevideo.renderSvg(input, config)
Video
- svgsequencevideo.buildVideo(config, heuristic=None)
Custom heuristics
The reveal timing of each element is driven by a Heuristic.
Subclass it and pass an instance to buildVideo() to
use your own logic instead of the built-in equal/area/complex
ones.
1from svgsequencevideo import Heuristic, buildVideo
2
3class MyHeuristic(Heuristic):
4 def computeBaseFactor(self, node, context):
5 return node.objectCount # every element gets the same reveal time
6
7buildVideo(config, heuristic=MyHeuristic())
Exceptions
- exception svgsequencevideo.config.InvalidRenderConfigError
Raised when a RenderConfig contains an invalid combination of options.
- exception svgsequencevideo.render.RenderOutputConflictError(outputDir, canResume)
Raised when the output folder already contains render output and neither force nor resume option was given.
- exception svgsequencevideo.render.ResumeMismatchError
Raised when resume is requested but no compatible previous render can be found in the output folder.
- exception svgsequencevideo.heuristic.CacheNotFoundError
Raised when no rendered metadata can be found in the requested cache directory.