Compare commits
	
		
			16 Commits
		
	
	
		
			main
			...
			8c60a46945
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						8c60a46945
	
				 | 
					
					
						|||
| 
						
						
							
						
						b5d9b30ee9
	
				 | 
					
					
						|||
| 
						
						
							
						
						a0cba047e5
	
				 | 
					
					
						|||
| 
						
						
							
						
						71cca0589e
	
				 | 
					
					
						|||
| 
						
						
							
						
						67b60b0e69
	
				 | 
					
					
						|||
| 
						
						
							
						
						79b66d47ee
	
				 | 
					
					
						|||
| 
						
						
							
						
						64e693fe4a
	
				 | 
					
					
						|||
| 
						
						
							
						
						f5b429217c
	
				 | 
					
					
						|||
| 
						
						
							
						
						d74f3dfe67
	
				 | 
					
					
						|||
| 
						
						
							
						
						f7540d5bca
	
				 | 
					
					
						|||
| 
						
						
							
						
						676e63eae5
	
				 | 
					
					
						|||
| 
						
						
							
						
						acd59515aa
	
				 | 
					
					
						|||
| 
						
						
							
						
						d7f0cb427d
	
				 | 
					
					
						|||
| 
						
						
							
						
						95175afb5d
	
				 | 
					
					
						|||
| 
						
						
							
						
						1385b3e6f3
	
				 | 
					
					
						|||
| 
						
						
							
						
						e6c417f0f6
	
				 | 
					
					
						
							
								
								
									
										28
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								README.md
									
									
									
									
									
								
							@ -2,24 +2,12 @@
 | 
			
		||||
 | 
			
		||||
Shaders for Avidemux with OpenGL support
 | 
			
		||||
 | 
			
		||||
## GoPro fisheye removal v2.0
 | 
			
		||||
## GoPro fisheye removal
 | 
			
		||||
 | 
			
		||||

 | 
			
		||||

 | 
			
		||||
 | 
			
		||||
### 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
 | 
			
		||||
 | 
			
		||||
#### Content
 | 
			
		||||
 | 
			
		||||
- avidemux.patch  
 | 
			
		||||
Optional 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
 | 
			
		||||
 | 
			
		||||
@ -27,9 +15,9 @@ Script to compute the parameters
 | 
			
		||||
Shader for fisheye removal
 | 
			
		||||
 | 
			
		||||
- preset_gopro_8:7.py  
 | 
			
		||||
Preset for mp4, 4K, high quality compression
 | 
			
		||||
Preset for mp4, 4K, high quality
 | 
			
		||||
 | 
			
		||||
#### 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)  
 | 
			
		||||
@ -38,15 +26,9 @@ 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
 | 
			
		||||
- Modify and/or add filters
 | 
			
		||||
- Save the video
 | 
			
		||||
 | 
			
		||||
#### Shader options
 | 
			
		||||
 | 
			
		||||
- #define color_conversion: comment out to disable gamma correction for the luminance channel
 | 
			
		||||
- #define texture_filtering: comment out to disable custom bilinear filtering for the luminance channel
 | 
			
		||||
- #define rotate_180: uncomment to rotate the image by 180 degrees
 | 
			
		||||
 | 
			
		||||
@ -1,28 +0,0 @@
 | 
			
		||||
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,9 +101,16 @@ 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=2468",
 | 
			
		||||
    "width=2880",
 | 
			
		||||
    "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,8 +37,9 @@ uniform float pts;
 | 
			
		||||
// parameters
 | 
			
		||||
 | 
			
		||||
const vec2  sensor_size              = vec2(5.949440, 5.205760);
 | 
			
		||||
const float equidistant_focal_length = 2.920000;
 | 
			
		||||
const float rectilinear_focal_length = 2.102263;
 | 
			
		||||
const vec2  rectilinear_scale        = vec2(1.138819, 1.0);
 | 
			
		||||
const float equidistant_focal_length = 2.970000;
 | 
			
		||||
const float rectilinear_focal_length = 2.167601;
 | 
			
		||||
 | 
			
		||||
// constants
 | 
			
		||||
 | 
			
		||||
@ -55,7 +56,7 @@ vec2 sensor_to_texture;
 | 
			
		||||
 | 
			
		||||
