From bfca7ee8ad73c237a16433091b44580107e9bba3 Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Wed, 17 Dec 2025 22:59:25 -0600 Subject: [PATCH 1/3] =?UTF-8?q?Adding=20Qt6=20detection=20and=20compatibil?= =?UTF-8?q?ity,=20without=20breaking=20Qt5.=20`-DUSE=5FQT6=3DAUTO|ON|OFF`?= =?UTF-8?q?=20(default:=20`AUTO`;=20prefers=20Qt6=20when=20available=20and?= =?UTF-8?q?=20CMake=20=E2=89=A53.16,=20`ON`=20forces=20Qt6,=20`OFF`=20forc?= =?UTF-8?q?es=20Qt5).=20Also,=20a=20few=20version=20specific=20changes=20f?= =?UTF-8?q?or=20API=20changes=20on=20Qt6,=20but=20it=20appears=20to=20work?= =?UTF-8?q?=20well.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- INSTALL.md | 3 ++- doc/INSTALL-LINUX.md | 10 +++++++- doc/INSTALL-MAC.md | 3 ++- doc/INSTALL-WINDOWS.md | 3 ++- examples/CMakeLists.txt | 43 +++++++++++++++++++++++++++++--- src/CMakeLists.txt | 52 ++++++++++++++++++++++++++++++++++++--- src/Qt/PlayerDemo.cpp | 2 +- src/effects/LensFlare.cpp | 13 +++++++--- tests/Caption.cpp | 4 ++- 9 files changed, 116 insertions(+), 17 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 561a011a9..d99f59c09 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -50,7 +50,7 @@ Libraries and executables have been labeled in the list below to help distinguis #### Qt 5 (libqt5) * **(Library)** -* Qt5 is used to display video, store image data, composite images, +* Qt5/Qt6 is used to display video, store image data, composite images, apply image effects, and many other utility functions, such as file system manipulation, high resolution timers, etc. @@ -201,6 +201,7 @@ Following are some of the flags you might need to set when generating your build * `-DCMAKE_PREFIX_PATH=/extra/path/to/search/for/libraries/` * `-DUSE_SYSTEM_JSONCPP=0` (default: auto if discovered) * `-DENABLE_MAGICK=0` (default: auto if discovered) +* `-DUSE_QT6=AUTO|ON|OFF` (default: `AUTO`; prefers Qt6 when available and CMake ≥3.16, `ON` forces Qt6, `OFF` forces Qt5) #### Options to compile bindings for a specific Python installation * `-DPYTHON_INCLUDE_DIR=/location/of/python/includes/` diff --git a/doc/INSTALL-LINUX.md b/doc/INSTALL-LINUX.md index fcc0a21a3..c1d987eaf 100644 --- a/doc/INSTALL-LINUX.md +++ b/doc/INSTALL-LINUX.md @@ -44,7 +44,8 @@ list below to help distinguish between them. ### Qt 5 (libqt5) * http://www.qt.io/qt5/ `(Library)` - * Qt5 is used to display video, store image data, composite images, apply image effects, and many other utility functions, such as file system manipulation, high resolution timers, etc... + * Qt5/Qt6 is used to display video, store image data, composite images, apply image effects, and many other utility functions, such as file system manipulation, high resolution timers, etc... + * Use the CMake option `-DUSE_QT6=ON|OFF|AUTO` (default AUTO) to pick a Qt major version; Qt6 builds require CMake 3.16+. ### CMake (cmake) * http://www.cmake.org/ `(Executable)` @@ -166,6 +167,13 @@ software packages available to download and install. swig ``` +If you want to build against Qt6 on Ubuntu 24.04 or newer, install the Qt6 dev stack instead and configure with the default `USE_QT6=AUTO` (prefers Qt6 when available) or `-DUSE_QT6=ON` to force it: + +``` +sudo apt install qt6-base-dev qt6-base-dev-tools qt6-tools-dev qt6-svg-dev +``` + + ## Linux Build Instructions (libopenshot-audio) To compile libopenshot-audio, we need to go through a few additional steps to manually build and install it. Launch a terminal and enter: diff --git a/doc/INSTALL-MAC.md b/doc/INSTALL-MAC.md index 7e5665287..183603207 100644 --- a/doc/INSTALL-MAC.md +++ b/doc/INSTALL-MAC.md @@ -44,7 +44,8 @@ list below to help distinguish between them. ### Qt 5 (libqt5) * http://www.qt.io/qt5/ `(Library)` - * Qt5 is used to display video, store image data, composite images, apply image effects, and many other utility functions, such as file system manipulation, high resolution timers, etc... + * Qt5/Qt6 is used to display video, store image data, composite images, apply image effects, and many other utility functions, such as file system manipulation, high resolution timers, etc... + * Use the CMake option `-DUSE_QT6=ON|OFF|AUTO` (default AUTO) to pick a Qt major version; Qt6 builds require CMake 3.16+. ### CMake (cmake) * http://www.cmake.org/ `(Executable)` diff --git a/doc/INSTALL-WINDOWS.md b/doc/INSTALL-WINDOWS.md index 4f04cb62c..2fe1e464a 100644 --- a/doc/INSTALL-WINDOWS.md +++ b/doc/INSTALL-WINDOWS.md @@ -46,7 +46,8 @@ have been labeled in the list below to help distinguish between them. ### Qt 5 (libqt5) * http://www.qt.io/qt5/ `(Library)` - * Qt5 is used to display video, store image data, composite images, apply image effects, and many other utility functions, such as file system manipulation, high resolution timers, etc... + * Qt5/Qt6 is used to display video, store image data, composite images, apply image effects, and many other utility functions, such as file system manipulation, high resolution timers, etc... + * Use the CMake option `-DUSE_QT6=ON|OFF|AUTO` (default AUTO) to pick a Qt major version; Qt6 builds require CMake 3.16+. ### CMake (cmake) * http://www.cmake.org/ `(Executable)` diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 12b5447e8..f36ea6fe9 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -11,8 +11,45 @@ include(GNUInstallDirs) -# Dependencies -find_package(Qt5 COMPONENTS Gui REQUIRED) +# Qt selection matches the main library (USE_QT6 option, CMake 3.16+ needed for Qt6) +set(_qt6_allowed TRUE) +if(CMAKE_VERSION VERSION_LESS "3.16") + set(_qt6_allowed FALSE) + if(USE_QT6 STREQUAL "ON") + message(FATAL_ERROR "USE_QT6=ON requires CMake 3.16 or newer") + endif() +endif() +if(USE_QT6 STREQUAL "OFF") + set(_qt6_allowed FALSE) +endif() + +set(_qt_selection "") +if(USE_QT6 STREQUAL "ON") + if(NOT _qt6_allowed) + message(FATAL_ERROR "Qt6 support disabled by CMake version; set USE_QT6=OFF or upgrade CMake") + endif() + set(_qt_selection "Qt6") +elseif(USE_QT6 STREQUAL "OFF") + set(_qt_selection "Qt5") +else() + if(_qt6_allowed) + find_package(Qt6 COMPONENTS Core QUIET) + if(Qt6_FOUND) + set(_qt_selection "Qt6") + endif() + endif() + if(NOT _qt_selection) + set(_qt_selection "Qt5") + endif() +endif() + +if(_qt_selection STREQUAL "Qt6") + set(QT_VERSION_MAJOR 6) +else() + set(QT_VERSION_MAJOR 5) +endif() + +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Gui REQUIRED) ############### CLI EXECUTABLES ################ # Create test executable @@ -27,7 +64,7 @@ target_compile_definitions(openshot-example PRIVATE target_link_libraries(openshot-example openshot) add_executable(openshot-html-example ExampleHtml.cpp) -target_link_libraries(openshot-html-example openshot Qt5::Gui) +target_link_libraries(openshot-html-example openshot Qt${QT_VERSION_MAJOR}::Gui) ############### PLAYER EXECUTABLE ################ # Create test executable diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6e22574c5..7c249bf69 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -314,6 +314,9 @@ endif() ### Qt Toolkit ### +set(USE_QT6 "AUTO" CACHE STRING "Select Qt major version (AUTO, ON=Qt6, OFF=Qt5)") +set_property(CACHE USE_QT6 PROPERTY STRINGS AUTO ON OFF) + set(_qt_components Core Gui Widgets) # We also need QtSvg unless we have Resvg insetead. @@ -321,16 +324,57 @@ if(NOT HAVE_RESVG) list(APPEND _qt_components Svg) endif() -find_package(Qt5 COMPONENTS ${_qt_components} REQUIRED) +# Qt6 packages require newer CMake; gate support so older systems still build Qt5. +set(_qt6_allowed TRUE) +if(CMAKE_VERSION VERSION_LESS "3.16") + set(_qt6_allowed FALSE) + if(USE_QT6 STREQUAL "ON") + message(FATAL_ERROR "USE_QT6=ON requires CMake 3.16 or newer") + endif() +endif() +if(USE_QT6 STREQUAL "OFF") + set(_qt6_allowed FALSE) +endif() + +set(_qt_selection "") +if(USE_QT6 STREQUAL "ON") + if(NOT _qt6_allowed) + message(FATAL_ERROR "Qt6 support disabled by CMake version; set USE_QT6=OFF or upgrade CMake") + endif() + set(_qt_selection "Qt6") +elseif(USE_QT6 STREQUAL "OFF") + set(_qt_selection "Qt5") +else() + if(_qt6_allowed) + find_package(Qt6 COMPONENTS Core QUIET) + if(Qt6_FOUND) + set(_qt_selection "Qt6") + endif() + endif() + if(NOT _qt_selection) + set(_qt_selection "Qt5") + endif() +endif() + +if(_qt_selection STREQUAL "Qt6") + set(QT_VERSION_MAJOR 6) +else() + set(QT_VERSION_MAJOR 5) +endif() + +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS ${_qt_components} REQUIRED) foreach(_qt_comp IN LISTS _qt_components) - if(TARGET Qt5::${_qt_comp}) - target_link_libraries(openshot PUBLIC Qt5::${_qt_comp}) + if(TARGET Qt${QT_VERSION_MAJOR}::${_qt_comp}) + target_link_libraries(openshot PUBLIC Qt${QT_VERSION_MAJOR}::${_qt_comp}) endif() endforeach() +string(REPLACE ";" ", " _qt_comp_list "${_qt_components}") +message(STATUS "Found Qt${QT_VERSION_MAJOR} ${Qt${QT_VERSION_MAJOR}Core_VERSION_STRING} (components: ${_qt_comp_list})") + # Keep track of Qt version, to embed in our version header -set(QT_VERSION_STR ${Qt5Core_VERSION_STRING} CACHE STRING "Qt version linked with" FORCE) +set(QT_VERSION_STR ${Qt${QT_VERSION_MAJOR}Core_VERSION_STRING} CACHE STRING "Qt version linked with" FORCE) mark_as_advanced(QT_VERSION_STR) ################### FFMPEG ##################### diff --git a/src/Qt/PlayerDemo.cpp b/src/Qt/PlayerDemo.cpp index f0514e766..5e2095944 100644 --- a/src/Qt/PlayerDemo.cpp +++ b/src/Qt/PlayerDemo.cpp @@ -43,7 +43,7 @@ PlayerDemo::PlayerDemo(QWidget *parent) vbox->addWidget(menu, 0); vbox->addWidget(video, 1); - vbox->setMargin(0); + vbox->setContentsMargins(0, 0, 0, 0); vbox->setSpacing(0); resize(600, 480); diff --git a/src/effects/LensFlare.cpp b/src/effects/LensFlare.cpp index e59b35cde..a8286b317 100644 --- a/src/effects/LensFlare.cpp +++ b/src/effects/LensFlare.cpp @@ -107,14 +107,19 @@ static QColor shifted_hsv(const QColor &base, float h_shift, float s_scale, float v_scale, float a_scale = 1.0f) { + // Qt6 switched getHsvF/setHsvF to float; keep compatibility with Qt5 (qreal) +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + float h, s, v, a; +#else qreal h, s, v, a; +#endif base.getHsvF(&h, &s, &v, &a); if (s == 0.0) h = 0.0; - h = std::fmod(h + h_shift + 1.0, 1.0); - s = std::clamp(s * s_scale, 0.0, 1.0); - v = std::clamp(v * v_scale, 0.0, 1.0); - a = std::clamp(a * a_scale, 0.0, 1.0); + h = static_cast(std::fmod(static_cast(h + h_shift + 1.0), 1.0)); + s = std::clamp(s * s_scale, static_cast(0.0), static_cast(1.0)); + v = std::clamp(v * v_scale, static_cast(0.0), static_cast(1.0)); + a = std::clamp(a * a_scale, static_cast(0.0), static_cast(1.0)); QColor out; out.setHsvF(h, s, v, a); diff --git a/tests/Caption.cpp b/tests/Caption.cpp index bc5768f0c..96d49a445 100644 --- a/tests/Caption.cpp +++ b/tests/Caption.cpp @@ -63,7 +63,9 @@ TEST_CASE("caption effect", "[libopenshot][caption]") { int argc = 1; char* argv[1] = {(char*)""}; +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); +#endif QApplication app(argc, argv); QApplication::processEvents(); @@ -202,4 +204,4 @@ TEST_CASE("caption effect", "[libopenshot][caption]") { // Close QApplication app.quit(); -} \ No newline at end of file +} From a26ed32424cd57ef7e285ebe8584f27b4ff3ce35 Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Mon, 22 Dec 2025 13:44:54 -0600 Subject: [PATCH 2/3] Adding missing packages to our linux install instructions doc: python3-zmq python3-pyqt5.qtwebengine --- doc/INSTALL-LINUX.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/INSTALL-LINUX.md b/doc/INSTALL-LINUX.md index c1d987eaf..d297f038c 100644 --- a/doc/INSTALL-LINUX.md +++ b/doc/INSTALL-LINUX.md @@ -164,7 +164,10 @@ software packages available to download and install. python3-dev \ qtbase5-dev \ qtmultimedia5-dev \ - swig + swig \ + python3-zmq \ + python3-pyqt5.qtwebengine + ``` If you want to build against Qt6 on Ubuntu 24.04 or newer, install the Qt6 dev stack instead and configure with the default `USE_QT6=AUTO` (prefers Qt6 when available) or `-DUSE_QT6=ON` to force it: From 23b4e748ea3b567c12a877692c929d5b77e3cb9b Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Mon, 22 Dec 2025 13:46:41 -0600 Subject: [PATCH 3/3] Improving swig bindings for Python, Java, and Ruby for access direct pixel byte array: Example Code Snippets: Python: import openshot r = openshot.FFmpegReader("/home/jonathan/Pictures/ChatGPT Image Mar 27, 2025, 09_50_56 AM.png") r.Open() f = r.GetFrame(1) buf = f.GetPixelsBytes() w, h = f.GetWidth(), f.GetHeight() stride = f.GetBytesPerLine() Ruby: require "openshot" r = Openshot::FFmpegReader.new("/home/jonathan/Pictures/ChatGPT Image Mar 27, 2025, 09_50_56 AM.png") r.Open() f = r.GetFrame(1) buf = f.GetPixelsBytes w = f.GetWidth h = f.GetHeight stride = f.GetBytesPerLine --- bindings/java/openshot.i | 67 +++++++++++++++++++++++++++++++++++++ bindings/python/openshot.i | 68 ++++++++++++++++++++++++++++++++++++++ bindings/ruby/openshot.i | 54 ++++++++++++++++++++++++++++++ 3 files changed, 189 insertions(+) diff --git a/bindings/java/openshot.i b/bindings/java/openshot.i index 7aaf7d1e2..ff794ede2 100644 --- a/bindings/java/openshot.i +++ b/bindings/java/openshot.i @@ -52,6 +52,34 @@ #%template() std::vector>; %template() std::vector>; +%inline %{ +typedef struct OpenShotByteBuffer { + const unsigned char* data; + int size; +} OpenShotByteBuffer; +%} + +%typemap(jni) OpenShotByteBuffer "jbyteArray" +%typemap(jstype) OpenShotByteBuffer "byte[]" +%typemap(jtype) OpenShotByteBuffer "byte[]" +%typemap(javaout) OpenShotByteBuffer { + return $jnicall; +} +%typemap(out) OpenShotByteBuffer { + if ($1.data && $1.size > 0) { + jbyteArray jarr = jenv->NewByteArray($1.size); + if (jarr == NULL) { + SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "Unable to allocate byte array"); + return NULL; + } + jenv->SetByteArrayRegion(jarr, 0, $1.size, + reinterpret_cast($1.data)); + $result = jarr; + } else { + $result = NULL; + } +} + %{ #include "OpenShotVersion.h" #include "ReaderBase.h" @@ -118,6 +146,45 @@ /* Deprecated */ %template(AudioDeviceInfoVector) std::vector; +%extend openshot::Frame { + OpenShotByteBuffer GetPixelsBytes() { + OpenShotByteBuffer out = {NULL, 0}; + std::shared_ptr img = $self->GetImage(); + if (!img) return out; + + const int size = img->bytesPerLine() * img->height(); + + const unsigned char* p = $self->GetPixels(); + if (!p || size <= 0) return out; + + out.data = p; + out.size = size; + return out; + } + + OpenShotByteBuffer GetPixelsRowBytes(int row) { + OpenShotByteBuffer out = {NULL, 0}; + std::shared_ptr img = $self->GetImage(); + if (!img) return out; + + if (row < 0 || row >= img->height()) { + return out; + } + + const unsigned char* p = $self->GetPixels(row); + if (!p) return out; + + out.data = p; + out.size = img->bytesPerLine(); + return out; + } + + int GetBytesPerLine() { + std::shared_ptr img = $self->GetImage(); + return img ? img->bytesPerLine() : 0; + } +} + %include "OpenShotVersion.h" %include "ReaderBase.h" %include "WriterBase.h" diff --git a/bindings/python/openshot.i b/bindings/python/openshot.i index 612bfb11d..0fa1d7880 100644 --- a/bindings/python/openshot.i +++ b/bindings/python/openshot.i @@ -284,6 +284,74 @@ } } +%extend openshot::Frame { + PyObject* GetPixelsBytes() { + PyGILState_STATE gstate = PyGILState_Ensure(); + PyObject* result = NULL; + + std::shared_ptr img = $self->GetImage(); + if (!img) { + Py_INCREF(Py_None); + result = Py_None; + PyGILState_Release(gstate); + return result; + } + + const Py_ssize_t size = + static_cast(img->bytesPerLine()) * + static_cast(img->height()); + + const unsigned char* p = img->constBits(); + if (!p || size <= 0) { + Py_INCREF(Py_None); + result = Py_None; + PyGILState_Release(gstate); + return result; + } + + result = PyBytes_FromStringAndSize(reinterpret_cast(p), size); + PyGILState_Release(gstate); + return result; + } + + PyObject* GetPixelsRowBytes(int row) { + PyGILState_STATE gstate = PyGILState_Ensure(); + PyObject* result = NULL; + + std::shared_ptr img = $self->GetImage(); + if (!img) { + Py_INCREF(Py_None); + result = Py_None; + PyGILState_Release(gstate); + return result; + } + + if (row < 0 || row >= img->height()) { + PyErr_SetString(PyExc_IndexError, "row out of range"); + PyGILState_Release(gstate); + return NULL; + } + + const unsigned char* p = img->constScanLine(row); + if (!p) { + Py_INCREF(Py_None); + result = Py_None; + PyGILState_Release(gstate); + return result; + } + + const Py_ssize_t row_bytes = static_cast(img->bytesPerLine()); + result = PyBytes_FromStringAndSize(reinterpret_cast(p), row_bytes); + PyGILState_Release(gstate); + return result; + } + + int GetBytesPerLine() { + std::shared_ptr img = $self->GetImage(); + return img ? img->bytesPerLine() : 0; + } +} + %include "OpenShotVersion.h" %include "ReaderBase.h" %include "WriterBase.h" diff --git a/bindings/ruby/openshot.i b/bindings/ruby/openshot.i index 655241be6..d7f85e117 100644 --- a/bindings/ruby/openshot.i +++ b/bindings/ruby/openshot.i @@ -52,6 +52,21 @@ %template() std::vector>; %template() std::vector>; +%inline %{ +typedef struct OpenShotByteBuffer { + const unsigned char* data; + int size; +} OpenShotByteBuffer; +%} + +%typemap(out) OpenShotByteBuffer { + if ($1.data && $1.size > 0) { + $result = rb_str_new(reinterpret_cast($1.data), $1.size); + } else { + $result = Qnil; + } +} + %{ /* Ruby and FFmpeg define competing RSHIFT macros, * so we move Ruby's out of the way for now. We'll @@ -136,6 +151,45 @@ /* Deprecated */ %template(AudioDeviceInfoVector) std::vector; +%extend openshot::Frame { + OpenShotByteBuffer GetPixelsBytes() { + OpenShotByteBuffer out = {NULL, 0}; + std::shared_ptr img = $self->GetImage(); + if (!img) return out; + + const int size = img->bytesPerLine() * img->height(); + + const unsigned char* p = $self->GetPixels(); + if (!p || size <= 0) return out; + + out.data = p; + out.size = size; + return out; + } + + OpenShotByteBuffer GetPixelsRowBytes(int row) { + OpenShotByteBuffer out = {NULL, 0}; + std::shared_ptr img = $self->GetImage(); + if (!img) return out; + + if (row < 0 || row >= img->height()) { + rb_raise(rb_eIndexError, "row out of range"); + } + + const unsigned char* p = $self->GetPixels(row); + if (!p) return out; + + out.data = p; + out.size = img->bytesPerLine(); + return out; + } + + int GetBytesPerLine() { + std::shared_ptr img = $self->GetImage(); + return img ? img->bytesPerLine() : 0; + } +} + %include "OpenShotVersion.h" %include "ReaderBase.h" %include "WriterBase.h"