ffmpeg implemented

This commit is contained in:
2026-01-11 13:40:01 +01:00
parent 34c3f0dc89
commit c4020615d2
18 changed files with 474 additions and 16 deletions

66
tools/copy-ffmpeg.js Normal file
View File

@@ -0,0 +1,66 @@
#!/usr/bin/env node
import fs from 'fs';
import path from 'path';
const repoRoot = process.cwd();
const tauriDir = path.join(repoRoot, 'src-tauri');
const resourcesDir = path.join(tauriDir, 'resources');
function platformBinName() {
return process.platform === 'win32' ? 'ffmpeg.exe' : 'ffmpeg';
}
function exists(p) {
try { return fs.existsSync(p); } catch { return false; }
}
function ensureDir(p) {
if (!exists(p)) fs.mkdirSync(p, { recursive: true });
}
// Source lookup order:
// 1) RADIOPLAYER_FFMPEG (absolute or relative)
// 2) tools/ffmpeg/ffmpeg(.exe)
// 3) tools/ffmpeg/bin/ffmpeg(.exe)
function resolveSource() {
const env = process.env.RADIOPLAYER_FFMPEG;
if (env && String(env).trim().length > 0) {
const p = path.isAbsolute(env) ? env : path.join(repoRoot, env);
if (exists(p)) return p;
console.warn(`RADIOPLAYER_FFMPEG set but not found: ${p}`);
}
const name = platformBinName();
const candidates = [
path.join(repoRoot, 'tools', 'ffmpeg', name),
path.join(repoRoot, 'tools', 'ffmpeg', 'bin', name),
];
return candidates.find(exists) || null;
}
function main() {
const name = platformBinName();
const src = resolveSource();
if (!src) {
console.log('FFmpeg not provided; skipping copy (set RADIOPLAYER_FFMPEG or place it under tools/ffmpeg/).');
process.exit(0);
}
ensureDir(resourcesDir);
const dst = path.join(resourcesDir, name);
try {
fs.copyFileSync(src, dst);
// Best-effort: ensure executable bit on unix-like platforms.
if (process.platform !== 'win32') {
try { fs.chmodSync(dst, 0o755); } catch {}
}
console.log(`Copied FFmpeg into bundle resources: ${src} -> ${dst}`);
} catch (e) {
console.error('Failed to copy FFmpeg:', e);
process.exit(1);
}
}
main();

45
tools/ffmpeg/README.md Normal file
View File

@@ -0,0 +1,45 @@
# FFmpeg (Optional) for Native Playback
The native player uses an external **FFmpeg** binary to decode radio streams.
## Why this exists
- The app intentionally does **not** download or embed FFmpeg automatically.
- You provide FFmpeg yourself (license/compliance-friendly).
## How the app finds FFmpeg
At runtime it searches in this order:
1. `RADIOPLAYER_FFMPEG` environment variable (absolute or relative path)
2. Next to the application executable (Windows: `ffmpeg.exe`, macOS/Linux: `ffmpeg`)
3. Common bundle resource folders relative to the executable:
- `resources/ffmpeg(.exe)`
- `Resources/ffmpeg(.exe)`
- `../resources/ffmpeg(.exe)`
- `../Resources/ffmpeg(.exe)`
4. Your system `PATH`
## Recommended setup (Windows dev)
- Put `ffmpeg.exe` somewhere stable, then set:
`RADIOPLAYER_FFMPEG=C:\\path\\to\\ffmpeg.exe`
Or copy `ffmpeg.exe` next to the built app binary:
- `src-tauri/target/debug/ffmpeg.exe` (dev)
- `src-tauri/target/release/ffmpeg.exe` (release)
## Optional: download helper (Windows)
You can also run:
`npm run ffmpeg:download`
This downloads a prebuilt FFmpeg zip and extracts `ffmpeg.exe` into `tools/ffmpeg/bin/ffmpeg.exe`.
## Notes
- The player will fail fast with a clear error if FFmpeg is missing.
- The project already includes a copy step (`tools/copy-ffmpeg.js`) that runs before `tauri`/`build` and places FFmpeg into `src-tauri/resources/` for bundling.

BIN
tools/ffmpeg/bin/ffmpeg.exe Normal file

Binary file not shown.