mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 20:58:01 +00:00
* craft-media: read and write the QuickTime logs box A video sample entry's `logs` child holds the CoreMedia log transfer-function identifier (`com.apple.rec2020.apple-log` for Apple Log). It is kept as `VideoParams::log_transfer_function`, whatever curve it names. The reader takes non-empty UTF-8 without NUL of at most 255 bytes; anything else, or a second `logs` box, reads as unknown. The writer refuses an identifier the reader would not accept. Ported from storytold/filmcraft#1764. * craft-media: the Matroska muxer writes a video track's Colour element `TrackSpec::color` takes the reader's `Color` and the muxer writes the fields that are set: matrix, range, transfer, primaries, chroma layout, light levels and mastering metadata (RFC 9559). VP9's own colour syntax carries only the matrix and range, so without the element a Rec. 2020, P3, PQ or HLG WebM reads as BT.709. Ported from storytold/effectcraft#2926, which wrote the element by hand in EffectCraft's WebM export. * craft-media: the laced remux test laces ffmpeg's Vorbis fixture again ffmpeg's Vorbis files declare a short DefaultDuration and store longer durations per block, so with the track's own default nothing laced and the test failed ("vorbis.mkv Xiph: nothing was laced", ffmpeg 9.0.2). Audio tracks now take their median packet duration as the default, and frames are written with their explicit durations, so a short last packet ends its lace. Ported from storytold/filmcraft#3622 (test-only part). --------- Co-authored-by: 20Coder <51251284+BitL8-ByteShort@users.noreply.github.com> Co-authored-by: JonRC <jonarc06@gmail.com> Co-authored-by: Michael Butler <michaelbutler75@gmail.com>
421 lines
19 KiB
Rust
421 lines
19 KiB
Rust
//! Oracle tests: compare our demuxer's packets, timestamps, keyframes and track parameters with
|
|
//! ffprobe on ffmpeg-generated fixtures (skipped when ffmpeg/ffprobe are not installed).
|
|
|
|
mod common;
|
|
#[path = "common/matroska.rs"]
|
|
mod mkv;
|
|
|
|
use craft_media::matroska::*;
|
|
use mkv::*;
|
|
use serde_json::Value;
|
|
use std::path::Path;
|
|
|
|
fn assert_streams_match(json: &Value, file: &MkvFile, name: &str) {
|
|
let streams = json["streams"].as_array().unwrap();
|
|
assert_eq!(streams.len(), file.tracks.len(), "{name}: stream count");
|
|
for (index, stream) in streams.iter().enumerate() {
|
|
let track = &file.tracks[index];
|
|
assert_eq!(stream["codec_name"].as_str().unwrap_or(""), track.codec.name(), "{name}: track {index} codec ({})", track.codec_id);
|
|
assert_eq!(stream["time_base"].as_str(), Some(format!("{}/{}", track.timebase.0, track.timebase.1).as_str()), "{name}: time_base");
|
|
match track.kind {
|
|
TrackKind::Video => {
|
|
let video = track.video.as_ref().unwrap();
|
|
assert_eq!(int(&stream["width"]), Some(video.pixel_width as i64), "{name}: width");
|
|
assert_eq!(int(&stream["height"]), Some(video.pixel_height as i64), "{name}: height");
|
|
}
|
|
TrackKind::Audio => {
|
|
let audio = track.audio.as_ref().unwrap();
|
|
assert_eq!(int(&stream["sample_rate"]), Some(audio.sampling_frequency as i64), "{name}: sample_rate");
|
|
assert_eq!(int(&stream["channels"]), Some(audio.channels as i64), "{name}: channels");
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|
|
}
|
|
|
|
fn assert_packets_match(json: &Value, file: &MkvFile, packets: &[Packet], name: &str) {
|
|
let ffprobe_packets = json["packets"].as_array().unwrap();
|
|
assert_eq!(packets.len(), ffprobe_packets.len(), "{name}: packet count");
|
|
let (mut pts_checked, mut duration_checked) = (0, 0);
|
|
for (index, (packet, ffprobe_packet)) in packets.iter().zip(ffprobe_packets).enumerate() {
|
|
let context = format!("{name}: packet {index} (track {})", packet.track);
|
|
assert_eq!(int(&ffprobe_packet["stream_index"]), Some(packet.track as i64), "{context}: stream");
|
|
if file.tracks[packet.track].codec_id.starts_with("D_WEBVTT") {
|
|
// WebM WebVTT blocks carry "id\nsettings\npayload"; FFmpeg moves id/settings to side data.
|
|
assert!(packet.data.len() as i64 >= int(&ffprobe_packet["size"]).unwrap(), "{context}: size");
|
|
} else {
|
|
assert_eq!(int(&ffprobe_packet["size"]), Some(packet.data.len() as i64), "{context}: size");
|
|
}
|
|
assert_eq!(ffprobe_packet["flags"].as_str().unwrap_or("").starts_with('K'), packet.keyframe, "{context}: keyframe");
|
|
compare_packet_pts(ffprobe_packet, packet, &context, &mut pts_checked);
|
|
compare_packet_duration(ffprobe_packet, packet, packets, file, &context, index, &mut duration_checked);
|
|
}
|
|
assert!(pts_checked > 0, "{name}: no pts compared");
|
|
eprintln!("{name}: {} packets, {pts_checked} pts and {duration_checked} durations compared", packets.len());
|
|
}
|
|
|
|
fn compare_packet_pts(ffprobe_packet: &Value, packet: &Packet, context: &str, checked: &mut usize) {
|
|
if let Some(pts) = int(&ffprobe_packet["pts"])
|
|
&& !(packet.lace > 0 && packet.duration == 0)
|
|
{
|
|
// FFmpeg truncates per-lace duration to whole ticks; later laces can differ by one tick each.
|
|
assert!((pts - packet.pts).abs() <= packet.lace as i64, "{context}: pts ffprobe {pts} vs {}", packet.pts);
|
|
*checked += 1;
|
|
}
|
|
}
|
|
|
|
fn compare_packet_duration(
|
|
ffprobe_packet: &Value,
|
|
packet: &Packet,
|
|
packets: &[Packet],
|
|
file: &MkvFile,
|
|
context: &str,
|
|
index: usize,
|
|
checked: &mut usize,
|
|
) {
|
|
// The final audio/video frame cut by `-t` has a shortened BlockDuration, but ffprobe reports
|
|
// the codec frame duration. Subtitle durations remain exact cue intervals and are compared.
|
|
let last_of_track = packets[index + 1..].iter().all(|next| next.track != packet.track);
|
|
if let Some(duration) = int(&ffprobe_packet["duration"])
|
|
&& packet.duration != 0
|
|
&& (!last_of_track || file.tracks[packet.track].kind == TrackKind::Subtitle)
|
|
{
|
|
assert!((duration - packet.duration as i64).abs() <= 1, "{context}: duration ffprobe {duration} vs {}", packet.duration);
|
|
*checked += 1;
|
|
}
|
|
}
|
|
|
|
fn assert_packet_index_matches(file: &MkvFile, packets: &[Packet], bytes: &[u8], name: &str) {
|
|
for (track_index, track) in file.tracks.iter().enumerate() {
|
|
let track_packets: Vec<&Packet> = packets.iter().filter(|packet| packet.track == track_index).collect();
|
|
assert_eq!(track.samples.len(), track_packets.len(), "{name}: index size track {track_index}");
|
|
for (sample_index, packet) in track_packets.iter().enumerate() {
|
|
assert_eq!(track.samples[sample_index].pts, packet.pts);
|
|
assert_eq!(track.samples[sample_index].keyframe, packet.keyframe);
|
|
assert_eq!(track.sample_size(sample_index), Some(packet.data.len() as u64));
|
|
}
|
|
if let Some(sample_index) = track_packets.len().checked_sub(1) {
|
|
assert_eq!(file.read_sample(bytes, track_index, sample_index).unwrap(), track_packets[sample_index].data);
|
|
}
|
|
}
|
|
}
|
|
|
|
fn assert_duration_matches(json: &Value, file: &MkvFile, name: &str) {
|
|
if let Some(ffprobe_duration) = json["format"]["duration"].as_str().and_then(|duration| duration.parse::<f64>().ok())
|
|
&& let Some(duration_ns) = file.duration_ns()
|
|
{
|
|
assert!((ffprobe_duration - duration_ns as f64 / 1e9).abs() < 0.05, "{name}: duration {ffprobe_duration} vs {duration_ns}");
|
|
}
|
|
}
|
|
|
|
/// Compare every packet (file order) and stream parameter against ffprobe.
|
|
fn compare(ffprobe: &Path, path: &Path) -> (MkvFile, Vec<Packet>) {
|
|
let json = ffprobe_json(ffprobe, path);
|
|
let bytes = std::fs::read(path).unwrap();
|
|
let mut demuxer = Demuxer::from_slice(&bytes).unwrap();
|
|
let name = path.file_name().unwrap().to_string_lossy().to_string();
|
|
let file = demuxer.file().clone();
|
|
assert_streams_match(&json, &file, &name);
|
|
let packets: Vec<Packet> = demuxer.by_ref().collect::<Result<_>>().unwrap();
|
|
assert_packets_match(&json, &file, &packets, &name);
|
|
assert_packet_index_matches(&file, &packets, &bytes, &name);
|
|
assert_duration_matches(&json, &file, &name);
|
|
(file, packets)
|
|
}
|
|
|
|
/// Seek to a range of times on `track` and check we land on the latest keyframe ≤ target.
|
|
fn check_seeks(bytes: &[u8], opts: OpenOptions, track: usize, packets: &[Packet]) {
|
|
let mut d = Demuxer::with_options(bytes, opts).unwrap();
|
|
let keys: Vec<(i64, i64)> = packets.iter().filter(|p| p.track == track && p.keyframe).map(|p| (p.pts, p.pts_ns)).collect();
|
|
let last = packets.iter().filter(|p| p.track == track).map(|p| p.pts_ns).max().unwrap();
|
|
let mut t = 0i64;
|
|
while t <= last + 100_000_000 {
|
|
let sp = d.seek(track, t).unwrap();
|
|
let expect = keys.iter().filter(|k| k.1 <= t).map(|k| k.0).max().unwrap_or(keys[0].0);
|
|
assert_eq!(sp.pts, expect, "seek to {t}ns");
|
|
assert!(sp.pts_ns <= t || sp.pts == keys[0].0);
|
|
// the first packet of that track after seeking is the keyframe
|
|
let p = loop {
|
|
let p = d.next_packet().unwrap().expect("packet after seek");
|
|
if p.track == track {
|
|
break p;
|
|
}
|
|
};
|
|
assert!(p.keyframe);
|
|
assert_eq!(p.pts, sp.pts);
|
|
t += 137_000_000;
|
|
}
|
|
}
|
|
|
|
fn run(name: &str) -> Option<(Vec<u8>, MkvFile, Vec<Packet>)> {
|
|
let (ffmpeg, ffprobe) = tools()?;
|
|
let path = fixture(&ffmpeg, name)?;
|
|
let (file, packets) = compare(&ffprobe, &path);
|
|
let bytes = std::fs::read(&path).unwrap();
|
|
Some((bytes, file, packets))
|
|
}
|
|
|
|
#[test]
|
|
fn h264_aac() {
|
|
let Some((bytes, f, packets)) = run("h264_aac.mkv") else { return };
|
|
assert_eq!(f.doc_type, "matroska");
|
|
assert!(f.warnings.is_empty(), "{:?}", f.warnings);
|
|
let v = f.track_of_kind(TrackKind::Video).unwrap();
|
|
let Codec::Avc { avcc } = &f.tracks[v].codec else { panic!("not avc") };
|
|
assert_eq!(avcc[0], 1, "avcC version");
|
|
let a = f.track_of_kind(TrackKind::Audio).unwrap();
|
|
assert!(matches!(&f.tracks[a].codec, Codec::Aac { asc } if asc.len() >= 2));
|
|
assert!(!f.cues.is_empty());
|
|
assert!(!f.seek_head.is_empty());
|
|
check_seeks(&bytes, OpenOptions::default(), v, &packets);
|
|
check_seeks(&bytes, OpenOptions { index: false, verify_crc: false, index_limit: None }, v, &packets);
|
|
check_seeks(&bytes, OpenOptions::default(), a, &packets);
|
|
// Read + Seek entry point and CRC verification (ffmpeg writes CRC-32 in level-1 elements)
|
|
let d = Demuxer::from_reader(std::io::Cursor::new(bytes.clone())).unwrap();
|
|
assert_eq!(d.file().tracks.len(), 2);
|
|
let crc = open_with(&bytes[..], &OpenOptions { index: true, verify_crc: true, index_limit: None }).unwrap();
|
|
assert!(crc.crc_checked > 0);
|
|
assert!(crc.crc_errors.is_empty());
|
|
let kf = Demuxer::from_slice(&bytes).unwrap().keyframe_index(v).unwrap();
|
|
assert_eq!(kf.len(), packets.iter().filter(|p| p.track == v && p.keyframe).count());
|
|
}
|
|
|
|
#[test]
|
|
fn vp9_opus_webm() {
|
|
let Some((bytes, f, packets)) = run("vp9_opus.webm") else { return };
|
|
assert!(f.is_webm());
|
|
let a = f.track_of_kind(TrackKind::Audio).unwrap();
|
|
let t = &f.tracks[a];
|
|
assert!(matches!(&t.codec, Codec::Opus { head } if head.starts_with(b"OpusHead")));
|
|
assert!(t.codec_delay_ns > 0 && t.seek_pre_roll_ns > 0);
|
|
assert!(packets.iter().any(|p| p.track == a && p.pts < 0), "codec delay applied");
|
|
let v = f.track_of_kind(TrackKind::Video).unwrap();
|
|
assert!(matches!(f.tracks[v].codec, Codec::Vp9 { .. }));
|
|
check_seeks(&bytes, OpenOptions::default(), v, &packets);
|
|
check_seeks(&bytes, OpenOptions { index: false, verify_crc: false, index_limit: None }, v, &packets);
|
|
}
|
|
|
|
#[test]
|
|
fn flac() {
|
|
let Some((_, f, _)) = run("flac.mkv") else { return };
|
|
assert!(matches!(&f.tracks[0].codec, Codec::Flac { private } if private.starts_with(b"fLaC")));
|
|
}
|
|
|
|
#[test]
|
|
fn vorbis() {
|
|
let Some((_, f, _)) = run("vorbis.mkv") else { return };
|
|
let Codec::Vorbis { headers } = &f.tracks[0].codec else { panic!("not vorbis") };
|
|
assert_eq!(headers.len(), 3);
|
|
assert_eq!(&headers[0][..7], b"\x01vorbis");
|
|
assert_eq!(&headers[1][..7], b"\x03vorbis");
|
|
assert_eq!(&headers[2][..7], b"\x05vorbis");
|
|
}
|
|
|
|
#[test]
|
|
fn subtitles() {
|
|
let Some((_, f, packets)) = run("subs.mkv") else { return };
|
|
let subs: Vec<usize> = (0..f.tracks.len()).filter(|&i| f.tracks[i].kind == TrackKind::Subtitle).collect();
|
|
assert_eq!(subs.len(), 2);
|
|
assert_eq!(f.tracks[subs[0]].codec, Codec::SubRip);
|
|
assert_eq!(f.tracks[subs[0]].language, "fre");
|
|
assert!(matches!(&f.tracks[subs[1]].codec, Codec::Ass { header, ssa: false } if !header.is_empty()));
|
|
assert_eq!(f.tracks[subs[1]].name, "Styled");
|
|
let first = packets.iter().find(|p| p.track == subs[0]).unwrap();
|
|
assert_eq!(first.data, b"Hello");
|
|
assert_eq!((first.pts, first.duration), (200, 700));
|
|
}
|
|
|
|
#[test]
|
|
fn webvtt_webm() {
|
|
let Some((_, f, packets)) = run("webvtt.webm") else { return };
|
|
let s = f.track_of_kind(TrackKind::Subtitle).unwrap();
|
|
assert_eq!(f.tracks[s].codec, Codec::WebVtt);
|
|
let cues: Vec<&Packet> = packets.iter().filter(|p| p.track == s).collect();
|
|
assert_eq!(cues.len(), 2);
|
|
assert!(cues[0].data.ends_with(b"Hello"));
|
|
}
|
|
|
|
#[test]
|
|
fn cues_at_front() {
|
|
let Some((bytes, f, packets)) = run("cues_front.mkv") else { return };
|
|
assert!(!f.cues.is_empty());
|
|
assert!(f.clusters.len() >= 5);
|
|
let v = f.track_of_kind(TrackKind::Video).unwrap();
|
|
check_seeks(&bytes, OpenOptions { index: false, verify_crc: false, index_limit: None }, v, &packets);
|
|
}
|
|
|
|
#[test]
|
|
fn live_stream_without_cues() {
|
|
let Some((bytes, f, packets)) = run("live.mkv") else { return };
|
|
assert!(f.cues.is_empty(), "streamed output has no Cues");
|
|
assert!(f.live || f.info.duration.is_none());
|
|
assert!(f.duration_ns().unwrap() > 1_900_000_000);
|
|
let v = f.track_of_kind(TrackKind::Video).unwrap();
|
|
// no cues: seeking builds the index by scanning clusters
|
|
check_seeks(&bytes, OpenOptions { index: false, verify_crc: false, index_limit: None }, v, &packets);
|
|
let mut d = Demuxer::with_options(&bytes[..], OpenOptions { index: false, verify_crc: false, index_limit: None }).unwrap();
|
|
assert!(!d.file().indexed);
|
|
assert!(!d.keyframe_index(v).unwrap().is_empty());
|
|
assert!(d.file().indexed);
|
|
}
|
|
|
|
#[test]
|
|
fn hevc_hdr_color() {
|
|
let Some((_, f, _)) = run("hevc_hdr.mkv") else { return };
|
|
let t = &f.tracks[0];
|
|
assert!(matches!(&t.codec, Codec::Hevc { hvcc } if hvcc.first() == Some(&1)));
|
|
let c = t.video.as_ref().unwrap().color.as_ref().expect("Colour element");
|
|
assert_eq!(c.primaries, Some(9));
|
|
assert_eq!(c.transfer_characteristics, Some(16));
|
|
assert_eq!(c.matrix_coefficients, Some(9));
|
|
assert_eq!(c.range, Some(1));
|
|
// mastering metadata / CLL are written by ffmpeg from stream side data when available
|
|
if let Some(m) = &c.mastering {
|
|
assert!((m.primaries[1].0 - 0.265).abs() < 1e-3, "{m:?}");
|
|
assert!((m.luminance_max - 1000.0).abs() < 1e-3);
|
|
}
|
|
if let Some(cll) = c.max_cll {
|
|
assert_eq!(cll, 1000);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn prores_pcm() {
|
|
let Some((_, f, _)) = run("prores_pcm.mkv") else { return };
|
|
let a = f.track_of_kind(TrackKind::Audio).unwrap();
|
|
assert_eq!(f.tracks[a].codec, Codec::Pcm { float: false, big_endian: false, bits: 24 });
|
|
}
|
|
|
|
#[test]
|
|
fn mjpeg_ac3() {
|
|
let Some((_, f, _)) = run("mjpeg_ac3.mkv") else { return };
|
|
assert_eq!(f.info.title.as_deref(), Some("craft-media test"));
|
|
assert!(f.info.muxing_app.starts_with("Lavf"));
|
|
assert!(f.tags.iter().flat_map(|t| &t.simple).any(|s| s.name == "ENCODER"));
|
|
}
|
|
|
|
#[test]
|
|
fn av1() {
|
|
let Some((_, f, _)) = run("av1.mkv") else { return };
|
|
assert!(matches!(&f.tracks[0].codec, Codec::Av1 { av1c } if av1c.first() == Some(&0x81)));
|
|
}
|
|
|
|
/// Re-mux a fixture with our writer using each lacing mode; ffprobe must read the result identically
|
|
/// to our demuxer (and to the source packets).
|
|
#[test]
|
|
fn laced_remux() {
|
|
let Some((ffmpeg, ffprobe)) = tools() else { return };
|
|
for (src, modes) in [
|
|
("vorbis.mkv", &[LacingMode::Xiph, LacingMode::Ebml][..]),
|
|
("h264_aac.mkv", &[LacingMode::Ebml, LacingMode::Xiph][..]),
|
|
("prores_pcm.mkv", &[LacingMode::FixedOrEbml][..]),
|
|
("flac.mkv", &[LacingMode::Ebml][..]),
|
|
] {
|
|
let Some(path) = fixture(&ffmpeg, src) else { continue };
|
|
let bytes = std::fs::read(&path).unwrap();
|
|
let d = Demuxer::from_slice(&bytes).unwrap();
|
|
let file = d.file().clone();
|
|
let packets: Vec<Packet> = d.collect::<Result<_>>().unwrap();
|
|
for &mode in modes {
|
|
let specs: Vec<TrackSpec> = file
|
|
.tracks
|
|
.iter()
|
|
.enumerate()
|
|
.map(|(ti, t)| {
|
|
let mut s = TrackSpec::new(t.kind, t.codec_id.clone());
|
|
s.codec_private = t.codec_private.clone();
|
|
// BlockDuration overrides DefaultDuration: ffmpeg's Vorbis files declare a short
|
|
// default and store longer durations per block. Audio takes its median packet
|
|
// duration (the packet spacing when no packet has one), so its frames can lace.
|
|
s.default_duration_ns = if t.kind == TrackKind::Audio {
|
|
let audio: Vec<&Packet> = packets.iter().filter(|p| p.track == ti).collect();
|
|
let mut durations: Vec<u64> = audio.iter().map(|p| p.duration_ns).filter(|&d| d > 0).collect();
|
|
if durations.is_empty() {
|
|
durations = audio.windows(2).filter_map(|w| u64::try_from(w[1].pts_ns - w[0].pts_ns).ok()).filter(|&d| d > 0).collect();
|
|
}
|
|
durations.sort_unstable();
|
|
durations.get(durations.len() / 2).copied().or(t.default_duration_ns)
|
|
} else {
|
|
t.default_duration_ns
|
|
};
|
|
s.video_size = t.video.as_ref().map(|v| (v.pixel_width, v.pixel_height));
|
|
s.audio = t.audio.as_ref().map(|a| (a.sampling_frequency, a.channels, a.bit_depth));
|
|
s.codec_delay_ns = t.codec_delay_ns;
|
|
s
|
|
})
|
|
.collect();
|
|
let opts = MuxOptions { lacing: mode, ..Default::default() };
|
|
let mut w = MkvWriter::new(std::io::Cursor::new(Vec::new()), specs, opts).unwrap();
|
|
for p in &packets {
|
|
// Keep explicit durations, a short last packet's too: one that differs from the
|
|
// track's default ends the lace.
|
|
w.write_frame(p.track, p.pts_ns, p.keyframe, &p.data, (p.duration_ns > 0).then_some(p.duration_ns)).unwrap();
|
|
}
|
|
let out = w.finish().unwrap().into_inner();
|
|
let laced = {
|
|
let f = open(&out[..]).unwrap();
|
|
f.tracks.iter().any(|t| t.samples.iter().any(|s| s.lace > 0))
|
|
};
|
|
assert!(laced, "{src} {mode:?}: nothing was laced");
|
|
let outp = fixture_dir().join(format!("remux_{mode:?}_{src}"));
|
|
std::fs::write(&outp, &out).unwrap();
|
|
let (_, got) = compare(&ffprobe, &outp);
|
|
assert_eq!(got.len(), packets.len());
|
|
for (a, b) in got.iter().zip(&packets) {
|
|
assert_eq!(a.data, b.data, "{src} {mode:?}: payload");
|
|
assert_eq!((a.track, a.pts), (b.track, b.pts), "{src} {mode:?}: timestamp");
|
|
}
|
|
std::fs::remove_file(&outp).unwrap();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Damaged file: overwrite bytes in the middle of the clusters; the demuxer must not fail and must
|
|
/// resync on a later cluster.
|
|
#[test]
|
|
fn damaged_resync() {
|
|
let Some((mut bytes, f, packets)) = run("h264_aac.mkv") else { return };
|
|
let mid = f.clusters[f.clusters.len() / 2];
|
|
let at = mid.data_start as usize + 40;
|
|
for b in &mut bytes[at..at + 200] {
|
|
*b = 0x00;
|
|
}
|
|
let d = Demuxer::from_slice(&bytes).unwrap();
|
|
assert!(!d.file().warnings.is_empty());
|
|
let got: Vec<Packet> = d.collect::<Result<_>>().unwrap();
|
|
assert!(got.len() < packets.len());
|
|
assert!(got.len() > packets.len() / 2);
|
|
// packets after the damaged cluster are intact
|
|
let last = packets.last().unwrap();
|
|
assert_eq!(got.last().unwrap(), last);
|
|
// truncated file
|
|
let cut = &bytes[..bytes.len() * 2 / 3];
|
|
let d = Demuxer::from_slice(cut).unwrap();
|
|
let got: Vec<Packet> = d.collect::<Result<_>>().unwrap();
|
|
assert!(!got.is_empty());
|
|
// garbage never panics
|
|
for n in [0usize, 10, 100, 1000] {
|
|
let _ = Demuxer::from_slice(&bytes[..n.min(bytes.len())]).map(|d| d.count());
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn not_matroska() {
|
|
assert!(matches!(open(&b"hello world"[..]), Err(Error::NotMatroska(_))));
|
|
let mut ebml = vec![0x1A, 0x45, 0xDF, 0xA3, 0x84, 0x42, 0x82, 0x81, b'x'];
|
|
ebml.extend_from_slice(&[0; 8]);
|
|
assert!(matches!(open(&ebml[..]), Err(Error::NotMatroska(_))));
|
|
let _ = Value::Null;
|
|
}
|
|
|
|
/// Pre-generate every fixture (`cargo test -p craft-media --all-features -- --ignored generate_fixtures`).
|
|
#[test]
|
|
#[ignore]
|
|
fn generate_fixtures() {
|
|
let Some((ffmpeg, _)) = tools() else { return };
|
|
for name in ALL_FIXTURES {
|
|
let out = [fixture_dir().join(name)];
|
|
common::generate_and_report(&format!("matroska/{name}"), &out, || fixture(&ffmpeg, name));
|
|
}
|
|
}
|