Filter
Filters can be declared in a similar way to sources, by calling new Filter
with the appropriate arguments.
const colorCorrectionFilter = new Filter({
kind: "color_filter_v2", // The kind of the filter
name: "Filter", // Name of the filter in OBS
// Must be unique within the filters of
// the source it will be created for
});
The filters package contains helper classes that have type definitions and filter kinds built into them.
- NodeJS
- Browser/TypeScript
const { ColorCorrectionFilter } = require("@simple-obs/filters");
const colorCorrectionFilter = new ColorCorrectionFilter({
name: "Filter",
// kind is no longer necessary, since it is
// provided by ColorCorrectionFilter
});
import { ColorCorrectionFilter } from "@simple-obs/filters";
const colorCorrectionFilter = new ColorCorrectionFilter({
name: "Filter",
// Kind is no longer necessary, since it is provided by ColorCorrectionFilter
});
Create Source with Filter​
Sources (and Scenes, since they are also sources) take a map of filters as an argument when being created to specify default filters that the source should be created with.
const imageSource = new ImageSource({
name: "Some Source",
filters: {
colorCorrection: new ColorCorrectionFilter({
name: "Filter",
}),
},
});
const scene = new Scene({
name: "Some Scene",
items: {
image: {
source: imageSource,
},
},
filters: {
colorCorrection: new ColorCorrectionFilter({
name: "Filter",
}),
},
});
The keys of this map are for acceessing the filters through the source's filter() method, and though it does not have the same function as a ref
, it must uniquely identify the filter within the source it is assigned to.
const filter = source.filter("colorCorrection");
Add a Filter to a Source​
A filter can be added to a source dynamically by calling addFilter on the source.
const filter = await source.addFilter(
"colorCorrection",
new ColorCorrectionFilter({
name: "Filter",
})
);
Properties​
- name: The name the filter was created with
- kind: The kind of the filter
- source: The source the filter is assigned to
These properties can be set with their associated functions: