app: download ffmpeg on the first run, not the first export
record-daemon / Build, check and test (push) Failing after 1m15s
record-daemon / Build, check and test (push) Failing after 1m15s
Clip export needs ffmpeg, and the app fetched it when an export was asked for: a minute of nothing at the worst moment, with the export sitting behind it. The run that follows an install now fetches it in the background and narrates the download in the notice banner; the notice is updated in place and leaves another notice alone. A hidden start (the login item) skips the fetch and leaves it to the export. Only ffmpeg.exe is unpacked. The archive also carries ffplay and ffprobe, which the export paths never call: unpacking all three put 370 MB beside the exe instead of 105 MB. An export asked for while the download runs says so instead of starting a second download over the same directory, and --fetch-ffmpeg runs the same fetch from a shell, printing progress. Checked on this machine: --fetch-ffmpeg downloaded in about 20 s, unpacked, and answered "ready"; a second run returned at once.
This commit is contained in:
1 parent
20303d5ddc
commit
297118cfc1
4 files changed
+174
-5
No files matched your search
+4
-3
@@ -100,9 +100,10 @@ reading (`history::tests`), highlight clipping (`highlight::tests`) and formatti
|
|||||||
the channels left on. Recordings made before the split play as one mixed track.
|
the channels left on. Recordings made before the split play as one mixed track.
|
||||||
8. OS integration: tray icon with open/hide/record/quit, launch at login through the Run key,
|
8. OS integration: tray icon with open/hide/record/quit, launch at login through the Run key,
|
||||||
single instance, and toasts on recording start and stop.
|
single instance, and toasts on recording start and stop.
|
||||||
9. Installer: `packager.toml` targets NSIS and copies the daemon and its OBS files beside the
|
9. Installer: `packager.toml` targets NSIS and copies the daemon, its OBS files and the VC++
|
||||||
exe. `cargo install cargo-packager --locked && cargo packager --release`. The installer has
|
runtime beside the exe. `cargo install cargo-packager --locked && cargo packager --release`.
|
||||||
not been run on a clean VM yet.
|
On the first run the app downloads ffmpeg (`--fetch-ffmpeg` does it from a shell), so clip
|
||||||
|
export is ready before the first clip. The installer has not been run on a clean VM yet.
|
||||||
10. Parity: `tauri-app` is still in the tree. Delete it once the items above are verified on a
|
10. Parity: `tauri-app` is still in the tree. Delete it once the items above are verified on a
|
||||||
machine with a live League Client.
|
machine with a live League Client.
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use std::time::Duration;
|
|||||||
use rune::tok::type_;
|
use rune::tok::type_;
|
||||||
use rune::{Cx, El, Key, KeyEvent, Tx, col, el, row, text};
|
use rune::{Cx, El, Key, KeyEvent, Tx, col, el, row, text};
|
||||||
|
|
||||||
|
use crate::export;
|
||||||
use crate::history::{self, QueueCategory, Summary, Timeline};
|
use crate::history::{self, QueueCategory, Summary, Timeline};
|
||||||
use crate::ipc::{self, Daemon};
|
use crate::ipc::{self, Daemon};
|
||||||
use crate::os;
|
use crate::os;
|
||||||
@@ -145,6 +146,9 @@ pub struct App {
|
|||||||
pub highlights_scroll: ui::ScrollBar,
|
pub highlights_scroll: ui::ScrollBar,
|
||||||
pub events_scroll: ui::ScrollBar,
|
pub events_scroll: ui::ScrollBar,
|
||||||
pub notice: Option<Notice>,
|
pub notice: Option<Notice>,
|
||||||
|
/// ffmpeg being downloaded on the first run, and the whole percent it last reported.
|
||||||
|
pub ffmpeg_rx: Option<Receiver<export::FetchEvent>>,
|
||||||
|
pub ffmpeg_pct: Option<u64>,
|
||||||
pub autostart: bool,
|
pub autostart: bool,
|
||||||
pub logs: String,
|
pub logs: String,
|
||||||
pub pending_review: bool,
|
pub pending_review: bool,
|
||||||
@@ -189,6 +193,8 @@ impl App {
|
|||||||
highlights_scroll: ui::ScrollBar::new(),
|
highlights_scroll: ui::ScrollBar::new(),
|
||||||
events_scroll: ui::ScrollBar::new(),
|
events_scroll: ui::ScrollBar::new(),
|
||||||
notice: None,
|
notice: None,
|
||||||
|
ffmpeg_rx: None,
|
||||||
|
ffmpeg_pct: None,
|
||||||
autostart,
|
autostart,
|
||||||
logs: String::new(),
|
logs: String::new(),
|
||||||
pending_review: false,
|
pending_review: false,
|
||||||
@@ -201,6 +207,19 @@ impl App {
|
|||||||
if headless && !live {
|
if headless && !live {
|
||||||
app.demo();
|
app.demo();
|
||||||
}
|
}
|
||||||
|
// Clip export runs on ffmpeg. Fetch it now, on the run that follows an install, so the
|
||||||
|
// first export does not sit behind a download. A hidden start (the login item) leaves it
|
||||||
|
// to the export itself.
|
||||||
|
let hidden = std::env::args().any(|arg| arg == "--hidden");
|
||||||
|
if !headless && !hidden && export::missing() && !export::fetching() {
|
||||||
|
let (tx, rx) = channel();
|
||||||
|
std::thread::spawn(move || {
|
||||||
|
let _ = export::fetch(move |event| {
|
||||||
|
let _ = tx.send(event);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
app.ffmpeg_rx = Some(rx);
|
||||||
|
}
|
||||||
app
|
app
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,6 +318,15 @@ impl App {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether the notice on screen belongs to the download. It is updated in place; a notice
|
||||||
|
/// the app is showing for something else is not replaced by the progress.
|
||||||
|
fn ffmpeg_banner_showing(&self) -> bool {
|
||||||
|
match &self.notice {
|
||||||
|
None => true,
|
||||||
|
Some(notice) => notice.text.starts_with("Downloading ffmpeg"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn refresh_settings(&self) {
|
pub fn refresh_settings(&self) {
|
||||||
self.daemon.get_settings();
|
self.daemon.get_settings();
|
||||||
}
|
}
|
||||||
@@ -661,6 +689,44 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Taken out of the field so the notice helpers below can borrow the app.
|
||||||
|
if let Some(rx) = self.ffmpeg_rx.take() {
|
||||||
|
let mut finished = false;
|
||||||
|
while let Ok(event) = rx.try_recv() {
|
||||||
|
match event {
|
||||||
|
export::FetchEvent::Bytes { done, total } => {
|
||||||
|
let pct = if total > 0 { done * 100 / total } else { 0 };
|
||||||
|
if self.ffmpeg_pct != Some(pct) {
|
||||||
|
self.ffmpeg_pct = Some(pct);
|
||||||
|
if self.ffmpeg_banner_showing() {
|
||||||
|
self.notify(format!("Downloading ffmpeg for clip exports: {pct}%"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export::FetchEvent::Unpacking => {
|
||||||
|
if self.ffmpeg_banner_showing() {
|
||||||
|
self.notify("Unpacking ffmpeg…");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export::FetchEvent::Finished(result) => {
|
||||||
|
finished = true;
|
||||||
|
match result {
|
||||||
|
Ok(()) => {
|
||||||
|
if self.ffmpeg_banner_showing() {
|
||||||
|
self.notify("ffmpeg is ready: clip export works now");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => self.notify_error(e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if !finished {
|
||||||
|
self.ffmpeg_rx = Some(rx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(rx) = &self.review_rx {
|
if let Some(rx) = &self.review_rx {
|
||||||
match rx.try_recv() {
|
match rx.try_recv() {
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
|
|||||||
+75
-2
@@ -2,10 +2,15 @@
|
|||||||
//! `tauri-app/src-tauri/src/lib.rs`.
|
//! `tauri-app/src-tauri/src/lib.rs`.
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
|
||||||
use ffmpeg_sidecar::command::{FfmpegCommand, ffmpeg_is_installed};
|
use ffmpeg_sidecar::command::{FfmpegCommand, ffmpeg_is_installed};
|
||||||
use ffmpeg_sidecar::download::auto_download;
|
use ffmpeg_sidecar::download::{
|
||||||
|
FfmpegDownloadProgressEvent, download_ffmpeg_package_with_progress, ffmpeg_download_url,
|
||||||
|
unpack_ffmpeg_without_extras,
|
||||||
|
};
|
||||||
use ffmpeg_sidecar::event::{FfmpegEvent, LogLevel};
|
use ffmpeg_sidecar::event::{FfmpegEvent, LogLevel};
|
||||||
|
use ffmpeg_sidecar::paths::{sidecar_dir, sidecar_path};
|
||||||
|
|
||||||
use crate::daemon;
|
use crate::daemon;
|
||||||
|
|
||||||
@@ -16,12 +21,80 @@ pub fn clips_dir() -> PathBuf {
|
|||||||
dir
|
dir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set while `fetch` runs, so an export during the download does not start a second one that
|
||||||
|
/// unpacks over the first.
|
||||||
|
static FETCHING: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
||||||
|
/// What `fetch` reports while it runs.
|
||||||
|
pub enum FetchEvent {
|
||||||
|
/// Bytes of the download so far, of the total the server announced.
|
||||||
|
Bytes { done: u64, total: u64 },
|
||||||
|
/// The archive is complete and being unpacked beside the exe.
|
||||||
|
Unpacking,
|
||||||
|
/// The work is over, with its outcome.
|
||||||
|
Finished(Result<(), String>),
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether ffmpeg still has to be downloaded: it lives beside the exe. The presence of the file
|
||||||
|
/// is enough here; `ffmpeg -version` is left to the export that needs it.
|
||||||
|
pub fn missing() -> bool {
|
||||||
|
sidecar_path().map(|path| !path.exists()).unwrap_or(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether a download is running right now.
|
||||||
|
pub fn fetching() -> bool {
|
||||||
|
FETCHING.load(Ordering::SeqCst)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Download ffmpeg beside the exe, reporting progress. Blocks: call it on a thread.
|
||||||
|
///
|
||||||
|
/// Only `ffmpeg.exe` is unpacked. The archive carries `ffplay` and `ffprobe` too, and the
|
||||||
|
/// export paths call neither; unpacking all three would add 200 MB to every install.
|
||||||
|
pub fn fetch(report: impl Fn(FetchEvent)) -> Result<(), String> {
|
||||||
|
if ffmpeg_is_installed() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
FETCHING.store(true, Ordering::SeqCst);
|
||||||
|
let result = download(&report);
|
||||||
|
FETCHING.store(false, Ordering::SeqCst);
|
||||||
|
report(FetchEvent::Finished(result.clone()));
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
fn download(report: &impl Fn(FetchEvent)) -> Result<(), String> {
|
||||||
|
let url = ffmpeg_download_url().map_err(|e| format!("cannot find a build to download: {e}"))?;
|
||||||
|
let dir = sidecar_dir().map_err(|e| format!("cannot find where to put ffmpeg: {e}"))?;
|
||||||
|
let archive = download_ffmpeg_package_with_progress(url, &dir, |event| {
|
||||||
|
if let FfmpegDownloadProgressEvent::Downloading {
|
||||||
|
total_bytes,
|
||||||
|
downloaded_bytes,
|
||||||
|
} = event
|
||||||
|
{
|
||||||
|
report(FetchEvent::Bytes {
|
||||||
|
done: downloaded_bytes,
|
||||||
|
total: total_bytes,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.map_err(|e| format!("cannot download ffmpeg: {e}"))?;
|
||||||
|
report(FetchEvent::Unpacking);
|
||||||
|
unpack_ffmpeg_without_extras(&archive, &dir)
|
||||||
|
.map_err(|e| format!("cannot unpack ffmpeg: {e}"))?;
|
||||||
|
if !ffmpeg_is_installed() {
|
||||||
|
return Err("ffmpeg did not end up beside the app".to_string());
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Download the ffmpeg sidecar on first use.
|
/// Download the ffmpeg sidecar on first use.
|
||||||
pub fn ensure_ffmpeg() -> Result<(), String> {
|
pub fn ensure_ffmpeg() -> Result<(), String> {
|
||||||
if ffmpeg_is_installed() {
|
if ffmpeg_is_installed() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
auto_download().map_err(|e| format!("cannot download ffmpeg: {e}"))
|
if fetching() {
|
||||||
|
return Err("ffmpeg is still downloading; try the export again in a moment".to_string());
|
||||||
|
}
|
||||||
|
fetch(|_| {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Export `start..end` of `video`. Stream copy is fast and keyframe-aligned; `precise` re-encodes
|
/// Export `start..end` of `video`. Stream copy is fast and keyframe-aligned; `precise` re-encodes
|
||||||
|
|||||||
@@ -52,6 +52,12 @@ fn main() {
|
|||||||
probe();
|
probe();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// `--fetch-ffmpeg`: download ffmpeg beside the exe and exit, 0 when it is ready. The app
|
||||||
|
// does this itself on the first run; this is the same fetch, for a shortcut or a script.
|
||||||
|
if std::env::args().any(|arg| arg == "--fetch-ffmpeg") {
|
||||||
|
fetch_ffmpeg();
|
||||||
|
return;
|
||||||
|
}
|
||||||
// A second launch hands its arguments to the first and exits; the tooling modes
|
// A second launch hands its arguments to the first and exits; the tooling modes
|
||||||
// (`--snap`, `--tree`, that sort of thing) render or print and exit, so they never forward.
|
// (`--snap`, `--tree`, that sort of thing) render or print and exit, so they never forward.
|
||||||
if !app::headless() && !rune::single_instance(os::APP_ID) {
|
if !app::headless() && !rune::single_instance(os::APP_ID) {
|
||||||
@@ -125,6 +131,29 @@ fn main() {
|
|||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `--fetch-ffmpeg`: download ffmpeg with the same code the first run uses, printing progress.
|
||||||
|
fn fetch_ffmpeg() {
|
||||||
|
let shown = std::cell::Cell::new(u64::MAX);
|
||||||
|
let result = export::fetch(|event| match event {
|
||||||
|
export::FetchEvent::Bytes { done, total } => {
|
||||||
|
let pct = if total > 0 { done * 100 / total } else { 0 };
|
||||||
|
if pct != shown.get() {
|
||||||
|
shown.set(pct);
|
||||||
|
println!("ffmpeg: {pct}%");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export::FetchEvent::Unpacking => println!("ffmpeg: unpacking"),
|
||||||
|
export::FetchEvent::Finished(_) => {}
|
||||||
|
});
|
||||||
|
match result {
|
||||||
|
Ok(()) => println!("ffmpeg: ready"),
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("{e}");
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// `--probe`: bring the daemon up and print what it answers, then exit. A quick check that the
|
/// `--probe`: bring the daemon up and print what it answers, then exit. A quick check that the
|
||||||
/// IPC client and the daemon agree without opening a window.
|
/// IPC client and the daemon agree without opening a window.
|
||||||
fn probe() {
|
fn probe() {
|
||||||
|
|||||||
Reference in new issue
Block a user