Free now2sdk Core is completely free — no license key required   See what's included →
SDK Modules Docs Release Notes Pricing GitHub
Get the SDK →

LFilter Reference Manual & FFmpeg Filter Recipes

The LFilter class is a dynamic filter graph wrapper of the now2sdk framework, derived from the base LObject class. It manages real-time audio or video filter configurations, enabling developers to build and modify standard FFmpeg filter chain strings dynamically at runtime.

When bound to a media playback engine (LFile) or a live video feed ingest (LLive), LFilter enables real-time adjustments (such as color corrections, audio delay alignments, and audio volume manipulation) without restarting the playout pipelines.


1. Architectural Concept & Core Mechanisms

LFilter acts as a container for individual filter components. Instead of managing fixed property fields, it stores an internal map of filter names and their parameter arguments:

graph LR
    A[setProps - key/value] --> B{Value empty or false?}
    B -->|Yes| C[Remove filter from map]
    B -->|No| D[Add / Update filter parameters]
    D --> E[Trigger m_onChanged callback]
    C --> E
    
    F[Parent Loop - LFile/LLive] --> G[getFilterString]
    G --> H{Map empty?}
    H -->|Yes| I[Return null/anull]
    H -->|No| J[Return combined filter string]
    J --> K[Rebuild AVFilterGraph if changed]

Key Subsystems:


2. API Reference & Key Methods

📌 Public API Signatures

enum Type {
    Audio,
    Video
};

Defines the stream processing type of the filter instance.

LFilter(Type type = Audio);

Constructs an LFilter instance. The default type is Audio.

virtual ~LFilter();

Destructs the LFilter instance.

void setProps(const std::string& key, const std::string& value);

Sets or removes filter parameters.

std::string getFilterString() const;

Assembles the internal filter map into a single comma-separated FFmpeg filter string (e.g. "eq=brightness=1.05:contrast=1.1,hflip"). If the filter map is empty, returns "anull" for audio filters and "null" for video filters.

Type getType() const;

Returns whether the filter instance is configured as Audio or Video.

void setNotifyCallback(std::function<void()> callback);

Binds an external callback function that is triggered whenever a property is added, updated, or removed via setProps().


3. Practical Video & Audio Filter Recipes

The table below lists standard, production-tested FFmpeg filters that can be directly passed to LFilter::setProps for real-time video and audio processing.

🎥 Video Filter Recipes (Type: Video)

Filter Key (key) Value Format Example (value) Description
eq "brightness=0.05:contrast=1.2:saturation=1.5" Color correction. Adjusts brightness (-1.0 to 1.0), contrast (0.0 to 10.0), and saturation (0.0 to 10.0).
hue "h=30:s=1.5" Color adjustments. Rotates hue angle in degrees (h) and scales color saturation (s).
hflip "true" Horizontally mirrors the video frame.
vflip "true" Vertically flips the video frame.
negate "true" Negates all video colors (creates a negative print effect).
boxblur "luma_radius=5:luma_power=1" Applies a blur effect. Adjusts radial size and power.
drawgrid "w=100:h=100:t=2:c=red@0.5" Draws gridlines over the video canvas (width, height, thickness, color with alpha).
drawbox "x=10:y=10:w=200:h=100:color=blue@0.4:t=fill" Draws a solid or outline color box over the video layout (coordinates, dimensions, color, thickness).

🔊 Audio Filter Recipes (Type: Audio)

Filter Key (key) Value Format Example (value) Description
volume "2.0" or "-10dB" Audio gain adjustments. Multiplies audio amplitude or adjusts using decibels.
adelay "delays=200ms|200ms" Audio channel latency offset. Delays target audio channels (e.g. left and right) in milliseconds.
highpass "f=150" Highpass frequency filter. Cuts off low-frequency noise (e.g. rumble) below the specified cutoff frequency f (in Hz).
lowpass "f=3000" Lowpass frequency filter. Removes high-frequency noise (e.g. hiss) above the specified frequency f (in Hz).
aecho "0.8:0.88:60:0.4" Adds audio echo. Parameters: in_gain:out_gain:delay:decay.
compand "0.3|0.3:1|1:-70/-60|-20/-14|0/-6:5:-90:0" Dynamic range compressor / noise gate to normalize audio levels.

4. C++ Integration Code Example

This code snippet shows how to instantiate and link video and audio filters to an LFile player, and dynamically update parameters at runtime based on developer controls.

#include "now2sdk.h"
#include <iostream>
#include <thread>
#include <chrono>

void setupProcessingFilters() {
    // 1. Create a playout object
    LFile* player = new LFile();
    player->fileNameSet("/home/alsaberk/Videos/sports_feed.mp4");
    player->setProps("loop", "true");

    // 2. Create and configure a Video Color Correction Filter
    LFilter* videoFilter = new LFilter(LFilter::Video);
    
    // Set color equalizer: slight brightness boost, increased contrast, vivid saturation
    videoFilter->setProps("eq", "brightness=0.03:contrast=1.15:saturation=1.4");
    
    // Bind to the player pipeline
    player->setVideoFilter(videoFilter);

    // 3. Create and configure an Audio delay/volume filter
    LFilter* audioFilter = new LFilter(LFilter::Audio);
    
    // Boost volume by 50%
    audioFilter->setProps("volume", "1.5");
    
    // Delay left and right channels by 120ms to fix sync errors
    audioFilter->setProps("adelay", "delays=120ms|120ms");
    
    // Bind to the player pipeline
    player->setAudioFilter(audioFilter);

    // 4. Start playout
    player->play();
    std::cout << "Playout started with active filters." << std::endl;

    // Simulate real-time adjustment after 5 seconds of playout
    std::this_thread::sleep_for(std::chrono::seconds(5));
    std::cout << "Modifying color levels and muting audio filter dynamically..." << std::endl;

    // Dynamically increase saturation on-the-fly (Graph auto-rebuilds in background)
    videoFilter->setProps("eq", "brightness=0.03:contrast=1.15:saturation=1.8");

    // Turn off volume boost (Passing "false" or empty string removes the filter from map)
    audioFilter->setProps("volume", "false");

    // Keep running...
    std::this_thread::sleep_for(std::chrono::seconds(10));

    player->stop();
    delete videoFilter;
    delete audioFilter;
    delete player;
}