Compare commits
7 Commits
8c60a46945
...
e950314ca1
| Author | SHA1 | Date | |
|---|---|---|---|
|
e950314ca1
|
|||
|
702d80b9a2
|
|||
|
8dcfd2d52d
|
|||
|
213ea05243
|
|||
|
8474d73ac1
|
|||
|
c91c9d44d9
|
|||
|
d346c69f69
|
20
README.md
20
README.md
@ -2,12 +2,24 @@
|
||||
|
||||
Shaders for Avidemux with OpenGL support
|
||||
|
||||
## GoPro fisheye removal
|
||||
## GoPro fisheye removal v2.0
|
||||
|
||||

|
||||
|
||||
### gopro_8:7 - Fisheye removal for GoPro 11+, 8:7 ratio, 4K, HyperSmooth off
|
||||
|
||||
#### What's new
|
||||
|
||||
- New method based on sensor size and focal length
|
||||
- Accurate frame widening
|
||||
- Fisheye aware subsampling
|
||||
- Rec.709 colorspace conversion _(requires to patch and rebuild Avidemux)_
|
||||
|
||||
#### Content
|
||||
|
||||
- avidemux.patch
|
||||
A patch to use GL_NEAREST instead of GL_LINEAR for the luminance channel (the shader is implementing bilinear interpolation with colorspace conversion).
|
||||
|
||||
- unfish_gopro_8:7.py
|
||||
Script to compute the parameters
|
||||
|
||||
@ -15,9 +27,9 @@ Script to compute the parameters
|
||||
Shader for fisheye removal
|
||||
|
||||
- preset_gopro_8:7.py
|
||||
Preset for mp4, 4K, high quality
|
||||
Preset for mp4, 4K, high quality compression
|
||||
|
||||
### Installation for BSD/GNU-Linux systems:
|
||||
#### Installation for BSD/GNU-Linux systems:
|
||||
|
||||
- Copy the preset into ~/.avidemux6/custom or ~/.local/share/avidemux6/custom
|
||||
- Copy the shader into /opt/rk/avidemux (or edit the preset to set the path)
|
||||
@ -26,7 +38,7 @@ Or just run the script install_gopro_8:7.sh
|
||||
|
||||
_For commercial OS's, figure out the paths yourself, then edit the preset to fix the path to the .glsl file_
|
||||
|
||||
### Usage:
|
||||
#### Usage:
|
||||
|
||||
- Load and edit video(s)
|
||||
- Select "Custom/preset_gopro_8:7" in the menu
|
||||
|
||||
28
gopro_8:7/avidemux.patch
Normal file
28
gopro_8:7/avidemux.patch
Normal file
@ -0,0 +1,28 @@
|
||||
From 42e283d8b7c5d950ff81cff788398665410bcd6b Mon Sep 17 00:00:00 2001
|
||||
Message-Id: <42e283d8b7c5d950ff81cff788398665410bcd6b.1759271917.git.roz@rozk.net>
|
||||
From: Roz K <roz@rozk.net>
|
||||
Date: Wed, 1 Oct 2025 00:38:19 +0200
|
||||
Subject: [PATCH] OpenGL: use nearest interpolation filter for Y texture
|
||||
|
||||
---
|
||||
avidemux/qt4/ADM_openGL/src/ADM_openGl.cpp | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/avidemux/qt4/ADM_openGL/src/ADM_openGl.cpp b/avidemux/qt4/ADM_openGL/src/ADM_openGl.cpp
|
||||
index ea389a1e6..b97a2034f 100644
|
||||
--- a/avidemux/qt4/ADM_openGL/src/ADM_openGl.cpp
|
||||
+++ b/avidemux/qt4/ADM_openGL/src/ADM_openGl.cpp
|
||||
@@ -236,8 +236,8 @@ void ADM_coreQtGl::uploadAllPlanes(ADMImage *image)
|
||||
glBindTexture(GL_TEXTURE_RECTANGLE_NV, texName[xplane]); // Use tex engine "texNum"
|
||||
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
- glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
- glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
+ glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, plane == PLANAR_Y ? GL_NEAREST : GL_LINEAR);
|
||||
+ glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, plane == PLANAR_Y ? GL_NEAREST : GL_LINEAR);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
|
||||
int pitch = (nbComponents == 1)? image->GetPitch(plane) : ALIGNX(image->GetWidth(plane),16); // ???
|
||||
--
|
||||
2.39.5
|
||||
|
||||
@ -101,16 +101,9 @@ adm.videoCodec(
|
||||
"ratecontrol.lookahead=40")
|
||||
adm.addVideoFilter(
|
||||
"shaderLoader", "shaderFile=/opt/rk/avidemux/unfish_gopro_8:7.glsl")
|
||||
adm.addVideoFilter(
|
||||
"crop",
|
||||
"top=80",
|
||||
"bottom=0",
|
||||
"left=0",
|
||||
"right=0",
|
||||
"ar_select=0")
|
||||
adm.addVideoFilter(
|
||||
"swscale",
|
||||
"width=2880",
|
||||
"width=2832",
|
||||
"height=2160",
|
||||
"algo=2",
|
||||
"sourceAR=0",
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
|
||||
#define color_conversion
|
||||
#define texture_filtering
|
||||
#define rotate_180
|
||||
//#define rotate_180
|
||||
//#define debug_borders
|
||||
|
||||
#undef highp // defined by Qt-OpenGl
|
||||
@ -37,9 +37,9 @@ uniform float pts;
|
||||
// parameters
|
||||
|
||||
const vec2 sensor_size = vec2(5.949440, 5.205760);
|
||||
const vec2 rectilinear_scale = vec2(1.138819, 1.0);
|
||||
const float equidistant_focal_length = 2.970000;
|
||||
const float rectilinear_focal_length = 2.167601;
|
||||
const vec2 rectilinear_scale = vec2(1.147370, 1.0);
|
||||
const float equidistant_focal_length = 2.920000;
|
||||
const float rectilinear_focal_length = 2.102263;
|
||||
|
||||
// constants
|
||||
|
||||
@ -78,39 +78,30 @@ const float luminance_min = 16.0 / 255.0;
|
||||
const float luminance_max = 235.0 / 255.0;
|
||||
const float luminance_range = luminance_max - luminance_min;
|
||||
|
||||
const vec2 chroma_min = vec2( 16.0 / 255.0);
|
||||
const vec2 chroma_max = vec2(240.0 / 255.0);
|
||||
const vec2 chroma_range = chroma_max - chroma_min;
|
||||
const vec2 chroma_center = vec2(0.5, 0.5);
|
||||
|
||||
const vec3 yuv_min = vec3(luminance_min, chroma_min);
|
||||
const vec3 yuv_range = vec3(luminance_range, chroma_range);
|
||||
const vec3 yuv_center = vec3(0.0, chroma_center);
|
||||
|
||||
float decode_luminance(const in float x) {
|
||||
float y = (x - luminance_min) / luminance_range;
|
||||
return (y < 0.081) ? (y / 4.5) : pow((y + 0.099) / 1.099, 1.0 / 0.45);
|
||||
}
|
||||
|
||||
vec2 decode_chroma(const in vec2 yz) {
|
||||
return (yz - chroma_min) / chroma_range - chroma_center;
|
||||
float encode_luminance(const in float l) {
|
||||
float x = (l < 0.018) ? (l * 4.5) : (pow(l, 0.45) * 1.099 - 0.099);
|
||||
return x * luminance_range + luminance_min;
|
||||
}
|
||||
|
||||
vec3 decode_pixel(const in vec3 pixel) {
|
||||
return vec3(decode_luminance(pixel.x), decode_chroma(pixel.yz));
|
||||
vec3 decode_ycbcr(const in vec3 pixel) {
|
||||
return vec3(decode_luminance(pixel.x), pixel.yz);
|
||||
}
|
||||
|
||||
vec3 encode_color(const in vec3 color) {
|
||||
float y = (color.x < 0.018) ? (color.x * 4.5) : (pow(color.x, 0.45) * 1.099 - 0.099);
|
||||
return (vec3(y, color.yz) + yuv_center) * yuv_range + yuv_min;
|
||||
vec3 encode_ycbcr(const in vec3 color) {
|
||||
return vec3(encode_luminance(color.x), color.yz);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define decode_luminance(_x) (_x)
|
||||
#define decode_chroma(_yz) (_yz)
|
||||
#define decode_pixel(_pixel) (_pixel)
|
||||
#define encode_color(_color) (_color)
|
||||
#define encode_luminance(_l) (_l)
|
||||
#define decode_ycbcr(_pixel) (_pixel)
|
||||
#define encode_ycbcr(_color) (_color)
|
||||
|
||||
#endif
|
||||
|
||||
@ -125,46 +116,27 @@ const vec2 corner_b = vec2(1.0, 0.0) + half_pixel;
|
||||
const vec2 corner_c = vec2(0.0, 1.0) + half_pixel;
|
||||
const vec2 corner_d = vec2(1.0, 1.0) + half_pixel;
|
||||
|
||||
vec2 bilinear_params(const in vec2 coord, out vec2 a, out vec2 b, out vec2 c, out vec2 d) {
|
||||
vec2 i, f = modf(coord - half_pixel, i);
|
||||
a = i + corner_a;
|
||||
b = i + corner_b;
|
||||
c = i + corner_c;
|
||||
d = i + corner_d;
|
||||
return f;
|
||||
}
|
||||
|
||||
vec3 texture_filter(const in vec2 y_coord) {
|
||||
vec2 a, b, c, d, f = bilinear_params(y_coord, a, b, c, d);
|
||||
vec2 i, f = modf(y_coord - half_pixel, i);
|
||||
float luminance = mix(
|
||||
mix(
|
||||
decode_luminance(texture2DRect(myTextureY, a).x),
|
||||
decode_luminance(texture2DRect(myTextureY, b).x),
|
||||
decode_luminance(texture2DRect(myTextureY, i + corner_a).x),
|
||||
decode_luminance(texture2DRect(myTextureY, i + corner_b).x),
|
||||
f.x),
|
||||
mix(
|
||||
decode_luminance(texture2DRect(myTextureY, c).x),
|
||||
decode_luminance(texture2DRect(myTextureY, d).x),
|
||||
decode_luminance(texture2DRect(myTextureY, i + corner_c).x),
|
||||
decode_luminance(texture2DRect(myTextureY, i + corner_d).x),
|
||||
f.x),
|
||||
f.y);
|
||||
f = bilinear_params(y_coord * 0.5, a, b, c, d);
|
||||
vec2 chroma = mix(
|
||||
mix(
|
||||
decode_chroma(vec2(texture2DRect(myTextureU, a).x, texture2DRect(myTextureV, a).x)),
|
||||
decode_chroma(vec2(texture2DRect(myTextureU, b).x, texture2DRect(myTextureV, b).x)),
|
||||
f.x),
|
||||
mix(
|
||||
decode_chroma(vec2(texture2DRect(myTextureU, c).x, texture2DRect(myTextureV, c).x)),
|
||||
decode_chroma(vec2(texture2DRect(myTextureU, d).x, texture2DRect(myTextureV, d).x)),
|
||||
f.x),
|
||||
f.y);
|
||||
return vec3(luminance, chroma);
|
||||
vec2 uv_coord = y_coord * 0.5;
|
||||
return vec3(luminance, texture2DRect(myTextureU, uv_coord).x, texture2DRect(myTextureV, uv_coord).x);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
vec3 texture_filter(const in vec2 y_coord) {
|
||||
vec2 uv_coord = y_coord * 0.5;
|
||||
return decode_pixel(vec3(
|
||||
return decode_ycbcr(vec3(
|
||||
texture2DRect(myTextureY, y_coord).x,
|
||||
texture2DRect(myTextureU, uv_coord).x,
|
||||
texture2DRect(myTextureV, uv_coord).x));
|
||||
@ -196,5 +168,5 @@ void main() {
|
||||
color += texture_sample(coord + offset);
|
||||
}
|
||||
}
|
||||
gl_FragColor = vec4(encode_color(color * subsampling_scale), 1.0);
|
||||
gl_FragColor = vec4(encode_ycbcr(color * subsampling_scale), 1.0);
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ print("gopro size : horizontal = %7.3f, vertical = %7.3f, diagonal = %7.3f (mm)
|
||||
|
||||
# https://thinglabs.io/gopro-focal-length-guide
|
||||
|
||||
gopro_focal_length = 2.97 # mm
|
||||
gopro_focal_length = 2.92
|
||||
|
||||
gopro_radius_horizontal = gopro_size_horizontal * 0.5
|
||||
gopro_radius_vertical = gopro_size_vertical * 0.5
|
||||
@ -92,33 +92,21 @@ output_size_vertical = gopro_size_vertical
|
||||
|
||||
output_scale_horizontal = output_size_horizontal / gopro_size_horizontal
|
||||
|
||||
print("""// parameters
|
||||
print("""// parameters\n
|
||||
const vec2 sensor_size = vec2(%.6f, %.6f);
|
||||
const vec2 rectilinear_scale = vec2(%.6f, 1.0);
|
||||
const float equidistant_focal_length = %.6f;
|
||||
const float rectilinear_focal_length = %.6f;
|
||||
const vec2 rectilinear_scale = vec2(%.6F, 1.0);""" % (
|
||||
const float rectilinear_focal_length = %.6f;""" % (
|
||||
gopro_size_horizontal, gopro_size_vertical,
|
||||
output_scale_horizontal,
|
||||
gopro_focal_length,
|
||||
rectilinear_focal_length_vertical,
|
||||
output_scale_horizontal)
|
||||
rectilinear_focal_length_vertical)
|
||||
)
|
||||
|
||||
print("\n--- filters parameters ---\n")
|
||||
|
||||
output_ratio_horizontal = 4.0
|
||||
output_ratio_vertical = 3.0
|
||||
|
||||
output_crop_ratio = output_ratio_vertical / (output_ratio_horizontal / output_scale_horizontal)
|
||||
|
||||
output_crop_horizontal = gopro_texture_horizontal
|
||||
output_crop_vertical = output_crop_horizontal * output_crop_ratio
|
||||
|
||||
print("crop : width = %d, height = %d" % (
|
||||
output_crop_horizontal,
|
||||
round(output_crop_vertical)))
|
||||
|
||||
def print_output_array(array_vertical):
|
||||
array_horizontal = (array_vertical / output_ratio_vertical) * output_ratio_horizontal
|
||||
array_horizontal = (array_vertical / gopro_array_vertical) * gopro_array_horizontal * output_scale_horizontal
|
||||
print("resize: width = %d, height = %d" % (
|
||||
round(array_horizontal / 4.0) * 4,
|
||||
array_vertical))
|
||||
|
||||
Reference in New Issue
Block a user