diff --git a/crates/media/src/craft_source.rs b/crates/media/src/craft_source.rs index 4459ac129..1bf733128 100644 --- a/crates/media/src/craft_source.rs +++ b/crates/media/src/craft_source.rs @@ -1674,6 +1674,13 @@ fn decode_track_packet( Ok(vec![frame]) } +fn video_decode_error(error: VideoError) -> MediaError { + match error { + VideoError::Unsupported(detail) => MediaError::Unsupported(detail), + other => MediaError::Decode(other.to_string()), + } +} + struct AudioTrackState { decoder: AudioTrackDecoder, audio_starts: AudioStarts, @@ -1842,7 +1849,7 @@ impl MediaSource for CraftMediaSource { // Backward seek, jump to a later GOP, or draft/full-quality mode switch: reset decoder to // the target sync sample so full-quality frames never reuse draft-decoded references. if draft_changed || target_idx < state.next_decode_idx || sync_idx > state.gop_start_idx { - state.decoder.reset().map_err(|e| MediaError::Decode(e.to_string()))?; + state.decoder.reset().map_err(video_decode_error)?; state.decoded.clear(); state.next_decode_idx = sync_idx; state.gop_start_idx = sync_idx; @@ -1859,12 +1866,11 @@ impl MediaSource for CraftMediaSource { let idx = state.next_decode_idx; let pts = self.file.sample_pts(video_idx, idx); let pkt = self.file.read_sample(&*self.source, video_idx, idx)?; - let frames = - decode_track_packet(&mut state.decoder, is_isobmff, &pkt, pts, prores::decode_frame_with).map_err(|e| MediaError::Decode(e.to_string()))?; + let frames = decode_track_packet(&mut state.decoder, is_isobmff, &pkt, pts, prores::decode_frame_with).map_err(video_decode_error)?; state.next_decode_idx = idx + 1; push_decoded(&mut state.decoded, frames, want_draft, self.presentation, &self.file, video_idx)?; } else if !state.flushed { - let frames = state.decoder.flush().map_err(|e| MediaError::Decode(e.to_string()))?; + let frames = state.decoder.flush().map_err(video_decode_error)?; state.flushed = true; push_decoded(&mut state.decoded, frames, want_draft, self.presentation, &self.file, video_idx)?; break; diff --git a/crates/media/src/pool.rs b/crates/media/src/pool.rs index 041b235db..92c7031f5 100644 --- a/crates/media/src/pool.rs +++ b/crates/media/src/pool.rs @@ -2029,10 +2029,30 @@ fn describe_problem(codec: &str, e: &MediaError) -> String { MediaError::Cancelled => "the decode was called off", }; 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; + loop { + if let Some(rest) = ["decode error: ", "unsupported media: ", "unsupported video: ", "malformed video: ", "unsupported: ", "I/O error: "] + .iter() + .find_map(|p| detail.strip_prefix(p)) + { + unsupported |= detail.starts_with("unsupported"); + detail = rest; + } else if !codec.is_empty() + && let Some(rest) = detail.strip_prefix(codec).and_then(|s| s.strip_prefix(": ")) + { + detail = rest; + } else { + break; + } } + // Present the stream's chroma sampling, not the shared decoder's H.264 syntax-field number. + let detail = if codec == "H.264" { + [("chroma_format_idc 0 ", "monochrome "), ("chroma_format_idc 2 ", "4:2:2 chroma "), ("chroma_format_idc 3 ", "4:4:4 chroma ")] + .into_iter() + .find_map(|(syntax, label)| detail.strip_prefix(syntax).map(|rest| format!("{label}{rest}"))) + .unwrap_or_else(|| detail.to_owned()) + } else { + detail.to_owned() + }; 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}") } }