The swiss army knife of lossless video/audio editing
Check that bundled ffmpeg runs, compare release asset sizes, bundle ffmpeg for Linux arm64
Claude8c1d95cde0e4
diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex 7287f052..565a3b20 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -94,7 +94,9 @@ jobs:- name: (Linux) Download ffmpegif: runner.os == 'Linux'- run: yarn download-ffmpeg-linux-x64+ run: |+ yarn download-ffmpeg-linux-x64+ yarn download-ffmpeg-linux-arm64- run: ls -R ffmpeg@@ -195,3 +197,17 @@ jobs:yarn upload-artifacts dist/LosslessCut-linux-x86_64.AppImageyarn upload-artifacts --name screenshot-linux.jpeg screenshot.jpeg++ # Catches e.g. an asset that was built without ffmpeg (#3147)+ check-release-assets:+ needs: release+ if: startsWith(github.ref, 'refs/tags/v')+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@v6+ - uses: actions/setup-node@v6+ with:+ node-version: 22+ - run: node script/checkReleaseAssets.ts "$GITHUB_REF_NAME"+ env:+ GH_TOKEN: ${{ secrets.github_token }}diff --git a/README.md b/README.mdindex 81a91ad1..ec92436e 100644--- a/README.md+++ b/README.md@@ -118,7 +118,7 @@ If you prefer to download the executables manually, this will of course always b- macOS: [Intel](https://github.com/mifi/lossless-cut/releases/latest/download/LosslessCut-mac-x64.dmg) / [Apple Silicon](https://github.com/mifi/lossless-cut/releases/latest/download/LosslessCut-mac-arm64.dmg) DMG (note that PKG does **not** work)- Windows: [7zip](https://github.com/mifi/lossless-cut/releases/latest/download/LosslessCut-win-x64.7z) (Windows 7, 8 and 8.1 is [no longer supported after v3.50.0](docs/requirements.md))-- Linux: [x64 tar.bz2](https://github.com/mifi/lossless-cut/releases/latest/download/LosslessCut-linux-x64.tar.bz2) / [x64 AppImage](https://github.com/mifi/lossless-cut/releases/latest/download/LosslessCut-linux-x86_64.AppImage) / [arm64 tar.bz2](https://github.com/mifi/lossless-cut/releases/latest/download/LosslessCut-linux-arm64.tar.bz2) / [Raspberry Pi armv7l](https://github.com/mifi/lossless-cut/releases/latest/download/LosslessCut-linux-armv7l.tar.bz2) (arm64 and armv7l builds don't include FFmpeg)+- Linux: [x64 tar.bz2](https://github.com/mifi/lossless-cut/releases/latest/download/LosslessCut-linux-x64.tar.bz2) / [x64 AppImage](https://github.com/mifi/lossless-cut/releases/latest/download/LosslessCut-linux-x86_64.AppImage) / [arm64 tar.bz2](https://github.com/mifi/lossless-cut/releases/latest/download/LosslessCut-linux-arm64.tar.bz2) / [Raspberry Pi armv7l](https://github.com/mifi/lossless-cut/releases/latest/download/LosslessCut-linux-armv7l.tar.bz2) (armv7l doesn't include FFmpeg)- [More releases](https://github.com/mifi/lossless-cut/releases) - Note that APPX (Windows) and PKG (macOS) do **not** work- [Latest nightly builds 🧪](https://mifi.no/llc/nightly/)diff --git a/package.json b/package.jsonindex 5fda9ee4..00b559d1 100644--- a/package.json+++ b/package.json@@ -14,6 +14,7 @@"download-ffmpeg-darwin-x64": "node script/downloadFfmpeg.ts darwin-x64","download-ffmpeg-darwin-arm64": "node script/downloadFfmpeg.ts darwin-arm64","download-ffmpeg-linux-x64": "node script/downloadFfmpeg.ts linux-x64",+ "download-ffmpeg-linux-arm64": "node script/downloadFfmpeg.ts linux-arm64","download-ffmpeg-win32-x64": "node script/downloadFfmpeg.ts win32-x64","download-ffmpeg-win32-arm64": "node script/downloadFfmpeg.ts win32-arm64","build": "yarn generate-icon && electron-vite build",diff --git a/script/afterPack.ts b/script/afterPack.tsindex 07a2bce9..74c450c7 100644--- a/script/afterPack.ts+++ b/script/afterPack.ts@@ -1,17 +1,25 @@-// electron-builder afterPack hook: fail the build if the bundled ffmpeg/ffprobe are missing.+// electron-builder afterPack hook: fail the build if the bundled ffmpeg/ffprobe are missing or don't run.// electron-builder only warns when an `extraResources` source doesn't exist, so a missing ffmpeg would otherwise ship silently.import assert from 'node:assert';import { existsSync } from 'node:fs';import { join } from 'node:path';import { Arch, type AfterPackContext } from 'electron-builder';+import { execa } from 'execa';export default async function afterPack({ appOutDir, arch, electronPlatformName, packager }: AfterPackContext) {- // We have no ffmpeg builds for Linux ARM (see script/downloadFfmpeg.ts)- if (electronPlatformName === 'linux' && arch !== Arch.x64) return;+ // We have no ffmpeg builds for Linux armv7l (see script/downloadFfmpeg.ts)+ if (electronPlatformName === 'linux' && arch === Arch.armv7l) return;const resourcesDir = packager.getResourcesDir(appOutDir);for (const name of ['ffmpeg', 'ffprobe']) {const path = join(resourcesDir, electronPlatformName === 'win32' ? `${name}.exe` : name);assert(existsSync(path), `${path} is missing. Did you run download-ffmpeg for ${electronPlatformName}-${Arch[arch]}?`);++ // If the binary can run on this machine, check that it does (e.g. not a broken download or missing libraries)+ if (electronPlatformName === process.platform && Arch[arch] === process.arch) {+ // Like the app does on Linux (see src/main/ffmpeg.ts)+ const { stdout } = await execa(path, ['-hide_banner', '-version'], { env: { LD_LIBRARY_PATH: resourcesDir } });+ console.log(stdout.split('\n')[0]);+ }}}diff --git a/script/checkReleaseAssets.ts b/script/checkReleaseAssets.tsnew file mode 100644index 00000000..c027e894--- /dev/null+++ b/script/checkReleaseAssets.ts@@ -0,0 +1,38 @@+// Compares the assets of a (draft) release with the latest published release, and fails if any is missing or much smaller.+// This catches e.g. a build that was packaged without ffmpeg. Run by the build workflow after a tag build.+// Usage: node script/checkReleaseAssets.ts v1.2.3 (GH_TOKEN is needed to see draft releases)+import assert from 'node:assert';++const tag = process.argv[2];+const token = process.env['GH_TOKEN'];+assert(tag != null, 'Usage: node script/checkReleaseAssets.ts <tag>');++const repo = process.env['GITHUB_REPOSITORY'] ?? 'mifi/lossless-cut';+// Sizes usually change by a few percent between releases. A failure on a draft can be checked and ignored if the size change is expected+const minRatio = 0.9;++interface Release { tag_name: string, assets: { name: string, size: number }[] }++async function get<T>(path: string) {+ const response = await fetch(`https://api.github.com/repos/${repo}/${path}`, { headers: { accept: 'application/vnd.github+json', ...(token != null && { authorization: `Bearer ${token}` }) } });+ assert(response.ok, `GET ${path} failed: ${response.status}`);+ return await response.json() as T;+}++// Drafts don't have a tag yet as far as the "release by tag" endpoint is concerned, so look in the list+const release = (await get<Release[]>('releases?per_page=20')).find((r) => r.tag_name === tag);+assert(release != null, `No release found for ${tag}`);+const previous = await get<Release>('releases/latest');+assert(previous.tag_name !== tag, `${tag} is already the latest published release, nothing to compare with`);++const formatMb = (bytes: number) => `${(bytes / 1e6).toFixed(0)} MB`;+const problems = previous.assets.flatMap(({ name, size }) => {+ const asset = release.assets.find((a) => a.name === name);+ if (asset == null) return [`${name} is missing (${formatMb(size)} in ${previous.tag_name})`];+ if (asset.size < size * minRatio) return [`${name} is ${formatMb(asset.size)}, was ${formatMb(size)} in ${previous.tag_name}`];+ return [];+});++console.log(`Compared ${release.assets.length} assets of ${tag} with ${previous.tag_name}`);+for (const problem of problems) console.log(`::error::${problem}`);+process.exitCode = problems.length > 0 ? 1 : 0;diff --git a/script/downloadFfmpeg.ts b/script/downloadFfmpeg.tsindex ca79a000..af7de005 100644--- a/script/downloadFfmpeg.ts+++ b/script/downloadFfmpeg.ts@@ -1,5 +1,5 @@// Downloads the bundled ffmpeg/ffprobe for a platform into ffmpeg/<platform>-<arch>, see CONTRIBUTING.md-// Usage: node script/downloadFfmpeg.ts darwin-x64|darwin-arm64|linux-x64|win32-x64|win32-arm64+// Usage: node script/downloadFfmpeg.ts darwin-x64|darwin-arm64|linux-x64|linux-arm64|win32-x64|win32-arm64import assert from 'node:assert';import { createWriteStream } from 'node:fs';import { chmod, mkdir, readdir, rename, rm } from 'node:fs/promises';@@ -10,10 +10,10 @@ import { execa } from 'execa';// Bump these when upgrading FFmpeg. This is also the minimum supported FFmpeg version (see `customFfPath` in src/main/ffmpeg.ts)const macRelease = '8.1.3-1'; // https://github.com/mifi/ffmpeg-build-script/releases-const windowsLinuxRelease = '8.1-1'; // https://github.com/mifi/ffmpeg-builds/releases (mirrors BtbN's n<branch>-latest builds)+const windowsLinuxRelease = '8.1-2'; // https://github.com/mifi/ffmpeg-builds/releases (mirrors BtbN's n<branch>-latest builds)const target = process.argv[2];-const btbnTargets: Record<string, string> = { 'linux-x64': 'linux64', 'win32-x64': 'win64', 'win32-arm64': 'winarm64' };+const btbnTargets: Record<string, string> = { 'linux-x64': 'linux64', 'linux-arm64': 'linuxarm64', 'win32-x64': 'win64', 'win32-arm64': 'winarm64' };const macArchs: Record<string, string> = { 'darwin-x64': 'X64', 'darwin-arm64': 'ARM64' };assert(target != null && (Object.hasOwn(btbnTargets, target) || Object.hasOwn(macArchs, target)), `Usage: downloadFfmpeg.ts ${[...Object.keys(macArchs), ...Object.keys(btbnTargets)].join('|')}`);