LVideoFilter Reference Manual & GPU Video Shader Pipeline
#include "LVideoFilter.h"LVideoFilter is a GPU-accelerated OpenGL video processing node derived from both LObject and LSink. It replaces CPU-bound FFmpeg video filter graphs with a dedicated offscreen GLSL pipeline (supporting direct YUV420P, YUV422P, NV12, UYVY422, YUYV422, BGRA, and RGBA uploads) that can be placed anywhere in the pipeline, such as LLive -> LVideoFilter -> LColor -> LMixer -> LOutput.
Note: For simple input-level orientation and deinterlacing (e.g. LLive -> LPreview without intermediate nodes), LLive and LFile also run the exact same GPU shader natively via setProps("hflip", true) and setProps("deinterlace", true).
1. Architectural Concept & Orientation Safety
graph LR
SRC[LLive / LFile / LMixer / LColor] -->|setSource| VF[LVideoFilter]
VF -->|All Filters Off or Progressive Bypass| PASS[Zero-Copy Passthrough]
VF -->|Active GPU Effect| GL[Offscreen OpenGL 1:1 Quad Shader + PBO Readback]
GL --> DOWN[LColor / LMixer / LSwitcher / LOutput / LRecorder]
- Zero CPU Filter Fallback: Uploads raw
UYVY422,YUYV422,NV12,YUV420P,BGRA, andRGBAframes directly to OpenGL textures and executes Flip, ELA Deinterlacing, Blur, Sharpen, Grayscale, Negate, and Vignette in one fragment pass. - Lazy Initialization: When
setEnabled(false)is set or no filter stage is active, no OpenGL context is created and frames pass through at zero cost. - 1:1 Row Orientation: Like
LColor,LVideoFilteroperates1:1on memory rows and delegatesisGpuFlipped()directly from its upstream source, making it safe before or afterLMixerandLColor.
2. Typed Filter Props Structs
struct LDeinterlaceProps {
bool force = false; // If false, deinterlaces only frames marked interlaced
};
Configures GPU edge-based line average (ELA) deinterlacing ("deinterlace").
struct LBlurProps {
float radius = 2.0f; // Soft blur radius in pixels (0.0..10.0)
};
struct LSharpenProps {
float amount = 0.5f; // Unsharp mask intensity (0.0..2.0)
};
struct LVignetteProps {
float strength = 0.5f; // Edge darkening intensity (0.0..1.0)
};
Configures GPU blur ("blur"), unsharp mask ("sharpen"), and radial vignette ("vignette").
3. API Reference & Key Methods
void setSource(LObject* source);
LObject* getSource() const;
void setEnabled(bool enabled);
bool isEnabled() const;
Attaches an upstream LObject source and enables or bypasses GPU video filtering.
void setProps(const std::string& key, bool enabled);
void setProps(const std::string& key, const std::string& value);
bool isFilterEnabled(const std::string& key) const;
std::string getProps(const std::string& key) const;
Enables or disables GPU stages cleanly without altering stored parameter values. Supported keys: "enabled", "hflip" (alias "mirror"), "vflip", "deinterlace", "blur", "sharpen", "vignette", "negate", "grayscale".
void updateFilter(const LDeinterlaceProps& props);
void updateFilter(const LBlurProps& props);
void updateFilter(const LSharpenProps& props);
void updateFilter(const LVignetteProps& props);
// Matching getFilter(...) overloads read current values back.
Updates parameter values without changing enable flags. Immediately re-renders the last paused frame if that stage is active.
void reset();
bool hasActiveFilters() const;
Disables all active stages and restores default struct parameters.
4. C++ Pipeline Example
#include "now2sdk.h"
int main() {
LLive* cam = new LLive();
cam->DeviceSet(0);
cam->Start();
// Pipeline: LLive -> LVideoFilter -> LColor -> LMixer -> LOutput
LVideoFilter* vf = new LVideoFilter();
vf->setSource(cam);
// Update effect values via structs
LSharpenProps sharpen;
sharpen.amount = 0.35f;
vf->updateFilter(sharpen);
LVignetteProps vig;
vig.strength = 0.40f;
vf->updateFilter(vig);
// Toggle stages via setProps
vf->setProps("hflip", true);
vf->setProps("deinterlace", true);
vf->setProps("sharpen", true);
vf->setProps("vignette", true);
LColor* color = new LColor();
color->setSource(vf);
LPreview* preview = new LPreview();
preview->setProps("ui_framework", "qt");
preview->previewEnable(nullptr, false, true);
preview->previewObject(color);
return 0;
}