v2.0, better quality, less perspective deformation (#1)
Reviewed-on: #1
This commit is contained in:
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
|
||||
|
@ -1,36 +0,0 @@
|
||||
# RozK
|
||||
# Computes fisheye removal parameters for GoPro 11+, 8:7 ratio, without hypersmooth,
|
||||
# keeping the vertical FOV and widening the frame to preserve the diagonal FOV
|
||||
|
||||
# https://www.bobatkins.com/photography/technical/field_of_view.html
|
||||
# https://community.gopro.com/s/article/HERO11-Black-Mini-Digital-Lenses-FOV-Information?language=fr
|
||||
|
||||
import math
|
||||
|
||||
frame_width = 8
|
||||
frame_height = 7
|
||||
input_ratio = frame_width / frame_height
|
||||
|
||||
input_vertical_fov = 108.0
|
||||
input_diagonal_fov = 156.0
|
||||
|
||||
input_vertical_length = math.radians(input_vertical_fov * 0.5)
|
||||
input_diagonal_length = math.radians(input_diagonal_fov * 0.5)
|
||||
|
||||
output_horizontal_length = math.sqrt((input_diagonal_length ** 2) / (input_vertical_length ** 2))
|
||||
output_diagonal_length = math.hypot(output_horizontal_length, input_vertical_length)
|
||||
output_diagonal_fov = math.degrees(math.atan(output_diagonal_length)) * 2.0
|
||||
|
||||
output_ratio = 1.0 / (output_horizontal_length / input_vertical_length)
|
||||
|
||||
print("Output FOV = %f" % output_diagonal_fov)
|
||||
print("Output Ratio = %f" % output_ratio)
|
||||
print("= Resolutions =====================")
|
||||
|
||||
def width_rounded_8(height):
|
||||
width = int(round(height * input_ratio))
|
||||
return ((width + 4) // 8) * 8
|
||||
|
||||
print("HD = %i x 720" % width_rounded_8(720))
|
||||
print("Full HD = %i x 1080" % width_rounded_8(1080))
|
||||
print("4K = %i x 2160" % width_rounded_8(2160))
|
@ -1,6 +1,20 @@
|
||||
#PY <- Needed to identify #
|
||||
# RozK
|
||||
# Custom preset for GoPro, 8:7 ratio, without hypersmooth, output widened scaled to 4K (2160p), high bitrate
|
||||
|
||||
# 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/>.
|
||||
|
||||
adm = Avidemux()
|
||||
adm.videoCodec(
|
||||
@ -12,8 +26,8 @@ adm.videoCodec(
|
||||
"general.tuning=film",
|
||||
"general.profile=high",
|
||||
"general.fast_decode=False",
|
||||
"general.zero_latency=False",
|
||||
"general.fast_first_pass=True",
|
||||
"general.zero_latency=True",
|
||||
"general.fast_first_pass=False",
|
||||
"general.blueray_compatibility=False",
|
||||
"general.fake_interlaced=False",
|
||||
"level=-1",
|
||||
@ -85,19 +99,29 @@ adm.videoCodec(
|
||||
"ratecontrol.aq_strength=1.000000",
|
||||
"ratecontrol.mb_tree=True",
|
||||
"ratecontrol.lookahead=40")
|
||||
adm.clearVideoFilters()
|
||||
adm.addVideoFilter(
|
||||
"shaderLoader",
|
||||
"shaderFile=/opt/rk/avidemux/unfish_gopro_8:7.glsl")
|
||||
"shaderLoader", "shaderFile=/opt/rk/avidemux/unfish_gopro_8:7.glsl")
|
||||
adm.addVideoFilter(
|
||||
"swscale",
|
||||
"width=2472",
|
||||
"width=2468",
|
||||
"height=2160",
|
||||
"algo=2",
|
||||
"sourceAR=0",
|
||||
"targetAR=0",
|
||||
"lockAR=False",
|
||||
"roundup=2")
|
||||
"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.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)
|
||||
adm.audioSetChannelDelays(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
||||
adm.audioSetChannelRemap(0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8)
|
||||
adm.audioSetShift(0, 0, 0)
|
||||
adm.audioSetNormalize2(0, 1, 10, -30)
|
||||
adm.setContainer(
|
||||
"MP4",
|
||||
"muxerType=0",
|
@ -1,109 +0,0 @@
|
||||
#PY <- Needed to identify #
|
||||
# RozK
|
||||
# Custom preset for GoPro, 8:7 ratio, without hypersmooth, output widened scaled to 4K (2160p)
|
||||
|
||||
adm = Avidemux()
|
||||
adm.videoCodec(
|
||||
"x264",
|
||||
"useAdvancedConfiguration=False",
|
||||
"general.params=CBR=32768",
|
||||
"general.threads=0",
|
||||
"general.preset=slow",
|
||||
"general.tuning=film",
|
||||
"general.profile=high",
|
||||
"general.fast_decode=False",
|
||||
"general.zero_latency=False",
|
||||
"general.fast_first_pass=True",
|
||||
"general.blueray_compatibility=False",
|
||||
"general.fake_interlaced=False",
|
||||
"level=-1",
|
||||
"vui.sar_height=1",
|
||||
"vui.sar_width=1",
|
||||
"vui.overscan=0",
|
||||
"vui.vidformat=5",
|
||||
"vui.fullrange=False",
|
||||
"vui.colorprim=2",
|
||||
"vui.transfer=2",
|
||||
"vui.colmatrix=2",
|
||||
"vui.chroma_loc=0",
|
||||
"MaxRefFrames=3",
|
||||
"MinIdr=25",
|
||||
"MaxIdr=250",
|
||||
"i_scenecut_threshold=40",
|
||||
"intra_refresh=False",
|
||||
"MaxBFrame=3",
|
||||
"i_bframe_adaptive=1",
|
||||
"i_bframe_bias=0",
|
||||
"i_bframe_pyramid=2",
|
||||
"b_deblocking_filter=True",
|
||||
"i_deblocking_filter_alphac0=0",
|
||||
"i_deblocking_filter_beta=0",
|
||||
"cabac=True",
|
||||
"interlaced=False",
|
||||
"constrained_intra=False",
|
||||
"tff=True",
|
||||
"fake_interlaced=False",
|
||||
"analyze.b_8x8=True",
|
||||
"analyze.b_i4x4=True",
|
||||
"analyze.b_i8x8=True",
|
||||
"analyze.b_p8x8=True",
|
||||
"analyze.b_p16x16=False",
|
||||
"analyze.b_b16x16=False",
|
||||
"analyze.weighted_pred=2",
|
||||
"analyze.weighted_bipred=True",
|
||||
"analyze.direct_mv_pred=1",
|
||||
"analyze.chroma_offset=0",
|
||||
"analyze.me_method=1",
|
||||
"analyze.me_range=16",
|
||||
"analyze.mv_range=-1",
|
||||
"analyze.mv_range_thread=-1",
|
||||
"analyze.subpel_refine=7",
|
||||
"analyze.chroma_me=True",
|
||||
"analyze.mixed_references=True",
|
||||
"analyze.trellis=1",
|
||||
"analyze.psy_rd=1.000000",
|
||||
"analyze.psy_trellis=0.000000",
|
||||
"analyze.fast_pskip=True",
|
||||
"analyze.dct_decimate=True",
|
||||
"analyze.noise_reduction=0",
|
||||
"analyze.psy=True",
|
||||
"analyze.intra_luma=11",
|
||||
"analyze.inter_luma=21",
|
||||
"ratecontrol.rc_method=0",
|
||||
"ratecontrol.qp_constant=0",
|
||||
"ratecontrol.qp_min=10",
|
||||
"ratecontrol.qp_max=51",
|
||||
"ratecontrol.qp_step=4",
|
||||
"ratecontrol.bitrate=0",
|
||||
"ratecontrol.rate_tolerance=1.000000",
|
||||
"ratecontrol.vbv_max_bitrate=0",
|
||||
"ratecontrol.vbv_buffer_size=0",
|
||||
"ratecontrol.vbv_buffer_init=1",
|
||||
"ratecontrol.ip_factor=1.400000",
|
||||
"ratecontrol.pb_factor=1.300000",
|
||||
"ratecontrol.aq_mode=1",
|
||||
"ratecontrol.aq_strength=1.000000",
|
||||
"ratecontrol.mb_tree=True",
|
||||
"ratecontrol.lookahead=40")
|
||||
adm.clearVideoFilters()
|
||||
adm.addVideoFilter(
|
||||
"shaderLoader",
|
||||
"shaderFile=/opt/rk/avidemux/unfish_gopro_8:7.glsl")
|
||||
adm.addVideoFilter(
|
||||
"swscale",
|
||||
"width=2472",
|
||||
"height=2160",
|
||||
"algo=2",
|
||||
"sourceAR=0",
|
||||
"targetAR=0",
|
||||
"lockAR=False",
|
||||
"roundup=2")
|
||||
adm.setContainer(
|
||||
"MP4",
|
||||
"muxerType=0",
|
||||
"optimize=1",
|
||||
"forceAspectRatio=False",
|
||||
"aspectRatio=1",
|
||||
"displayWidth=1280",
|
||||
"rotation=0",
|
||||
"clockfreq=0")
|
@ -1,109 +0,0 @@
|
||||
#PY <- Needed to identify #
|
||||
# RozK
|
||||
# Custom preset for GoPro, 8:7 ratio, without hypersmooth, output widened scaled to Full HD (1080p)
|
||||
|
||||
adm = Avidemux()
|
||||
adm.videoCodec(
|
||||
"x264",
|
||||
"useAdvancedConfiguration=False",
|
||||
"general.params=CBR=16384",
|
||||
"general.threads=0",
|
||||
"general.preset=slow",
|
||||
"general.tuning=film",
|
||||
"general.profile=high",
|
||||
"general.fast_decode=False",
|
||||
"general.zero_latency=False",
|
||||
"general.fast_first_pass=True",
|
||||
"general.blueray_compatibility=False",
|
||||
"general.fake_interlaced=False",
|
||||
"level=-1",
|
||||
"vui.sar_height=1",
|
||||
"vui.sar_width=1",
|
||||
"vui.overscan=0",
|
||||
"vui.vidformat=5",
|
||||
"vui.fullrange=False",
|
||||
"vui.colorprim=2",
|
||||
"vui.transfer=2",
|
||||
"vui.colmatrix=2",
|
||||
"vui.chroma_loc=0",
|
||||
"MaxRefFrames=3",
|
||||
"MinIdr=25",
|
||||
"MaxIdr=250",
|
||||
"i_scenecut_threshold=40",
|
||||
"intra_refresh=False",
|
||||
"MaxBFrame=3",
|
||||
"i_bframe_adaptive=1",
|
||||
"i_bframe_bias=0",
|
||||
"i_bframe_pyramid=2",
|
||||
"b_deblocking_filter=True",
|
||||
"i_deblocking_filter_alphac0=0",
|
||||
"i_deblocking_filter_beta=0",
|
||||
"cabac=True",
|
||||
"interlaced=False",
|
||||
"constrained_intra=False",
|
||||
"tff=True",
|
||||
"fake_interlaced=False",
|
||||
"analyze.b_8x8=True",
|
||||
"analyze.b_i4x4=True",
|
||||
"analyze.b_i8x8=True",
|
||||
"analyze.b_p8x8=True",
|
||||
"analyze.b_p16x16=False",
|
||||
"analyze.b_b16x16=False",
|
||||
"analyze.weighted_pred=2",
|
||||
"analyze.weighted_bipred=True",
|
||||
"analyze.direct_mv_pred=1",
|
||||
"analyze.chroma_offset=0",
|
||||
"analyze.me_method=1",
|
||||
"analyze.me_range=16",
|
||||
"analyze.mv_range=-1",
|
||||
"analyze.mv_range_thread=-1",
|
||||
"analyze.subpel_refine=7",
|
||||
"analyze.chroma_me=True",
|
||||
"analyze.mixed_references=True",
|
||||
"analyze.trellis=1",
|
||||
"analyze.psy_rd=1.000000",
|
||||
"analyze.psy_trellis=0.000000",
|
||||
"analyze.fast_pskip=True",
|
||||
"analyze.dct_decimate=True",
|
||||
"analyze.noise_reduction=0",
|
||||
"analyze.psy=True",
|
||||
"analyze.intra_luma=11",
|
||||
"analyze.inter_luma=21",
|
||||
"ratecontrol.rc_method=0",
|
||||
"ratecontrol.qp_constant=0",
|
||||
"ratecontrol.qp_min=10",
|
||||
"ratecontrol.qp_max=51",
|
||||
"ratecontrol.qp_step=4",
|
||||
"ratecontrol.bitrate=0",
|
||||
"ratecontrol.rate_tolerance=1.000000",
|
||||
"ratecontrol.vbv_max_bitrate=0",
|
||||
"ratecontrol.vbv_buffer_size=0",
|
||||
"ratecontrol.vbv_buffer_init=1",
|
||||
"ratecontrol.ip_factor=1.400000",
|
||||
"ratecontrol.pb_factor=1.300000",
|
||||
"ratecontrol.aq_mode=1",
|
||||
"ratecontrol.aq_strength=1.000000",
|
||||
"ratecontrol.mb_tree=True",
|
||||
"ratecontrol.lookahead=40")
|
||||
adm.clearVideoFilters()
|
||||
adm.addVideoFilter(
|
||||
"shaderLoader",
|
||||
"shaderFile=/opt/rk/avidemux/unfish_gopro_8:7.glsl")
|
||||
adm.addVideoFilter(
|
||||
"swscale",
|
||||
"width=1232",
|
||||
"height=1080",
|
||||
"algo=2",
|
||||
"sourceAR=0",
|
||||
"targetAR=0",
|
||||
"lockAR=False",
|
||||
"roundup=2")
|
||||
adm.setContainer(
|
||||
"MP4",
|
||||
"muxerType=0",
|
||||
"optimize=1",
|
||||
"forceAspectRatio=False",
|
||||
"aspectRatio=1",
|
||||
"displayWidth=1280",
|
||||
"rotation=0",
|
||||
"clockfreq=0")
|
@ -1,109 +0,0 @@
|
||||
#PY <- Needed to identify #
|
||||
# RozK
|
||||
# Custom preset for GoPro, 8:7 ratio, without hypersmooth, output widened scaled to HD (720p)
|
||||
|
||||
adm = Avidemux()
|
||||
adm.videoCodec(
|
||||
"x264",
|
||||
"useAdvancedConfiguration=False",
|
||||
"general.params=CBR=12288",
|
||||
"general.threads=0",
|
||||
"general.preset=slow",
|
||||
"general.tuning=film",
|
||||
"general.profile=high",
|
||||
"general.fast_decode=False",
|
||||
"general.zero_latency=False",
|
||||
"general.fast_first_pass=True",
|
||||
"general.blueray_compatibility=False",
|
||||
"general.fake_interlaced=False",
|
||||
"level=-1",
|
||||
"vui.sar_height=1",
|
||||
"vui.sar_width=1",
|
||||
"vui.overscan=0",
|
||||
"vui.vidformat=5",
|
||||
"vui.fullrange=False",
|
||||
"vui.colorprim=2",
|
||||
"vui.transfer=2",
|
||||
"vui.colmatrix=2",
|
||||
"vui.chroma_loc=0",
|
||||
"MaxRefFrames=3",
|
||||
"MinIdr=25",
|
||||
"MaxIdr=250",
|
||||
"i_scenecut_threshold=40",
|
||||
"intra_refresh=False",
|
||||
"MaxBFrame=3",
|
||||
"i_bframe_adaptive=1",
|
||||
"i_bframe_bias=0",
|
||||
"i_bframe_pyramid=2",
|
||||
"b_deblocking_filter=True",
|
||||
"i_deblocking_filter_alphac0=0",
|
||||
"i_deblocking_filter_beta=0",
|
||||
"cabac=True",
|
||||
"interlaced=False",
|
||||
"constrained_intra=False",
|
||||
"tff=True",
|
||||
"fake_interlaced=False",
|
||||
"analyze.b_8x8=True",
|
||||
"analyze.b_i4x4=True",
|
||||
"analyze.b_i8x8=True",
|
||||
"analyze.b_p8x8=True",
|
||||
"analyze.b_p16x16=False",
|
||||
"analyze.b_b16x16=False",
|
||||
"analyze.weighted_pred=2",
|
||||
"analyze.weighted_bipred=True",
|
||||
"analyze.direct_mv_pred=1",
|
||||
"analyze.chroma_offset=0",
|
||||
"analyze.me_method=1",
|
||||
"analyze.me_range=16",
|
||||
"analyze.mv_range=-1",
|
||||
"analyze.mv_range_thread=-1",
|
||||
"analyze.subpel_refine=7",
|
||||
"analyze.chroma_me=True",
|
||||
"analyze.mixed_references=True",
|
||||
"analyze.trellis=1",
|
||||
"analyze.psy_rd=1.000000",
|
||||
"analyze.psy_trellis=0.000000",
|
||||
"analyze.fast_pskip=True",
|
||||
"analyze.dct_decimate=True",
|
||||
"analyze.noise_reduction=0",
|
||||
"analyze.psy=True",
|
||||
"analyze.intra_luma=11",
|
||||
"analyze.inter_luma=21",
|
||||
"ratecontrol.rc_method=0",
|
||||
"ratecontrol.qp_constant=0",
|
||||
"ratecontrol.qp_min=10",
|
||||
"ratecontrol.qp_max=51",
|
||||
"ratecontrol.qp_step=4",
|
||||
"ratecontrol.bitrate=0",
|
||||
"ratecontrol.rate_tolerance=1.000000",
|
||||
"ratecontrol.vbv_max_bitrate=0",
|
||||
"ratecontrol.vbv_buffer_size=0",
|
||||
"ratecontrol.vbv_buffer_init=1",
|
||||
"ratecontrol.ip_factor=1.400000",
|
||||
"ratecontrol.pb_factor=1.300000",
|
||||
"ratecontrol.aq_mode=1",
|
||||
"ratecontrol.aq_strength=1.000000",
|
||||
"ratecontrol.mb_tree=True",
|
||||
"ratecontrol.lookahead=40")
|
||||
adm.clearVideoFilters()
|
||||
adm.addVideoFilter(
|
||||
"shaderLoader",
|
||||
"shaderFile=/opt/rk/avidemux/unfish_gopro_8:7.glsl")
|
||||
adm.addVideoFilter(
|
||||
"swscale",
|
||||
"width=824",
|
||||
"height=720",
|
||||
"algo=2",
|
||||
"sourceAR=0",
|
||||
"targetAR=0",
|
||||
"lockAR=False",
|
||||
"roundup=2")
|
||||
adm.setContainer(
|
||||
"MP4",
|
||||
"muxerType=0",
|
||||
"optimize=1",
|
||||
"forceAspectRatio=False",
|
||||
"aspectRatio=1",
|
||||
"displayWidth=1280",
|
||||
"rotation=0",
|
||||
"clockfreq=0")
|
@ -1,14 +1,33 @@
|
||||
// RozK
|
||||
#version 130
|
||||
|
||||
// Fisheye removal for GoPro 11+, 8:7 ratio, without hypersmooth
|
||||
// Adapted from https://github.com/duducosmos/defisheye
|
||||
// itself based on http://www.fmwconcepts.com/imagemagick/defisheye/index.php
|
||||
// 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/>.
|
||||
|
||||
#extension GL_ARB_texture_rectangle: enable
|
||||
|
||||
// TODO: investigate
|
||||
// precision highp float;
|
||||
#define color_conversion
|
||||
#define texture_filtering
|
||||
//#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;
|
||||
@ -16,50 +35,137 @@ uniform vec2 myResolution;
|
||||
uniform float pts;
|
||||
|
||||
// parameters
|
||||
const float input_fov = 156.0;
|
||||
const float output_fov = 124.45;
|
||||
const vec2 pixel_scale = vec2(0.652485, 1.0);
|
||||
const int subsampling = 4;
|
||||
|
||||
// subsampling constants
|
||||
const float substep = 1.0 / float(subsampling);
|
||||
const float substart = substep * 0.5 - 0.5;
|
||||
const float subscale = 1.0 / float(subsampling * subsampling);
|
||||
const vec2 sensor_size = vec2(5.949440, 5.205760);
|
||||
const float equidistant_focal_length = 2.920000;
|
||||
const float rectilinear_focal_length = 2.102263;
|
||||
|
||||
// variables
|
||||
vec2 center;
|
||||
float diameter;
|
||||
float input_len;
|
||||
float inv_output_len;
|
||||
// constants
|
||||
|
||||
vec4 unfish(const in vec2 coord) {
|
||||
float len = max(0.001, length(coord));
|
||||
vec2 y_coord = center + coord * ((input_len / len) * atan(len * inv_output_len));
|
||||
vec2 uv_coord = y_coord * 0.5;
|
||||
return vec4(
|
||||
texture2DRect(myTextureY, y_coord).r,
|
||||
texture2DRect(myTextureU, uv_coord).r,
|
||||
texture2DRect(myTextureV, uv_coord).r,
|
||||
1.0
|
||||
);
|
||||
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 float subsampling_scale = 1.0 / float(subsampling * subsampling);
|
||||
|
||||
// reprojection
|
||||
|
||||
vec2 texture_center;
|
||||
vec2 texture_to_sensor;
|
||||
vec2 sensor_to_texture;
|
||||
|
||||
void initialize() {
|
||||
texture_center = myResolution * 0.5;
|
||||
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);
|
||||
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));
|
||||
}
|
||||
|
||||
// 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);
|
||||
#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);
|
||||
}
|
||||
#endif
|
||||
return texture_filter(rectilinear);
|
||||
}
|
||||
|
||||
// main
|
||||
|
||||
void main() {
|
||||
center = myResolution * 0.5;
|
||||
diameter = length(myResolution);
|
||||
input_len = diameter / radians(input_fov);
|
||||
inv_output_len = (2.0 * tan(radians(output_fov * 0.5))) / diameter;
|
||||
|
||||
vec2 coord = gl_TexCoord[0].xy - center;
|
||||
vec4 pixel = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
float x, y = substart;
|
||||
for (int column = 0; column < subsampling; column++, y += substep) {
|
||||
x = substart;
|
||||
for (int row = 0; row < subsampling; row++, x += substep) {
|
||||
pixel += unfish((coord + vec2(x, y)) * pixel_scale);
|
||||
initialize();
|
||||
vec2 coord = gl_TexCoord[0].xy;
|
||||
vec3 color = vec3(0.0);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
gl_FragColor = pixel * subscale;
|
||||
gl_FragColor = vec4(encode_ycbcr(color * subsampling_scale), 1.0);
|
||||
}
|
||||
|
108
gopro_8:7/unfish_gopro_8:7.py
Normal file
108
gopro_8:7/unfish_gopro_8:7.py
Normal file
@ -0,0 +1,108 @@
|
||||
# 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/>.
|
||||
|
||||
import math
|
||||
|
||||
print("\n--- physical sensor ---\n")
|
||||
|
||||
# https://www.sony-semicon.com/files/62/pdf/p-13_IMX677-AAPH5-J_Flyer.pdf
|
||||
|
||||
sensor_pixel_size = 1.12 * 0.001 # mm
|
||||
|
||||
# https://community.gopro.com/s/article/HERO11-Black-Video-Settings-And-Resolutions
|
||||
|
||||
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)
|
||||
|
||||
print("gopro size : horizontal = %7.3f, vertical = %7.3f, diagonal = %7.3f (mm)" % (
|
||||
gopro_size_horizontal,
|
||||
gopro_size_vertical,
|
||||
gopro_size_diagonal))
|
||||
|
||||
# https://thinglabs.io/gopro-focal-length-guide
|
||||
|
||||
gopro_focal_length = 2.92
|
||||
|
||||
gopro_radius_horizontal = gopro_size_horizontal * 0.5
|
||||
gopro_radius_vertical = gopro_size_vertical * 0.5
|
||||
gopro_radius_diagonal = gopro_size_diagonal * 0.5
|
||||
|
||||
# https://en.wikipedia.org/wiki/Fisheye_lens
|
||||
|
||||
equidistant_angle = lambda radius: math.degrees(radius / gopro_focal_length)
|
||||
|
||||
gopro_fov_horizontal = 2.0 * equidistant_angle(gopro_radius_horizontal)
|
||||
gopro_fov_vertical = 2.0 * equidistant_angle(gopro_radius_vertical)
|
||||
gopro_fov_diagonal = 2.0 * equidistant_angle(gopro_radius_diagonal)
|
||||
|
||||
print("gopro fov : horizontal = %7.3f, vertical = %7.3f, diagonal = %7.3f (deg)" % (
|
||||
gopro_fov_horizontal,
|
||||
gopro_fov_vertical,
|
||||
gopro_fov_diagonal))
|
||||
|
||||
print("\n--- rectilinear re-projection ---\n")
|
||||
|
||||
rectilinear_focal_length = lambda radius: radius * math.tan(math.radians(90.0 - equidistant_angle(radius)))
|
||||
|
||||
rectilinear_focal_length_horizontal = rectilinear_focal_length(gopro_radius_horizontal)
|
||||
rectilinear_focal_length_vertical = rectilinear_focal_length(gopro_radius_vertical)
|
||||
rectilinear_focal_length_diagonal = rectilinear_focal_length(gopro_radius_diagonal)
|
||||
|
||||
print("linear focal: horizontal = %7.3f, vertical = %7.3f, diagonal = %7.3f (mm)" % (
|
||||
rectilinear_focal_length_horizontal,
|
||||
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_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)
|
||||
|
||||
print("linear fov : horizontal = %7.3f, vertical = %7.3f, diagonal = %7.3f (deg)" % (
|
||||
rectilinear_fov_horizontal,
|
||||
rectilinear_fov_vertical,
|
||||
rectilinear_fov_diagonal))
|
||||
|
||||
print("\n--- shader parameters ---\n")
|
||||
|
||||
print("""// parameters\n
|
||||
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,
|
||||
gopro_focal_length,
|
||||
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)
|
Reference in New Issue
Block a user