Compare commits
13 Commits
main
...
71cca0589e
| Author | SHA1 | Date | |
|---|---|---|---|
|
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
|
||||
|
||||
@ -1,20 +1,6 @@
|
||||
#PY <- Needed to identify #
|
||||
|
||||
# Fisheye removal for GoPro 11+, 8:7 ratio, without hypersmooth
|
||||
# Copyright (C) 2025 Roz K <roz@rozk.net>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
# RozK
|
||||
# Custom preset for GoPro, 8:7 ratio, without hypersmooth, output widened scaled to 4K (2160p), high bitrate
|
||||
|
||||
adm = Avidemux()
|
||||
adm.videoCodec(
|
||||
@ -102,19 +88,12 @@ adm.videoCodec(
|
||||
adm.addVideoFilter(
|
||||
"shaderLoader", "shaderFile=/opt/rk/avidemux/unfish_gopro_8:7.glsl")
|
||||
adm.addVideoFilter(
|
||||
"swscale",
|
||||
"width=2468",
|
||||
"height=2160",
|
||||
"algo=2",
|
||||
"sourceAR=0",
|
||||
"targetAR=0",
|
||||
"lockAR=False",
|
||||
"roundup=0")
|
||||
"swscale", "width=2792", "height=2160", "algo=2", "sourceAR=0", "targetAR=0", "lockAR=False", "roundup=0")
|
||||
adm.audioClearTracks()
|
||||
if adm.audioTotalTracksCount() <= 0:
|
||||
raise("Cannot add audio track 0, total tracks: " + str(adm.audioTotalTracksCount()))
|
||||
adm.audioAddTrack(0)
|
||||
adm.audioCodec(0, "LavAAC", "bitrate=192")
|
||||
adm.audioCodec(0, "LavAAC", "bitrate=128")
|
||||
adm.audioSetDrc2(0, 1, 1, 0.001, 0.2, 1, 2, -12)
|
||||
adm.audioSetEq(0, 0, 0, 0, 0, 880, 5000)
|
||||
adm.audioSetChannelGains(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
#version 130
|
||||
|
||||
// Fisheye removal for GoPro 11+, 8:7 ratio, without hypersmooth
|
||||
// Copyright (C) 2025 Roz K <roz@rozk.net>
|
||||
// Copyright (C) 2025 Jean-Baptiste Berlioz
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
@ -18,16 +17,14 @@
|
||||
|
||||
#extension GL_ARB_texture_rectangle: enable
|
||||
|
||||
#define color_conversion
|
||||
#define texture_filtering
|
||||
//#define rotate_180
|
||||
#define non_linear_decoding
|
||||
#define rotate_180
|
||||
//#define debug_borders
|
||||
|
||||
#undef highp // defined by Qt-OpenGl
|
||||
precision highp float;
|
||||
|
||||
// uniforms
|
||||
|
||||
uniform sampler2DRect myTextureY;
|
||||
uniform sampler2DRect myTextureU;
|
||||
uniform sampler2DRect myTextureV;
|
||||
@ -35,127 +32,84 @@ uniform vec2 myResolution;
|
||||
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 sensor_size = vec2(5.949440, 5.205760);
|
||||
const float equidistant_focal_length = 2.970000;
|
||||
const float rectilinear_focal_length = 2.167601;
|
||||
|
||||
// constants
|
||||
|
||||
const int subsampling = 8;
|
||||
const vec2 subsampling_step = vec2(1.0 / float(subsampling));
|
||||
const vec2 subsampling_start = subsampling_step * 0.5 - vec2(0.5);
|
||||
const int subsampling = 4;
|
||||
const vec2 subsampling_step = vec2(1.0 / float(subsampling));
|
||||
const vec2 subsampling_start = subsampling_step * 0.5 - vec2(0.5);
|
||||
const float subsampling_scale = 1.0 / float(subsampling * subsampling);
|
||||
|
||||
// reprojection
|
||||
|
||||
// variables
|
||||
vec2 texture_center;
|
||||
vec2 texture_to_sensor;
|
||||
vec2 sensor_to_texture;
|
||||
|
||||
void initialize() {
|
||||
texture_center = myResolution * 0.5;
|
||||
texture_to_sensor = (sensor_size / myResolution);
|
||||
texture_to_sensor = sensor_size / myResolution;
|
||||
#ifdef rotate_180
|
||||
texture_to_sensor *= -1.0;
|
||||
#endif
|
||||
sensor_to_texture = myResolution / sensor_size;
|
||||
}
|
||||
|
||||
vec2 equidistant_to_rectilinear(const in vec2 equidistant) {
|
||||
float rectilinear_radius = length(equidistant);
|
||||
vec2 equidistant_to_rectilinear(const in vec2 coord) {
|
||||
float rectilinear_radius = length(coord);
|
||||
float rectilinear_angle = atan(rectilinear_radius / rectilinear_focal_length);
|
||||
float equidistant_radius = rectilinear_angle * equidistant_focal_length;
|
||||
return equidistant * (equidistant_radius / (rectilinear_radius > 0.0 ? rectilinear_radius : 1.0));
|
||||
return coord * (equidistant_radius / rectilinear_radius);
|
||||
}
|
||||
|
||||
// color space (https://en.wikipedia.org/wiki/Rec._709)
|
||||
|
||||
#ifdef color_conversion
|
||||
|
||||
const float luminance_min = 16.0 / 255.0;
|
||||
const float luminance_max = 235.0 / 255.0;
|
||||
const float luminance_range = luminance_max - luminance_min;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
vec3 decode_ycbcr(const in vec3 pixel) {
|
||||
return vec3(decode_luminance(pixel.x), pixel.yz);
|
||||
}
|
||||
|
||||
vec3 encode_ycbcr(const in vec3 color) {
|
||||
return vec3(encode_luminance(color.x), color.yz);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define decode_luminance(_x) (_x)
|
||||
#define encode_luminance(_l) (_l)
|
||||
#define decode_ycbcr(_pixel) (_pixel)
|
||||
#define encode_ycbcr(_color) (_color)
|
||||
|
||||
#endif
|
||||
|
||||
// texture filtering
|
||||
|
||||
#ifdef texture_filtering
|
||||
|
||||
const vec2 half_pixel = vec2(0.5);
|
||||
|
||||
const vec2 corner_a = vec2(0.0, 0.0) + half_pixel;
|
||||
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;
|
||||
|
||||
vec3 texture_filter(const in vec2 y_coord) {
|
||||
vec2 i, f = modf(y_coord - half_pixel, i);
|
||||
float luminance = mix(
|
||||
mix(
|
||||
decode_luminance(texture2DRect(myTextureY, i + corner_a).x),
|
||||
decode_luminance(texture2DRect(myTextureY, i + corner_b).x),
|
||||
f.x),
|
||||
mix(
|
||||
decode_luminance(texture2DRect(myTextureY, i + corner_c).x),
|
||||
decode_luminance(texture2DRect(myTextureY, i + corner_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);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
vec3 texture_filter(const in vec2 y_coord) {
|
||||
vec2 uv_coord = y_coord * 0.5;
|
||||
return decode_ycbcr(vec3(
|
||||
texture2DRect(myTextureY, y_coord).x,
|
||||
texture2DRect(myTextureU, uv_coord).x,
|
||||
texture2DRect(myTextureV, uv_coord).x));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
vec3 texture_sample(const in vec2 equidistant) {
|
||||
vec2 rectilinear = texture_center + sensor_to_texture *
|
||||
equidistant_to_rectilinear((equidistant - texture_center) * texture_to_sensor);
|
||||
vec3 sample_texture(const in vec2 coord) {
|
||||
vec2 rectilinear = equidistant_to_rectilinear((coord - texture_center) * texture_to_sensor);
|
||||
vec2 y_coord = texture_center + rectilinear * sensor_to_texture;
|
||||
#ifdef debug_borders
|
||||
if (rectilinear.x < 0.0 || rectilinear.y < 0.0 ||
|
||||
rectilinear.x > myResolution.x || rectilinear.y > myResolution.y) {
|
||||
return vec3(235.0 / 255.0, 240.0 / 255.0, 240.0 / 255.0);
|
||||
if (y_coord.x < 0.0 || y_coord.y < 0.0 || y_coord.x > myResolution.x || y_coord.y > myResolution.y) {
|
||||
return vec3(16.0 / 255.0, 0.5, 0.5);
|
||||
}
|
||||
#endif
|
||||
return texture_filter(rectilinear);
|
||||
vec2 uv_coord = y_coord * 0.5;
|
||||
return vec3(
|
||||
texture2DRect(myTextureY, y_coord).x,
|
||||
texture2DRect(myTextureU, uv_coord).x,
|
||||
texture2DRect(myTextureV, uv_coord).x);
|
||||
}
|
||||
|
||||
// main
|
||||
#ifdef non_linear_decoding
|
||||
|
||||
// https://en.wikipedia.org/wiki/Rec._709
|
||||
|
||||
#define y_min ( 16.0 / 255.0)
|
||||
#define y_max (235.0 / 255.0)
|
||||
#define uv_min ( 16.0 / 255.0)
|
||||
#define uv_max (240.0 / 255.0)
|
||||
#define y_range (y_max - y_min)
|
||||
#define uv_range (uv_max - uv_min)
|
||||
|
||||
const vec3 yuv_min = vec3(y_min, uv_min, uv_min);
|
||||
const vec3 yuv_range = vec3(y_range, uv_range, uv_range);
|
||||
const vec3 yuv_center = vec3(0.0, 0.5, 0.5);
|
||||
|
||||
vec3 decode_pixel(const in vec3 pixel) {
|
||||
vec3 color = (pixel - yuv_min) / yuv_range - yuv_center;
|
||||
float l = (color.x < 0.081) ? (color.x / 4.5) : pow((color.x + 0.099) / 1.099, 1.0 / 0.45);
|
||||
return vec3(l, 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_pixel(_pixel) _pixel
|
||||
#define encode_color(_color) _color
|
||||
|
||||
#endif // non_linear_decoding
|
||||
|
||||
void main() {
|
||||
initialize();
|
||||
@ -164,8 +118,8 @@ void main() {
|
||||
for (int y = 0; y < subsampling; y++) {
|
||||
for (int x = 0; x < subsampling; x++) {
|
||||
vec2 offset = subsampling_start + subsampling_step * vec2(x, y);
|
||||
color += texture_sample(coord + offset);
|
||||
color += decode_pixel(sample_texture(coord + offset));
|
||||
}
|
||||
}
|
||||
gl_FragColor = vec4(encode_ycbcr(color * subsampling_scale), 1.0);
|
||||
gl_FragColor = vec4(encode_color(color * subsampling_scale), 1.0);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
# Fisheye removal for GoPro 11+, 8:7 ratio, without hypersmooth
|
||||
# Copyright (C) 2025 Roz K <roz@rozk.net>
|
||||
# Copyright (C) 2025 Jean-Baptiste Berlioz
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
@ -27,9 +27,6 @@ sensor_pixel_size = 1.12 * 0.001 # mm
|
||||
gopro_array_horizontal = 5312 # p
|
||||
gopro_array_vertical = 4648 # p
|
||||
|
||||
gopro_texture_horizontal = 3840 # p
|
||||
gopro_texture_vertical = 3360 # p
|
||||
|
||||
gopro_size_horizontal = gopro_array_horizontal * sensor_pixel_size
|
||||
gopro_size_vertical = gopro_array_vertical * sensor_pixel_size
|
||||
gopro_size_diagonal = math.hypot(gopro_size_horizontal, gopro_size_vertical)
|
||||
@ -41,7 +38,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
|
||||
@ -73,12 +70,12 @@ print("linear focal: horizontal = %7.3f, vertical = %7.3f, diagonal = %7.3f (mm)
|
||||
rectilinear_focal_length_vertical,
|
||||
rectilinear_focal_length_diagonal))
|
||||
|
||||
rectilinear_radius = lambda angle: rectilinear_focal_length_vertical * math.tan(math.radians(angle))
|
||||
rectilinear_angle = lambda radius: math.degrees(math.atan(radius / rectilinear_focal_length_vertical))
|
||||
rectilinear_radius = lambda angle, focal_length: focal_length * math.tan(math.radians(angle))
|
||||
rectilinear_angle = lambda radius, focal_length: math.degrees(math.atan(radius / focal_length))
|
||||
|
||||
rectilinear_fov_horizontal = 2.0 * rectilinear_angle(gopro_radius_horizontal)
|
||||
rectilinear_fov_vertical = 2.0 * rectilinear_angle(gopro_radius_vertical)
|
||||
rectilinear_fov_diagonal = 2.0 * rectilinear_angle(gopro_radius_diagonal)
|
||||
rectilinear_fov_horizontal = 2.0 * rectilinear_angle(gopro_radius_horizontal, rectilinear_focal_length_vertical)
|
||||
rectilinear_fov_vertical = 2.0 * rectilinear_angle(gopro_radius_vertical, rectilinear_focal_length_vertical)
|
||||
rectilinear_fov_diagonal = 2.0 * rectilinear_angle(gopro_radius_diagonal, rectilinear_focal_length_vertical)
|
||||
|
||||
print("linear fov : horizontal = %7.3f, vertical = %7.3f, diagonal = %7.3f (deg)" % (
|
||||
rectilinear_fov_horizontal,
|
||||
@ -87,8 +84,8 @@ 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);
|
||||
print("""// parameters
|
||||
const vec2 sensor_size = vec2(%.6f, %.6f);
|
||||
const float equidistant_focal_length = %.6f;
|
||||
const float rectilinear_focal_length = %.6f;""" % (
|
||||
gopro_size_horizontal, gopro_size_vertical,
|
||||
@ -96,13 +93,14 @@ const float rectilinear_focal_length = %.6f;""" % (
|
||||
rectilinear_focal_length_vertical)
|
||||
)
|
||||
|
||||
print("\n--- output size ---\n")
|
||||
|
||||
def print_output_array(array_vertical):
|
||||
array_horizontal = (array_vertical / gopro_array_vertical) * gopro_array_horizontal
|
||||
print("resize: width = %d, height = %d" % (
|
||||
round(array_horizontal / 4.0) * 4,
|
||||
array_vertical))
|
||||
|
||||
print_output_array(2160)
|
||||
print_output_array(1080)
|
||||
# print("\n--- filter parameters 4K ---\n")
|
||||
#
|
||||
# width_scale = rectilinear_focal_length_vertical / rectilinear_focal_length_horizontal
|
||||
#
|
||||
# output_height = 2160
|
||||
# output_width = int(round((output_height / gopro_array_vertical) * gopro_array_horizontal * width_scale))
|
||||
#
|
||||
# print("resize: width = %d, height = %d, ratio = %f" % (
|
||||
# output_width,
|
||||
# output_height,
|
||||
# output_width / output_height))
|
||||
|
||||
Reference in New Issue
Block a user