#886: say why footage the decoders can't read shows no picture

Problem: a movie whose profile the software decoders lack (H.264 High 4:2:2 / 10-bit)
probes fine, then every frame read fails; MediaPool logged the error per frame and returned
None, so the layer rendered black with no sign why in the viewer, Project panel or for agents.

Fix: MediaPool records the reason once per file (codec from the probe plus the decoder's text
without error wrappers; I/O errors stay with missing-footage handling), logs it once, and
exposes it through the new FootageSource::problem. The Composition viewer shows it on the
affected layer, the Project panel marks the item with a warning whose tooltip is the reason,
and project.summary / footage.info carry a "problem" field. Cleared when the file is
forgotten; only set when decoding really failed, so a hardware decoder that handles the file
shows nothing.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
vangel76
2026-10-11 18:49:54 +02:00
co-authored by Claude Sonnet 5.5
parent 67434e9038
commit 74b95b0a9d
9 changed files with 232 additions and 5 deletions
+49 -3
View File
@@ -206,6 +206,9 @@ struct Inner {
/// audio is read from the decoder instead of trying again on every read.
#[cfg_attr(target_arch = "wasm32", allow(dead_code))]
conform_failed: Mutex<HashSet<std::path::PathBuf>>,
/// Movies that failed to open or decode (path to a readable reason; see
/// [`FootageSource::problem`]). The first failure of a file is logged, later ones are not.
problems: Mutex<HashMap<Arc<str>, String>>,
}
/// Decodes footage for the renderer: stills, image sequences and movies (FilmCraft codecs), plus
@@ -273,6 +276,7 @@ impl MediaPool {
conform: Mutex::default(),
conforming: Mutex::default(),
conform_failed: Mutex::default(),
problems: Mutex::default(),
}),
}
}
@@ -320,6 +324,7 @@ impl MediaPool {
pub fn clear(&self) {
self.clear_frames();
lock(&self.inner.sources).clear();
lock(&self.inner.problems).clear();
}
/// Forget a file (after it changed on disk, or to retry a file that failed to open).
@@ -327,6 +332,7 @@ impl MediaPool {
lock(&self.inner.sources).remove(path);
lock(&self.inner.models).remove(path);
lock(&self.inner.gifs).remove(path);
lock(&self.inner.problems).remove(path);
let mut c = lock(&self.inner.cache);
let keys: Vec<Key> = c.lru.map.keys().filter(|k| &*k.path == path).cloned().collect();
for k in keys {
@@ -355,8 +361,11 @@ impl MediaPool {
}
match Inner::frame_at(&self.inner, footage, t, true, size) {
Ok(img) => Some(img),
// (a movie's failure is logged once per file, when it is recorded)
Err(e) => {
log::warn!("media: frame of {} at {:?}: {e}", footage.path, t);
if lock(&self.inner.problems).get(footage.path.as_str()).is_none() {
log::warn!("media: frame of {} at {:?}: {e}", footage.path, t);
}
None
}
}
@@ -582,7 +591,7 @@ impl Inner {
match opened {
Ok(s) => Some(s),
Err(e) => {
log::warn!("media: cannot open {path}: {e}");
self.note_problem(path, "", &e);
None
}
}
@@ -590,6 +599,19 @@ impl Inner {
.clone()
}
/// Remember why the movie at `path` cannot be shown (`codec` is the footage's, when known)
/// and log it the first time. I/O errors (missing or unreadable file) are not decoder
/// problems and are left to the missing-footage handling.
fn note_problem(&self, path: &Arc<str>, codec: &str, e: &MediaError) {
if matches!(e, MediaError::Io(_)) {
return;
}
let reason = describe_problem(codec, e);
if lock(&self.problems).insert(path.clone(), reason.clone()).is_none() {
log::warn!("media: {path}: {reason}");
}
}
/// The decoded frames of the animated GIF at `path`. The first caller decodes it, outside the
/// map's lock; callers asking for the same file meanwhile wait for that.
fn gif(&self, path: &Arc<str>) -> Result<Arc<Anim>> {
@@ -752,7 +774,10 @@ impl Inner {
}
Some(mt) => {
let src = self.source(path).ok_or_else(|| MediaError::Io(format!("{path}: cannot open")))?;
let vf = src.video_frame(FrameRequest::full(filmcraft_time::Tick(mt.0))).map_err(MediaError::from)?;
let vf = src
.video_frame(FrameRequest::full(filmcraft_time::Tick(mt.0)))
.map_err(MediaError::from)
.inspect_err(|e| self.note_problem(path, &footage.codec, e))?;
// A reduced-resolution render's frame, made at its size (a frame of the footage's
// own size only, as the renderer resamples only those).
let (w, h) = loc.key.size;
@@ -798,6 +823,13 @@ impl FootageSource for MediaPool {
self.frame_sized(item, footage, t, Some((width, height)))
}
fn problem(&self, footage: &Footage) -> Option<String> {
if footage.missing || footage.kind != FootageKind::Video {
return None;
}
lock(&self.inner.problems).get(footage.path.as_str()).cloned()
}
fn vector_frame(&self, _item: ItemId, footage: &Footage, scale: f64) -> Option<Arc<Image>> {
if footage.missing || !effectcraft_render::is_vector_footage(footage) {
return None;
@@ -845,6 +877,20 @@ fn read_stereo(src: &SharedSource, s0: i64, frames: usize, rate: u32) -> std::re
Ok(out)
}
/// The one-line reason a movie shows no picture: its `codec` (the probe's, e.g. "H.264 (High
/// 4:2:2)") and what the decoder said, without the error wrappers it passed through.
fn describe_problem(codec: &str, e: &MediaError) -> String {
let (MediaError::Io(s) | MediaError::Unsupported(s) | MediaError::Decode(s)) = e;
let mut detail = s.as_str();
let mut unsupported = matches!(e, MediaError::Unsupported(_));
while let Some(rest) = ["decode error: ", "unsupported media: ", "unsupported: ", "I/O error: "].iter().find_map(|p| detail.strip_prefix(p)) {
unsupported |= detail.starts_with("unsupported");
detail = rest;
}
let what = if codec.is_empty() { "This video" } else { codec };
if unsupported { format!("{what} isn't supported by the built-in decoder: {detail}") } else { format!("{what} can't be decoded: {detail}") }
}
fn lock<T>(m: &Mutex<T>) -> std::sync::MutexGuard<'_, T> {
m.lock().unwrap_or_else(|e| e.into_inner())
}