Merge pull request #384 from storytold/feat/297-image-sequences
Import: image sequences with a Sequence option, ranges, folders and missing frames (#297) # Conflicts: # docs/parity.md
This commit is contained in:
@@ -5,6 +5,7 @@ use effectcraft_project::{FootageKind, ItemId, ItemKind, LayerSource, Project};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use super::{CommandSpec, always, b_p, bad, str_p};
|
||||
use crate::sequence::{SequenceOptions, Source};
|
||||
use crate::{EngineError, Result, Session, cmd};
|
||||
|
||||
fn has_path(s: &Session) -> std::result::Result<(), String> {
|
||||
@@ -111,23 +112,22 @@ fn revert(s: &mut Session, _: &Value) -> Result<Value> {
|
||||
fn import_cmd(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let target = s.active_comp_id();
|
||||
let mut pending = prepare_import(s, p)?;
|
||||
if b_p(p, "background").unwrap_or(false) && !pending.paths.is_empty() {
|
||||
let paths = std::mem::take(&mut pending.paths);
|
||||
let total = paths.len();
|
||||
let label = match paths.first() {
|
||||
Some(one) if total == 1 => format!("Importing {}", file_name(one)),
|
||||
if b_p(p, "background").unwrap_or(false) && !pending.sources.is_empty() {
|
||||
let sources = std::mem::take(&mut pending.sources);
|
||||
let total = sources.len();
|
||||
let label = match sources.first() {
|
||||
Some(one) if total == 1 => format!("Importing {}", one.name()),
|
||||
_ => format!("Importing {total} files"),
|
||||
};
|
||||
let p = p.clone();
|
||||
return s.spawn_task("import", label, false, move |ctl| {
|
||||
let mut probed = Vec::with_capacity(total);
|
||||
for (k, path) in paths.into_iter().enumerate() {
|
||||
ctl.message(format!("{} ({} of {total})", file_name(&path), k + 1));
|
||||
for (k, src) in sources.iter().enumerate() {
|
||||
ctl.message(format!("{} ({} of {total})", src.name(), k + 1));
|
||||
if !ctl.progress(k as u64, total as u64) {
|
||||
return Err(crate::render_queue::CANCELLED.into());
|
||||
}
|
||||
let r = pending.prober.probe(&path);
|
||||
probed.push(r);
|
||||
probed.push(pending.prober.probe(src));
|
||||
}
|
||||
ctl.progress(total as u64, total as u64);
|
||||
let apply: crate::jobs::Apply = Box::new(move |s: &mut Session| {
|
||||
@@ -147,17 +147,12 @@ fn import_cmd(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
Ok(apply)
|
||||
});
|
||||
}
|
||||
let probed = pending.paths.iter().map(|path| pending.prober.probe(path)).collect();
|
||||
let probed = pending.sources.iter().map(|src| pending.prober.probe(src)).collect();
|
||||
let mut r = add_footage(s, pending, probed)?;
|
||||
finish_import(s, &mut r, target, p);
|
||||
Ok(r)
|
||||
}
|
||||
|
||||
/// The file name of a path, for labels.
|
||||
fn file_name(path: &str) -> String {
|
||||
std::path::Path::new(path).file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_else(|| path.to_string())
|
||||
}
|
||||
|
||||
/// After an import (its result `r`): with `addToComp`, the new items become layers of `target`;
|
||||
/// what couldn't be added joins the result's errors.
|
||||
fn finish_import(s: &mut Session, r: &mut Value, target: Option<ItemId>, p: &Value) {
|
||||
@@ -206,14 +201,14 @@ pub(crate) fn add_to_comp(s: &mut Session, r: &Value, target: Option<ItemId>, p:
|
||||
/// File ▸ Import, all in one go (scripts and commands built on it); see [`import_cmd`].
|
||||
pub(crate) fn import(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let pending = prepare_import(s, p)?;
|
||||
let probed = pending.paths.iter().map(|path| pending.prober.probe(path)).collect();
|
||||
let probed = pending.sources.iter().map(|src| pending.prober.probe(src)).collect();
|
||||
add_footage(s, pending, probed)
|
||||
}
|
||||
|
||||
/// An import whose layered files are already compositions: the files left to probe as footage,
|
||||
/// how, and what the import made so far.
|
||||
/// An import whose layered files are already compositions: the files and image sequences left
|
||||
/// to probe as footage, how, and what the import made so far.
|
||||
struct PendingImport {
|
||||
paths: Vec<String>,
|
||||
sources: Vec<Source>,
|
||||
prober: Prober,
|
||||
comps: Vec<u64>,
|
||||
items: Vec<u64>,
|
||||
@@ -229,7 +224,8 @@ struct Prober {
|
||||
/// Settings ▸ Import ▸ Interpret Unlabeled Alpha As, for stills and for movies.
|
||||
still_alpha: Option<effectcraft_project::AlphaMode>,
|
||||
movie_alpha: Option<effectcraft_project::AlphaMode>,
|
||||
/// Settings ▸ Import ▸ Sequence Footage frames per second.
|
||||
/// Image sequences' frames per second: the import's `frameRate`, or Settings ▸ Import ▸
|
||||
/// Sequence Footage.
|
||||
sequence_rate: effectcraft_time::FrameRate,
|
||||
/// PDF / Illustrator page (0-based).
|
||||
page: u32,
|
||||
@@ -237,9 +233,10 @@ struct Prober {
|
||||
psd_layer: Option<Value>,
|
||||
}
|
||||
|
||||
/// A file probed as footage.
|
||||
/// A file (or image sequence) probed as footage.
|
||||
struct Probed {
|
||||
path: String,
|
||||
/// The Project panel name.
|
||||
name: String,
|
||||
footage: effectcraft_project::Footage,
|
||||
/// Its alpha is unlabeled and Settings say Ask User: open Interpret Footage.
|
||||
ask_alpha: bool,
|
||||
@@ -247,22 +244,27 @@ struct Probed {
|
||||
}
|
||||
|
||||
impl Prober {
|
||||
/// Probe `path` as footage; the error names the file.
|
||||
fn probe(&self, path: &str) -> std::result::Result<Probed, String> {
|
||||
/// Probe a file or image sequence as footage; the error names the file.
|
||||
fn probe(&self, src: &Source) -> std::result::Result<Probed, String> {
|
||||
let path = src.path();
|
||||
let name = src.name();
|
||||
let fail = |e: String| format!("{path}: {e}");
|
||||
// Data files (JSON, CSV, TSV) for data-driven animation: kept as text in the project.
|
||||
if let Some(f) = data_footage(self.services.as_ref(), path) {
|
||||
return f.map(|footage| Probed { path: path.to_string(), footage, ask_alpha: false, warning: None }).map_err(fail);
|
||||
if let Source::File(_) = src
|
||||
&& let Some(f) = data_footage(self.services.as_ref(), path)
|
||||
{
|
||||
return f.map(|footage| Probed { name, footage, ask_alpha: false, warning: None }).map_err(fail);
|
||||
}
|
||||
let importer = self.importer.as_ref().ok_or_else(|| fail("media import is not available in this build".into()))?;
|
||||
let mut f = importer.probe(path).map_err(fail)?;
|
||||
let mut f = crate::sequence::probe(importer.as_ref(), src, self.sequence_rate).map_err(fail)?;
|
||||
let mut warning = None;
|
||||
// Settings ▸ Import ▸ Report Missing Frames.
|
||||
// Settings ▸ Import ▸ Report Missing Frames (numbered sequences).
|
||||
if f.kind == FootageKind::Sequence
|
||||
&& !f.alphabetical
|
||||
&& self.report_missing_frames
|
||||
&& let Some(gaps) = missing_frames(&f.sequence)
|
||||
&& let Some(gaps) = crate::sequence::missing_report(&f.sequence)
|
||||
{
|
||||
warning = Some(format!("{path}: {gaps}"));
|
||||
warning = Some(format!("{name}: {gaps} (shown as placeholders)"));
|
||||
}
|
||||
// Settings ▸ Import ▸ Interpret Unlabeled Alpha As: images only (a 3D model renders its
|
||||
// own alpha, and audio and data have none).
|
||||
@@ -277,13 +279,6 @@ impl Prober {
|
||||
None => ask_alpha = true,
|
||||
}
|
||||
}
|
||||
// Settings ▸ Import ▸ Sequence Footage frames per second.
|
||||
if f.kind == FootageKind::Sequence {
|
||||
let r = self.sequence_rate;
|
||||
let frames = f.frame_rate.frame_at(f.duration);
|
||||
f.frame_rate = r;
|
||||
f.duration = r.tick_of(frames.max(1));
|
||||
}
|
||||
// Page: another page of a PDF / Illustrator file.
|
||||
if self.page > 0 && matches!(f.codec.as_str(), "PDF" | "AI") {
|
||||
let doc = self
|
||||
@@ -308,7 +303,7 @@ impl Prober {
|
||||
.ok_or_else(|| fail(format!("no layer {sel}")))?;
|
||||
f.layer = Some(effectcraft_project::SourceLayer { index: index as u32, name, layer_size: false, embedded: None, placed: false });
|
||||
}
|
||||
Ok(Probed { path: path.to_string(), footage: f, ask_alpha, warning })
|
||||
Ok(Probed { name, footage: f, ask_alpha, warning })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,17 +374,25 @@ fn prepare_import(s: &mut Session, p: &Value) -> Result<PendingImport> {
|
||||
}
|
||||
paths = rest;
|
||||
}
|
||||
// Numbered stills as image sequences (the Import dialog's "<format> Sequence" and Force
|
||||
// Alphabetical Order), at `frameRate` or Settings ▸ Import ▸ Sequence Footage.
|
||||
let opts = SequenceOptions::from_params(p);
|
||||
let fps = match p.get("frameRate") {
|
||||
None | Some(Value::Null) => s.prefs.import.sequence_fps,
|
||||
Some(v) => v.as_f64().filter(|x| *x > 0.0 && *x <= 999.0).ok_or_else(|| bad("file.import", "frameRate: frames per second, up to 999"))?,
|
||||
};
|
||||
let sources = crate::sequence::group(s.services.as_ref(), &paths, opts);
|
||||
let prober = Prober {
|
||||
importer: s.importer.clone(),
|
||||
services: s.services.clone(),
|
||||
report_missing_frames: s.prefs.import.report_missing_frames,
|
||||
still_alpha: s.prefs.unlabeled_alpha(false),
|
||||
movie_alpha: s.prefs.unlabeled_alpha(true),
|
||||
sequence_rate: effectcraft_time::FrameRate::from_f64(s.prefs.import.sequence_fps),
|
||||
sequence_rate: effectcraft_time::FrameRate::from_f64(fps),
|
||||
page,
|
||||
psd_layer: p.get("layer").cloned(),
|
||||
};
|
||||
Ok(PendingImport { paths, prober, comps, items, errors })
|
||||
Ok(PendingImport { sources, prober, comps, items, errors })
|
||||
}
|
||||
|
||||
/// The last part of an import: add the probed files to the project (one undo step) and select
|
||||
@@ -413,7 +416,7 @@ fn add_footage(s: &mut Session, pending: PendingImport, probed: Vec<std::result:
|
||||
s.edit("Import", None, |proj, st| {
|
||||
let mut selection = made;
|
||||
for f in found {
|
||||
let name = file_name(&f.path);
|
||||
let name = f.name;
|
||||
let footage = f.footage;
|
||||
let name = match &footage.layer {
|
||||
Some(l) => format!("{}/{name}", l.name),
|
||||
@@ -457,29 +460,6 @@ fn alpha_is_labeled(path: &str, codec: &str) -> bool {
|
||||
matches!(ext.as_str(), "png" | "gif" | "webp" | "psd" | "psb" | "exr" | "svg" | "jpg" | "jpeg" | "ai" | "pdf" | "eps") || codec.eq_ignore_ascii_case("PSD")
|
||||
}
|
||||
|
||||
/// Gaps in an image sequence's frame numbers ("missing frames 4–6, 9"), from the digit run at the
|
||||
/// end of each file name. `None` when the numbering is continuous (or there is none).
|
||||
pub(crate) fn missing_frames(files: &[String]) -> Option<String> {
|
||||
let num = |f: &String| -> Option<i64> {
|
||||
let stem = std::path::Path::new(f).file_stem()?.to_string_lossy().to_string();
|
||||
let digits: String = stem.chars().rev().take_while(char::is_ascii_digit).collect::<Vec<_>>().into_iter().rev().collect();
|
||||
digits.parse().ok()
|
||||
};
|
||||
let mut ns: Vec<i64> = files.iter().filter_map(num).collect();
|
||||
ns.sort_unstable();
|
||||
ns.dedup();
|
||||
let mut gaps = vec![];
|
||||
let mut total = 0;
|
||||
for w in ns.windows(2) {
|
||||
if w[1] - w[0] > 1 {
|
||||
let (a, b) = (w[0] + 1, w[1] - 1);
|
||||
total += b - a + 1;
|
||||
gaps.push(if a == b { a.to_string() } else { format!("{a}–{b}") });
|
||||
}
|
||||
}
|
||||
(!gaps.is_empty()).then(|| format!("{total} missing frame{} ({})", if total == 1 { "" } else { "s" }, gaps.join(", ")))
|
||||
}
|
||||
|
||||
/// A Photoshop layer by index or name (pixel layers only).
|
||||
fn find_psd_layer(d: &effectcraft_psd::Psd, sel: &Value) -> Option<(usize, String)> {
|
||||
let l = match sel {
|
||||
@@ -700,7 +680,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"File...",
|
||||
["File", "Import"],
|
||||
Some("Cmd+I"),
|
||||
"{paths: [string], importAs?: footage|composition|compositionLayerSizes (Photoshop, PDF, Illustrator and EPS files), layer?: name|index (footage of one Photoshop layer), page?: number from 1 (PDF / Illustrator page), drag?: bool (dropped files: Settings ▸ Import ▸ Default Drag Import As), addToComp?: bool (also add them to the active comp, at time?, index?, position? as in layer.addItem), background?: bool (probe the files in a background job, jobs.list / jobs.wait; returns {job})}",
|
||||
"{paths: [string] (files or folders), sequence?: bool (default true: numbered stills of one run import as one image sequence; one picked file brings its whole run, several picked files that range), alphabetical?: bool (Force Alphabetical Order: every image of that type in the folder, by name), frameRate?: fps (image sequences; default Settings ▸ Import ▸ Sequence Footage), importAs?: footage|composition|compositionLayerSizes (Photoshop, PDF, Illustrator and EPS files), layer?: name|index (footage of one Photoshop layer), page?: number from 1 (PDF / Illustrator page), drag?: bool (dropped files: Settings ▸ Import ▸ Default Drag Import As), addToComp?: bool (also add them to the active comp, at time?, index?, position? as in layer.addItem), background?: bool (probe the files in a background job, jobs.list / jobs.wait; returns {job})}",
|
||||
always,
|
||||
import_cmd
|
||||
),
|
||||
|
||||
@@ -10,6 +10,7 @@ use effectcraft_time::{FrameRate, Tick};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use super::{CommandSpec, always, b_p, bad, f_p, has_comp, has_project_selection, str_p};
|
||||
use crate::sequence::SequenceOptions;
|
||||
use crate::{EngineError, Result, Session, cmd};
|
||||
|
||||
fn has_footage_selection(s: &Session) -> std::result::Result<(), String> {
|
||||
@@ -552,6 +553,8 @@ pub(crate) struct Interpretation {
|
||||
fields: Option<effectcraft_project::FieldOrder>,
|
||||
profile: Option<Option<effectcraft_project::ColorSpace>>,
|
||||
linear: Option<bool>,
|
||||
/// Image sequences: Start Frame (`Some(None)` = the first file's number).
|
||||
start: Option<Option<i64>>,
|
||||
}
|
||||
|
||||
impl Interpretation {
|
||||
@@ -598,12 +601,28 @@ impl Interpretation {
|
||||
None => None,
|
||||
};
|
||||
it.linear = super::b_p(p, "linearLight");
|
||||
// Start Frame: a frame number, or "file" for the first file's.
|
||||
it.start = match p.get("startFrame") {
|
||||
None | Some(Value::Null) => None,
|
||||
Some(Value::String(f)) if f == "file" => Some(None),
|
||||
Some(v) => Some(Some(
|
||||
v.as_f64()
|
||||
.filter(|x| x.is_finite() && x.abs() <= 1.0e9)
|
||||
.map(|x| x.round() as i64)
|
||||
.ok_or_else(|| bad(cmd, "startFrame: a frame number (up to 1e9), or \"file\""))?,
|
||||
)),
|
||||
};
|
||||
Ok(it)
|
||||
}
|
||||
|
||||
pub(crate) fn apply(&self, f: &mut Footage, guessed: Option<(AlphaMode, [f32; 3])>) {
|
||||
let before = f.frame_rate;
|
||||
self.apply_settings(f, guessed);
|
||||
// A sequence's length is its frames (Start Frame decides how many).
|
||||
if f.kind == FootageKind::Sequence && !f.sequence.is_empty() {
|
||||
f.sync_sequence_duration();
|
||||
return;
|
||||
}
|
||||
// Conforming keeps the frames and changes how long they last (12 frames at 30 fps are
|
||||
// 0.4 s; conformed to 12 fps, 1 s). Stills have no frame rate of their own.
|
||||
let (old, new) = (before.as_f64(), f.frame_rate.as_f64());
|
||||
@@ -652,6 +671,13 @@ impl Interpretation {
|
||||
if let Some(v) = self.linear {
|
||||
f.linear_light = v;
|
||||
}
|
||||
if f.kind == FootageKind::Sequence
|
||||
&& let Some(start) = self.start
|
||||
{
|
||||
// The first file's own number needn't be stored (it follows the files).
|
||||
let first = f.sequence.first().and_then(|p| effectcraft_project::sequence::frame_number(p));
|
||||
f.start_frame = start.filter(|n| Some(*n) != first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -728,7 +754,8 @@ fn interpret(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
Some(ItemKind::Footage(f)) => Some(json!({
|
||||
"item": i.0, "alpha": format!("{:?}", f.alpha), "matteColor": f.premul_color, "invertAlpha": f.invert_alpha,
|
||||
"fields": f.fields.label(), "pixelAspect": f.pixel_aspect, "loop": f.loop_count, "frameRate": f.frame_rate.as_f64(),
|
||||
"linearLight": f.linear_light,
|
||||
"linearLight": f.linear_light, "startFrame": f.first_frame_number(),
|
||||
"frames": f.sequence_frames(),
|
||||
})),
|
||||
_ => None,
|
||||
})
|
||||
@@ -775,8 +802,11 @@ fn replace_footage(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let path = str_p(p, "path").ok_or_else(|| bad("file.replaceFootage", "missing `path`"))?.to_string();
|
||||
let item = *items_p(s, p).first().ok_or_else(|| bad("file.replaceFootage", "select footage"))?;
|
||||
let importer = s.importer.clone().ok_or_else(|| EngineError::Other("media import is not available in this build".into()))?;
|
||||
let f = importer.probe(&path).map_err(|e| EngineError::Other(format!("{path}: {e}")))?;
|
||||
let name = std::path::Path::new(&path).file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or(path.clone());
|
||||
// A numbered still brings its image sequence, as on import (`sequence: false` for one frame).
|
||||
let opts = SequenceOptions::from_params(p);
|
||||
let src = crate::sequence::source_of(s.services.as_ref(), &path, opts);
|
||||
let f = crate::sequence::probe(importer.as_ref(), &src, s.sequence_rate()).map_err(|e| EngineError::Other(format!("{path}: {e}")))?;
|
||||
let name = src.name();
|
||||
s.edit("Replace Footage", None, |proj, _| {
|
||||
let it = proj.item_mut(item).ok_or_else(|| bad("file.replaceFootage", "no such item"))?;
|
||||
it.name = name;
|
||||
@@ -843,11 +873,14 @@ fn replace_with_solid(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
|
||||
fn reload(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let items = items_p(s, p);
|
||||
let Some(importer) = s.importer.clone() else { return Err(EngineError::Other("media import is not available in this build".into())) };
|
||||
if s.importer.is_none() {
|
||||
return Err(EngineError::Other("media import is not available in this build".into()));
|
||||
}
|
||||
let mut updates = vec![];
|
||||
for i in &items {
|
||||
if let Some(ItemKind::Footage(f)) = s.project.item(*i).map(|x| &x.kind) {
|
||||
let mut nf = match importer.probe(&f.path) {
|
||||
// An image sequence picks up frames added to (or removed from) its run.
|
||||
let mut nf = match s.probe_footage(&f.path) {
|
||||
Ok(n) => n,
|
||||
Err(_) => Footage { missing: true, ..f.clone() },
|
||||
};
|
||||
@@ -855,6 +888,13 @@ fn reload(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
nf.alpha = f.alpha;
|
||||
nf.loop_count = f.loop_count;
|
||||
nf.pixel_aspect = f.pixel_aspect;
|
||||
if nf.kind == FootageKind::Sequence && f.kind == FootageKind::Sequence {
|
||||
nf.frame_rate = f.frame_rate;
|
||||
nf.native_rate = f.native_rate;
|
||||
nf.alphabetical = f.alphabetical;
|
||||
nf.start_frame = f.start_frame;
|
||||
nf.sync_sequence_duration();
|
||||
}
|
||||
updates.push((*i, nf));
|
||||
}
|
||||
}
|
||||
@@ -954,7 +994,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Main...",
|
||||
["File", "Interpret Footage"],
|
||||
Some("Cmd+Alt+G"),
|
||||
"{items?, frameRate?: fps|\"file\", alpha?: straight|premultiplied|ignore|guess, guessAlpha?, matteColor?, invertAlpha?, loop?, pixelAspect?, fields?: off|upper|lower, colorProfile?: srgb|rec709|rec2020|p3|auto, linearLight?}",
|
||||
"{items?, frameRate?: fps|\"file\", alpha?: straight|premultiplied|ignore|guess, guessAlpha?, matteColor?, invertAlpha?, loop?, pixelAspect?, fields?: off|upper|lower, colorProfile?: srgb|rec709|rec2020|p3|auto, linearLight?, startFrame?: number|\"file\" (image sequences: the frame number at the footage's first frame)}",
|
||||
has_footage_selection,
|
||||
interpret
|
||||
),
|
||||
@@ -976,7 +1016,15 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
has_interpretation,
|
||||
apply_interpretation
|
||||
),
|
||||
cmd!("file.replaceFootage", "File...", ["File", "Replace Footage"], Some("Cmd+H"), "{path, item?}", has_footage_selection, replace_footage),
|
||||
cmd!(
|
||||
"file.replaceFootage",
|
||||
"File...",
|
||||
["File", "Replace Footage"],
|
||||
Some("Cmd+H"),
|
||||
"{path, item?, sequence?: bool (default true: a numbered still brings its image sequence), alphabetical?: bool}",
|
||||
has_footage_selection,
|
||||
replace_footage
|
||||
),
|
||||
cmd!(
|
||||
"file.replaceWithPlaceholder",
|
||||
"Placeholder...",
|
||||
|
||||
@@ -74,8 +74,6 @@ pub(crate) mod watch_folder;
|
||||
pub(crate) use app_more::report_text as report_text_for_tests;
|
||||
pub(crate) use app_more::view_command;
|
||||
#[cfg(test)]
|
||||
pub(crate) use file::missing_frames as missing_frames_for_tests;
|
||||
#[cfg(test)]
|
||||
pub(crate) use keys_more::amplitudes as amplitudes_for_tests;
|
||||
#[cfg(test)]
|
||||
pub(crate) use mask::split_segment as split_segment_for_tests;
|
||||
|
||||
@@ -120,9 +120,8 @@ fn file_info(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let path = str_p(p, "path").ok_or_else(|| bad("mediaBrowser.fileInfo", "missing `path`"))?;
|
||||
let (created, modified, size) = mb::file_dates(path);
|
||||
let mut v = json!({"path": path, "kind": mb::kind_of(path), "size": size, "created": created.map(mb::iso_date), "modified": modified.map(mb::iso_date)});
|
||||
if let Some(imp) = s.importer.clone()
|
||||
&& matches!(mb::kind_of(path), Some("video" | "image" | "audio" | "model"))
|
||||
&& let Ok(f) = imp.probe(path)
|
||||
if matches!(mb::kind_of(path), Some("video" | "image" | "audio" | "model"))
|
||||
&& let Ok(f) = s.probe_footage(path)
|
||||
{
|
||||
v["footage"] = mb::footage_metadata(&f);
|
||||
}
|
||||
|
||||
@@ -40,8 +40,11 @@ fn has_proxy(s: &Session) -> std::result::Result<(), String> {
|
||||
|
||||
/// Probe a proxy file through the importer.
|
||||
fn probe(s: &Session, path: &str, cmd: &str) -> Result<Footage> {
|
||||
let importer = s.importer.clone().ok_or_else(|| EngineError::Other("media import is not available in this build".into()))?;
|
||||
let f = importer.probe(path).map_err(|e| bad(cmd, format!("{path}: {e}")))?;
|
||||
if s.importer.is_none() {
|
||||
return Err(EngineError::Other("media import is not available in this build".into()));
|
||||
}
|
||||
// The first frame of a proxy sequence (Create Proxy ▸ Movie renders one) brings the rest.
|
||||
let f = s.probe_footage(path).map_err(|e| bad(cmd, format!("{path}: {e}")))?;
|
||||
if !f.has_video {
|
||||
return Err(bad(cmd, format!("{path} has no video to use as a proxy")));
|
||||
}
|
||||
|
||||
@@ -40,11 +40,12 @@ fn import_timeline(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
};
|
||||
let importer = s.importer.clone();
|
||||
let services = s.services.clone();
|
||||
let rate = s.sequence_rate();
|
||||
let mut probe = move |m: &str| -> Option<effectcraft_project::Footage> {
|
||||
if !services.exists(m) {
|
||||
return None;
|
||||
}
|
||||
importer.as_ref()?.probe(m).ok()
|
||||
crate::sequence::probe_path(importer.as_deref()?, services.as_ref(), m, rate).ok()
|
||||
};
|
||||
let res = s.edit("Import Timeline", None, |proj, st| {
|
||||
let r = effectcraft_interchange::import(proj, &bytes, format, &opts, &mut probe).map_err(|e| EngineError::Other(e.to_string()))?;
|
||||
|
||||
Reference in New Issue
Block a user