clean up and add new showcase videos

This commit is contained in:
2026-03-10 02:32:27 -07:00
parent b32c3cf58c
commit ff5ecdaded
20 changed files with 206 additions and 13 deletions

View File

@@ -102,7 +102,19 @@ fi
has_encoder() {
local encoder="$1"
ffmpeg -hide_banner -encoders 2> /dev/null | grep -qE "[[:space:]]${encoder}[[:space:]]"
ffmpeg -hide_banner -encoders 2> /dev/null | awk -v encoder="$encoder" '$2 == encoder { found = 1 } END { exit(found ? 0 : 1) }'
}
pick_webp_encoder() {
if has_encoder "libwebp_anim"; then
echo "libwebp_anim"
return 0
fi
if has_encoder "libwebp"; then
echo "libwebp"
return 0
fi
return 1
}
crop_vf="crop=1920:1080:760:205"
@@ -168,14 +180,14 @@ else
fi
if [[ "$generate_webp" -eq 1 ]]; then
if ! has_encoder "libwebp"; then
if ! webp_encoder="$(pick_webp_encoder)"; then
echo "Error: encoder not found: libwebp" >&2
exit 1
fi
echo "Generating animated WebP: $webp_out"
echo "Generating animated WebP with $webp_encoder: $webp_out"
ffmpeg "$overwrite_flag" -i "$input" \
-vf "${crop_vf},fps=24,scale=960:-1:flags=lanczos" \
-c:v libwebp \
-c:v "$webp_encoder" \
-q:v 80 \
-loop 0 \
-an \

View File

@@ -0,0 +1,75 @@
import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { spawnSync } from 'node:child_process';
import test from 'node:test';
function withTempDir<T>(fn: (dir: string) => T): T {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-mkv-to-readme-video-test-'));
try {
return fn(dir);
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
}
function writeExecutable(filePath: string, contents: string): void {
fs.writeFileSync(filePath, contents, 'utf8');
fs.chmodSync(filePath, 0o755);
}
test('mkv-to-readme-video accepts libwebp_anim when libwebp is unavailable', () => {
withTempDir((root) => {
const binDir = path.join(root, 'bin');
const inputPath = path.join(root, 'sample.mkv');
const ffmpegLogPath = path.join(root, 'ffmpeg-args.log');
fs.mkdirSync(binDir, { recursive: true });
fs.writeFileSync(inputPath, 'fake-video', 'utf8');
writeExecutable(
path.join(binDir, 'ffmpeg'),
`#!/usr/bin/env bash
set -euo pipefail
if [[ "$#" -ge 2 && "$1" == "-hide_banner" && "$2" == "-encoders" ]]; then
cat <<'EOF'
V....D libx264 libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (codec h264)
V....D libvpx-vp9 libvpx VP9 (codec vp9)
V....D libwebp_anim libwebp WebP image (codec webp)
A....D aac AAC (Advanced Audio Coding)
A....D libopus libopus Opus (codec opus)
EOF
exit 0
fi
printf '%s\\n' "$*" >> "${ffmpegLogPath}"
output=""
for arg in "$@"; do
output="$arg"
done
mkdir -p "$(dirname "$output")"
touch "$output"
`,
);
const result = spawnSync('bash', ['scripts/mkv-to-readme-video.sh', '--webp', inputPath], {
cwd: process.cwd(),
env: {
...process.env,
PATH: `${binDir}:${process.env.PATH || ''}`,
},
encoding: 'utf8',
});
assert.equal(result.status, 0, result.stderr || result.stdout);
assert.equal(fs.existsSync(path.join(root, 'sample.mp4')), true);
assert.equal(fs.existsSync(path.join(root, 'sample.webm')), true);
assert.equal(fs.existsSync(path.join(root, 'sample.webp')), true);
assert.equal(fs.existsSync(path.join(root, 'sample-poster.jpg')), true);
const ffmpegLog = fs.readFileSync(ffmpegLogPath, 'utf8');
assert.match(ffmpegLog, /-c:v libwebp_anim/);
});
});