OBS Studio Defish on Linux

Nicola Landro
2 min readDec 21, 2021

If you have a Fish-Eye camera like a GoPro or a generic action cam and you want to correct the distorction is easy to do with KdenLive and similar software but how to do it live with OBS on Linx? I will explain a solution that use shader.

Requirements

We must add to our obs studio the OBS-StreamFX by downloading streamfx-ubuntu-20.04–0.10.1.0-gc8484f65.zip unzip it ad put into ~/.config/obs-studio/ .

Start OBS and configure Shader

Now we can start OBS Studio, and with left click on the video source, filtri we can add new filter of type Shader.

We can load a file that we create as defish.effect

// Based on Sharpness shader of OBS Studio v27.0.0,
// And https://github.com/Oncorporation/obs-shaderfilter/
uniform float4x4 ViewProj;
uniform texture2d image;
uniform float sharpness;
uniform float texture_width;
uniform float texture_height;
sampler_state def_sampler {
Filter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};
struct VertData {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
VertData VSDefault(VertData v_in)
{
VertData vert_out;
vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
vert_out.uv = v_in.uv;
return vert_out;
}
float4 PSDrawBare(VertData v_in) : TARGET
{
int center_x_percent = 50;
int center_y_percent = 50;
float power = -sharpness;
float2 uv_pixel_interval;
uv_pixel_interval.x = 1.0 / texture_width;
uv_pixel_interval.y = 1.0 / texture_height;
float2 center_pos = float2(center_x_percent * .01, center_y_percent * .01);
float2 uv = v_in.uv;
float b;
if (uv_pixel_interval.x < uv_pixel_interval.y){
b = center_pos.x;
} else {
b = center_pos.y;
}
uv = center_pos + normalize(v_in.uv - center_pos) * atan(distance(center_pos, v_in.uv) * -power * 10.0) * b / atan(-power * b * 10.0);
return image.Sample(def_sampler, uv);
}
technique Draw
{
pass
{
vertex_shader = VSDefault(v_in);
pixel_shader = PSDrawBare(v_in);
}
}

Now you can see under the filter file some paramiters. Scroll to sharpness, it is the paramiter that defish the camera, you can set it experimetally, in my case 0,11.

Set Sharpness on Shader filter

Build (Untested)

If you want to buid:

git clone https://github.com/Xaymar/obs-StreamFX.git
cd obs-StreamFX
git checkout v0.10
git submodule sync
git submodule update --init --recursive
mkdir BUILD
cd BUILD
CC=/usr/bin/clang CXX=/usr/bin/clang++ cmake ../

Conclustion

Now you can defish your camera into OBS easily, this plugin get also other potentiality and you can write your Shader as you want to obtain spectacular custom effects.

Enjoy OBS, Linux and Open-Source!

--

--

Nicola Landro

Linux user and Open Source fun. Deep learning PhD. , Full stack web developer, Mobile developer, cloud engineer and Musitian.