Kintrel desktop FFmpeg source, rebuild, and replacement guide
=============================================================

Scope
-----

Kintrel's Linux, macOS, and Windows video recorder and video transcoder use the
default, non-GPL `org.bytedeco:ffmpeg:8.0.1-1.5.13` runtime. Each desktop
package carries exactly one host-native classifier JAR:

  linux-x86_64
  linux-arm64
  macosx-x86_64
  macosx-arm64
  windows-x86_64

The classifier contains FFmpeg 8.0.1 shared libraries built by JavaCPP Presets
1.5.13. It is dynamically loaded and remains replaceable; it is not merged into
Kintrel's application executable.

The single source bundle published beside every coordinated desktop release
contains:

* the exact FFmpeg, JavaCPP, JavaCPP Presets, and JavaCV source revisions;
* every versioned native-library archive downloaded by the upstream FFmpeg
  recipe before it selects the Linux, macOS, or Windows build branch, including
  the recipe's build scripts and patches;
* the exact classifier-build source commit and composite-action files used by
  upstream run 22218401775, plus the later 1.5.13 release-source snapshot;
* exact source and packaging inputs for Ubuntu libdrm/libva, Raspberry Pi
  userland, Homebrew GCC/libatomic, and MinGW GCC/winpthreads runtime code;
* the small Kintrel patch that replaces the obsolete HTTP libxml2 archive with
  the equivalent official HTTPS release archive;
* `SOURCE-MANIFEST.sha256`, which is checked before the release bundle is made;
* `RUNTIME-LICENSE-MANIFEST.sha256`, `THIRD-PARTY-NOTICES.txt`, and the complete
  audited license/notice set under `Licenses/Runtime/`. Each native source
  archive also carries its original notices and applicable license text.

The permanent public bundle for Kintrel product version {version} is:

  https://kintrel.app/downloads/releases/{version}/desktop-source

Its checksum is:

  https://kintrel.app/downloads/releases/{version}/desktop-source/sha256

The moving `https://kintrel.app/downloads/latest/desktop-source` URL is only a
convenience for the newest release. It is not the permanent source location
for this bundle.

Prepare the source tree
-----------------------

Build on the operating system and CPU architecture of the classifier you want
to replace. Install the prerequisites named by JavaCPP Presets 1.5.13: a JDK,
Maven, Bash, Git, CMake, Meson, NASM, pkg-config, Autotools, and the native C/C++
toolchain. Linux uses GCC or Clang, macOS uses Xcode Command Line Tools, and
Windows uses a 64-bit MSYS2 MinGW environment. Work from a new directory:

1. Verify every file in `sources/` against `SOURCE-MANIFEST.sha256`. From the
   bundle root, run `sha256sum --check SOURCE-MANIFEST.sha256` on Linux or
   MSYS2, or `shasum -a 256 --check SOURCE-MANIFEST.sha256` on macOS.
2. Extract `sources/javacpp-1.5.13.tar.gz` and install JavaCPP 1.5.13 with
   Maven from its extracted root:

     mvn -DskipTests install

3. Extract `sources/javacpp-presets-ffmpeg-build-5f19192f.tar.gz`. This is the
   exact source commit used to produce the audited classifier JARs. Rename its
   extracted commit-named directory to `javacpp-presets-1.5.13`. The separate
   `javacpp-presets-1.5.13.tar.gz` is the final 1.5.13 release-source snapshot
   and is included for comparison and Maven-release provenance.
4. Copy the native source archives from `sources/` into
   `javacpp-presets-1.5.13/downloads/`, preserving their filenames.
5. In the presets root, apply `DesktopFfmpegLibxml2Https.patch` with:

     patch -p1 < ../DesktopFfmpegLibxml2Https.patch

Reproduce the platform runtime inputs
-------------------------------------

The files `sources/javacpp-build-{ubuntu,macosx,windows}.yml` are the exact
composite-action revision used by upstream. They are the authoritative package
installation scripts for the classifier build. The following pinned inputs
replace every mutable or externally packaged source relevant to code Kintrel
redistributes:

* `linux-x86_64` was built on Ubuntu 22.04. Its classifier copies libdrm
  2.4.113-2~ubuntu0.22.04.1 and libva 2.14.0-1. The `sources/libdrm-*` and
  `sources/libva-*` original source, Debian patch tarballs, and `.dsc` files
  reconstruct those exact Ubuntu packages. Install those package versions in
  the build root before running `cppbuild.sh`.
* `linux-arm64` builds ALSA 1.2.14 from the ordinary recipe input. Extract
  `raspberrypi-userland-a54a0dbb.tar.gz`, run `bash buildme --aarch64`, and
  export `USERLAND_PATH` as the extracted directory's absolute path before
  running `cppbuild.sh`. This replaces the upstream action's mutable
  `userland/archive/master.tar.gz` download with the commit actually available
  at classifier-build time.
* Both macOS classifiers were produced on the upstream Intel macOS 15 runner.
  Homebrew installed GCC 13.4.0 and the classifier copied its
  `libatomic.1.dylib`. Rebuild that runtime from `gcc-13.4.0.tar.xz`,
  `homebrew-gcc-13-formula.rb`, and `homebrew-gcc-13.4.0.diff`; make its library
  directory available exactly as shown in `javacpp-build-macosx.yml`.