void initialize() {
 | 
			
		||||
    texture_center = myResolution * 0.5;
 | 
			
		||||
    texture_to_sensor = (sensor_size / myResolution);
 | 
			
		||||
    texture_to_sensor = (sensor_size / myResolution) * rectilinear_scale;
 | 
			
		||||
#ifdef rotate_180
 | 
			
		||||
    texture_to_sensor *= -1.0;
 | 
			
		||||
#endif
 | 
			
		||||
@ -77,30 +78,39 @@ 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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
vec2 decode_chroma(const in vec2 yz) {
 | 
			
		||||
    return (yz - chroma_min) / chroma_range - chroma_center;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
vec3 decode_ycbcr(const in vec3 pixel) {
 | 
			
		||||
    return vec3(decode_luminance(pixel.x), pixel.yz);
 | 
			
		||||
vec3 decode_pixel(const in vec3 pixel) {
 | 
			
		||||
    return vec3(decode_luminance(pixel.x), decode_chroma(pixel.yz));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
vec3 encode_ycbcr(const in vec3 color) {
 | 
			
		||||
    return vec3(encode_luminance(color.x), color.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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#else
 | 
			
		||||
 | 
			
		||||
#define decode_luminance(_x) (_x)
 | 
			
		||||
#define encode_luminance(_l) (_l)
 | 
			
		||||
#define decode_ycbcr(_pixel) (_pixel)
 | 
			
		||||
#define encode_ycbcr(_color) (_color)
 | 
			
		||||
#define decode_chroma(_yz)   (_yz)
 | 
			
		||||
#define decode_pixel(_pixel) (_pixel)
 | 
			
		||||
#define encode_color(_color) (_color)
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
@ -115,27 +125,46 @@ 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 i, f = modf(y_coord - half_pixel, i);
 | 
			
		||||
    vec2 a, b, c, d, f = bilinear_params(y_coord, a, b, c, d);
 | 
			
		||||
    float luminance = mix(
 | 
			
		||||
        mix(
 | 
			
		||||
            decode_luminance(texture2DRect(myTextureY, i + corner_a).x),
 | 
			
		||||
            decode_luminance(texture2DRect(myTextureY, i + corner_b).x),
 | 
			
		||||
            decode_luminance(texture2DRect(myTextureY, a).x),
 | 
			
		||||
            decode_luminance(texture2DRect(myTextureY, b).x),
 | 
			
		||||
            f.x),
 | 
			
		||||
        mix(
 | 
			
		||||
            decode_luminance(texture2DRect(myTextureY, i + corner_c).x),
 | 
			
		||||
            decode_luminance(texture2DRect(myTextureY, i + corner_d).x),
 | 
			
		||||
            decode_luminance(texture2DRect(myTextureY, c).x),
 | 
			
		||||
            decode_luminance(texture2DRect(myTextureY, d).x),
 | 
			
		||||
            f.x),
 | 
			
		||||
        f.y);
 | 
			
		||||
    vec2 uv_coord = y_coord * 0.5;
 | 
			
		||||
    return vec3(luminance, texture2DRect(myTextureU, uv_coord).x, texture2DRect(myTextureV, uv_coord).x);
 | 
			
		||||
    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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#else
 | 
			
		||||
 | 
			
		||||
vec3 texture_filter(const in vec2 y_coord) {
 | 
			
		||||
    vec2 uv_coord = y_coord * 0.5;
 | 
			
		||||
    return decode_ycbcr(vec3(
 | 
			
		||||
    return decode_pixel(vec3(
 | 
			
		||||
        texture2DRect(myTextureY, y_coord).x,
 | 
			
		||||
        texture2DRect(myTextureU, uv_coord).x,
 | 
			
		||||
        texture2DRect(myTextureV, uv_coord).x));
 | 
			
		||||
@ -167,5 +196,5 @@ void main() {
 | 
			
		||||
            color += texture_sample(coord + offset);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    gl_FragColor = vec4(encode_ycbcr(color * subsampling_scale), 1.0);
 | 
			
		||||
    gl_FragColor = vec4(encode_color(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.92
 | 
			
		||||
gopro_focal_length = 2.97 # mm
 | 
			
		||||
 | 
			
		||||
gopro_radius_horizontal = gopro_size_horizontal * 0.5
 | 
			
		||||
gopro_radius_vertical   = gopro_size_vertical   * 0.5
 | 
			
		||||
@ -87,19 +87,38 @@ print("linear fov  : horizontal = %7.3f, vertical = %7.3f, diagonal = %7.3f (deg
 | 
			
		||||
 | 
			
		||||
print("\n--- shader parameters ---\n")
 | 
			
		||||
 | 
			
		||||
print("""// parameters\n
 | 
			
		||||
const vec2  sensor_size              = vec2(%.6f, %.6f);
 | 
			
		||||
output_size_horizontal = 2.0 * rectilinear_radius(gopro_fov_horizontal * 0.5)
 | 
			
		||||
output_size_vertical   = gopro_size_vertical
 | 
			
		||||
 | 
			
		||||
output_scale_horizontal = output_size_horizontal / gopro_size_horizontal
 | 
			
		||||
 | 
			
		||||
print("""// parameters
 | 
			
		||||
const vec2 sensor_size = vec2(%.6f, %.6f);
 | 
			
		||||
const float equidistant_focal_length = %.6f;
 | 
			
		||||
const float rectilinear_focal_length = %.6f;""" % (
 | 
			
		||||
const float rectilinear_focal_length = %.6f;
 | 
			
		||||
const vec2 rectilinear_scale = vec2(%.6F, 1.0);""" % (
 | 
			
		||||
    gopro_size_horizontal, gopro_size_vertical,
 | 
			
		||||
    gopro_focal_length,
 | 
			
		||||
    rectilinear_focal_length_vertical)
 | 
			
		||||
    rectilinear_focal_length_vertical,
 | 
			
		||||
    output_scale_horizontal)
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
print("\n--- output size ---\n")
 | 
			
		||||
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 / gopro_array_vertical) * gopro_array_horizontal
 | 
			
		||||
    array_horizontal = (array_vertical / output_ratio_vertical) * output_ratio_horizontal
 | 
			
		||||
    print("resize: width = %d, height = %d" % (
 | 
			
		||||
        round(array_horizontal / 4.0) * 4,
 | 
			
		||||
        array_vertical))
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user