mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-28 09:09:39 +01:00
Merge pull request #4121 from storytold/fix/media-unsupported-video-errors
fix(media): keep the shared decoder's unsupported-video errors
This commit is contained in:
2 files changed
+70
-7
No files matched your search
@@ -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;
|
||||
@@ -2864,6 +2870,15 @@ mod raw_avi_tests;
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// A decoder's "unsupported" stays unsupported; anything else is a decode failure.
|
||||
#[test]
|
||||
fn video_decode_errors_keep_unsupported_apart() {
|
||||
assert!(matches!(video_decode_error(VideoError::Unsupported("H.264: 4:2:2".into())), MediaError::Unsupported(s) if s == "H.264: 4:2:2"));
|
||||
assert!(
|
||||
matches!(video_decode_error(VideoError::Malformed("VP9: bad header".into())), MediaError::Decode(s) if s == "malformed video: VP9: bad header")
|
||||
);
|
||||
}
|
||||
|
||||
// One 20 ms mono packet from craft-audio's generated tone.opus test fixture.
|
||||
// Re-mux it into ordinary small audio-only files without an external encoder.
|
||||
const OPUS_TONE: &[u8] = b"\x78\x82\x01\xB7\x6C\x7E\x40\xE6\x00\x00\x0A\xBE\x9A\xA7\xBE\xFF\xB6\x85\xD7\x0A\x71\xE0\xDD\
|
||||
|
||||
@@ -2108,10 +2108,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}") }
|
||||
}
|
||||
@@ -2402,6 +2422,34 @@ mod tests {
|
||||
assert_eq!(c.bytes, (16 * 16 * 16 + 64) + (16 * 16 * 4 + 64));
|
||||
}
|
||||
|
||||
/// The shared decoder's real messages read without their wrappers or the H.264 syntax-field
|
||||
/// number, and stay "unsupported" or "can't be decoded" as the decoder said.
|
||||
#[test]
|
||||
fn describe_problem_unwraps_shared_decoder_errors() {
|
||||
let unsupported = |s: &str| MediaError::Unsupported(s.into());
|
||||
assert_eq!(
|
||||
describe_problem("H.264", &unsupported("H.264: unsupported: chroma_format_idc 2 (only 4:2:0 is implemented)")),
|
||||
"H.264 isn't supported by the built-in decoder: 4:2:2 chroma (only 4:2:0 is implemented)"
|
||||
);
|
||||
assert_eq!(
|
||||
describe_problem("H.264", &unsupported("H.264: chroma_format_idc 0 stream")),
|
||||
"H.264 isn't supported by the built-in decoder: monochrome stream"
|
||||
);
|
||||
assert_eq!(describe_problem("H.264", &unsupported("chroma_format_idc 3 stream")), "H.264 isn't supported by the built-in decoder: 4:4:4 chroma stream");
|
||||
// The relabel is H.264's own field: another codec keeps the text.
|
||||
assert_eq!(
|
||||
describe_problem("HEVC", &unsupported("chroma_format_idc 2 stream")),
|
||||
"HEVC isn't supported by the built-in decoder: chroma_format_idc 2 stream"
|
||||
);
|
||||
// A wrapped "unsupported" inside a decode error still counts as unsupported.
|
||||
assert_eq!(
|
||||
describe_problem("VP9", &MediaError::Decode("decode error: unsupported video: VP9: profile 3".into())),
|
||||
"VP9 isn't supported by the built-in decoder: profile 3"
|
||||
);
|
||||
assert_eq!(describe_problem("VP9", &MediaError::Decode("malformed video: VP9: bad frame header".into())), "VP9 can't be decoded: bad frame header");
|
||||
assert_eq!(describe_problem("", &MediaError::Decode("malformed video: truncated".into())), "This video can't be decoded: truncated");
|
||||
}
|
||||
|
||||
/// #482: an OpenEXR file with HTJ2K compression (which the decoder lacks) says so on import
|
||||
/// and when its frame is read, instead of "no non-deep rgb channels" or a transparent frame.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user