* Windows used MSYS2's GCC 14.1.0-3 and MinGW-w64 runtime revision
  dc42231f0392f75de72e87ba0170ec60fcc6c10b. `gcc-14.1.0.tar.xz`, the
  `mingw-packages-3127522154.tar.gz` recipe/patch snapshot, and
  `mingw-w64-dc42231f0.tar.gz` contain the complete source and scripts for the
  statically linked GCC, libstdc++, CRT, and winpthreads runtime portions.

The exact upstream JAR digests and platform file inventory are recorded in
`THIRD-PARTY-NOTICES.txt`. A locally rebuilt classifier need not be byte-for-byte
identical—tool timestamps, signatures, and archive metadata vary—but it must
retain the same non-GPL configuration and JavaCPP ABI/package layout.

Build one desktop classifier
----------------------------

Set `PLATFORM` to the classifier for the machine doing the build. Supported
Kintrel desktop values are `linux-x86_64`, `linux-arm64`, `macosx-x86_64`,
`macosx-arm64`, and `windows-x86_64`. Then, from the presets root, build the
default non-GPL runtime. Do not pass an `-extension=-gpl` argument:

     PLATFORM=linux-x86_64
     bash cppbuild.sh -platform "$PLATFORM" install ffmpeg
     mvn install --projects .,ffmpeg -Djavacpp.platform="$PLATFORM" \
       -Djavacpp.cppbuild.skip -DskipTests

On Windows, run the same commands from the MSYS2 MinGW64 shell. For example:

     bash cppbuild.sh -platform windows-x86_64 install ffmpeg
     mvn install --projects .,ffmpeg -Djavacpp.platform=windows-x86_64 \
       -Djavacpp.cppbuild.skip -DskipTests

The upstream recipe may compile x264 and x265 as intermediate projects, but the
non-GPL configuration does not pass `--enable-gpl`, `--enable-libx264`, or
`--enable-libx265` to FFmpeg and therefore does not link those libraries into
the resulting runtime. They remain in the source bundle so the tagged upstream
recipe can be run without fetching an unverified input.

The rebuilt classifier is written below the local Maven repository as
`org/bytedeco/ffmpeg/8.0.1-1.5.13/ffmpeg-8.0.1-1.5.13-<platform>.jar`. Verify
that the JAR contains `org/bytedeco/ffmpeg/<platform>/` and the expected FFmpeg
shared libraries before installing it into Kintrel.

Replace the runtime in Kintrel
------------------------------

1. Quit Kintrel.
2. Find the installed classifier JAR. Compose packaging adds a content hash to
   its filename, so match
   `ffmpeg-8.0.1-1.5.13-<platform>-*.jar` rather than assuming an exact name:

   * Linux application directory or extracted tarball: `lib/app/`
   * Linux AppImage after `--appimage-extract`: locate the JAR beneath
     `squashfs-root/` with:

       find squashfs-root -type f \
         -name 'ffmpeg-8.0.1-1.5.13-linux-*-*.jar'

   * macOS: `Kintrel.app/Contents/app/`
   * Windows: the `app` directory adjacent to `Kintrel.exe`

3. Back up the installed JAR. Copy the rebuilt classifier JAR over it while
   retaining the installed, hash-bearing filename. The replacement must keep
   the JavaCPP package layout and FFmpeg ABI expected by the platform-neutral
   `ffmpeg-8.0.1-1.5.13-*.jar` bindings.
4. On Linux, an AppImage is read-only while mounted. Run the vendor AppImage
   with `--appimage-extract`, make the replacement in the extracted tree, and
   launch `squashfs-root/AppRun`; alternatively use Kintrel's tarball. Repacking
   the tree with `appimagetool` is optional.
5. On macOS, code-sign every rebuilt Mach-O file inside the classifier before
   recreating the JAR, then replace the JAR and ad-hoc sign the locally modified
   application so the operating system accepts its changed bundle seal. This
   loop signs both executables and shared libraries in an extracted classifier:

     find org/bytedeco/ffmpeg/macosx-arm64 -type f -print0 | \
       while IFS= read -r -d '' file; do
         file "$file" | grep -q 'Mach-O' && codesign --force --sign - "$file"
       done
     /usr/bin/ditto -c -k --sequesterRsrc . \
       ../ffmpeg-8.0.1-1.5.13-macosx-arm64.jar
     codesign --force --deep --sign - /Applications/Kintrel.app

   Substitute `macosx-x86_64` and the actual application path when applicable.
   Ad-hoc signing is for the local modified copy and does not recreate CTI's
   Developer ID signature or notarization ticket.
6. Start Kintrel. JavaCPP extracts and loads the shared libraries from the
   replacement classifier JAR.

Kintrel does not perform a post-install classifier checksum check and does not
prevent the user from replacing this LGPL component. Reinstalling or upgrading
Kintrel restores the vendor-supplied classifier, so keep the rebuilt JAR if you
want to apply it again.

No warranty
-----------

The corresponding source and replacement mechanism are provided to preserve
the rights granted by the applicable licenses. They do not add a warranty or
support commitment beyond those license terms.
