forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

deinterlace_mode.rs515 lines, 21.4 KiBHistoryRawDownload
1//! A clip's deinterlace setting (`Frame`, `Field`, `Off`) on interlaced H.264:
2//! `Field` is ffmpeg's `bwdif=mode=send_field` (one picture per field, 50i -> 50p),
3//! `Off` leaves the woven pictures as decoded, `Frame` is what it always was, and a
4//! progressive source ignores all three. Exports and stills (`compose_at`) go
5//! through the public session; the decode layer (seeks, reverse) is covered by
6//! `deinterlace::session_tests`.
7//!
8//! Clips are synthetic (`testsrc2`, interlaced by ffmpeg's `interlace` filter and
9//! encoded by libx264 MBAFF into the temp dir); without ffmpeg and libx264 each
10//! test says so and passes. `VE_SW` is process-wide, so exports hold [`SW`].
11
12use std::path::{Path, PathBuf};
13use std::process::Command;
14use std::sync::Mutex;
15use std::time::{Duration, Instant};
16
17use ec_core::frame::{Frame as CoreFrame, Interlace};
18use ec_core::registry::{CodecId, CodecParameters, Decoder as _};
19use ec_core::{Packet, TimeBase, VideoFrame};
20use ec_h264::H264Decoder;
21use engine::PlaybackSession;
22use engine::deinterlace::Deinterlacer;
23use engine::demux::Demuxer;
24use engine::export::{ExportSettings, Format};
25use engine::project::{Deinterlace, Lane, Speed};
26
27const W: usize = 352;
28const H: usize = 288;
29/// Interlaced frames; the source has twice as many progressive moments.
30const FRAMES: u32 = 30;
31
32static SW: Mutex<()> = Mutex::new(());
33
34fn software<T>(f: impl FnOnce() -> T) -> T {
35 let _guard = SW.lock().unwrap_or_else(|poisoned| poisoned.into_inner());
36 engine::envcfg::set("VE_SW", "1");
37 let out = f();
38 engine::envcfg::unset("VE_SW");
39 out
40}
41
42fn have_x264() -> bool {
43 let tool = |t: &str, a: &str| Command::new(t).arg(a).output().is_ok_and(|o| o.status.success());
44 if !tool("ffmpeg", "-version") || !tool("ffprobe", "-version") {
45 return false;
46 }
47 Command::new("ffmpeg")
48 .args(["-hide_banner", "-encoders"])
49 .output()
50 .is_ok_and(|o| String::from_utf8_lossy(&o.stdout).contains("libx264"))
51}
52
53fn scratch(name: &str) -> PathBuf {
54 let dir = std::env::temp_dir().join(format!("edith-{name}-{}", std::process::id()));
55 let _ = std::fs::remove_dir_all(&dir);
56 std::fs::create_dir_all(&dir).expect("scratch directory");
57 dir
58}
59
60fn ffmpeg(args: &[&str]) {
61 let out = Command::new("ffmpeg").args(["-v", "error", "-y"]).args(args).output().expect("run ffmpeg");
62 assert!(out.status.success(), "ffmpeg {args:?}: {}", String::from_utf8_lossy(&out.stderr));
63}
64
65#[derive(Clone, Copy)]
66struct Look {
67 tff: bool,
68 deep: bool,
69 c422: bool,
70}
71
72impl Look {
73 fn pix(self) -> &'static str {
74 match (self.c422, self.deep) {
75 (false, false) => "yuv420p",
76 (false, true) => "yuv420p10le",
77 (true, false) => "yuv422p",
78 (true, true) => "yuv422p10le",
79 }
80 }
81
82 fn frame_bytes(self) -> usize {
83 W * H * if self.c422 { 2 } else { 3 } / if self.c422 { 1 } else { 2 } * if self.deep { 2 } else { 1 }
84 }
85
86 fn parity(self) -> &'static str {
87 if self.tff { "tff" } else { "bff" }
88 }
89}
90
91/// The progressive original, every one of its 60 moments (raw), and the interlaced
92/// clip `name`. Field `k` of the clip belongs to moment `k` whichever field leads.
93fn make(dir: &Path, name: &str, look: Look) -> (PathBuf, PathBuf) {
94 let src = dir.join(format!("{name}.src.y4m"));
95 ffmpeg(&[
96 "-f", "lavfi", "-i", "testsrc2=size=352x288:rate=50", "-frames:v", &(FRAMES * 2).to_string(), "-pix_fmt",
97 if look.c422 { "yuv422p" } else { "yuv420p" }, src.to_str().unwrap(),
98 ]);
99 let reference = dir.join(format!("{name}.ref.yuv"));
100 ffmpeg(&["-i", src.to_str().unwrap(), "-fps_mode", "passthrough", "-f", "rawvideo", "-pix_fmt", look.pix(), reference.to_str().unwrap()]);
101 let clip = dir.join(name);
102 let scan = look.parity();
103 let params = format!("interlaced=1:{scan}=1:keyint=10:min-keyint=10:bframes=2");
104 let profile = match (look.c422, look.deep) {
105 (true, _) => "high422",
106 (false, true) => "high10",
107 (false, false) => "high",
108 };
109 ffmpeg(&[
110 "-i", src.to_str().unwrap(), "-vf", &format!("interlace=scan={scan}"), "-c:v", "libx264", "-profile:v", profile, "-pix_fmt",
111 look.pix(), "-crf", "10", "-flags", "+ildct+ilme", "-x264-params", &params, clip.to_str().unwrap(),
112 ]);
113 (clip, reference)
114}
115
116fn progressive(dir: &Path, name: &str, fps: u32) -> PathBuf {
117 let clip = dir.join(name);
118 ffmpeg(&[
119 "-f", "lavfi", "-i", &format!("testsrc2=size=352x288:rate={fps}"), "-frames:v", "30", "-c:v", "libx264", "-x264-params",
120 "keyint=10:min-keyint=10:bframes=2", clip.to_str().unwrap(),
121 ]);
122 clip
123}
124
125fn woven(clip: &Path) -> Vec<VideoFrame> {
126 let (_, mut demuxer) = Demuxer::open(clip).expect("open");
127 demuxer.seek_to_sync_at_or_before(0);
128 let mut decoder = H264Decoder::new(CodecParameters::new(CodecId::H264)).expect("decoder");
129 let mut out = Vec::new();
130 let take = |decoder: &mut H264Decoder, out: &mut Vec<VideoFrame>| {
131 while let Ok(frame) = decoder.receive_frame() {
132 if let CoreFrame::Video(pic) = frame {
133 out.push(pic);
134 }
135 }
136 };
137 while let Some(au) = demuxer.next_access_unit().expect("demux") {
138 decoder.send_packet(&Packet::new(0, TimeBase::new(1, 1), au)).expect("decode");
139 take(&mut decoder, &mut out);
140 }
141 decoder.flush().expect("flush");
142 take(&mut decoder, &mut out);
143 out
144}
145
146fn raw(pics: &[VideoFrame]) -> Vec<u8> {
147 pics.iter().flat_map(|p| p.planes.iter().flat_map(|pl| pl.data.iter().copied())).collect()
148}
149
150fn ffmpeg_raw(args: &[&str], path: &Path, pix_fmt: &str) -> Vec<u8> {
151 let out = Command::new("ffmpeg")
152 .args(["-v", "error", "-i"])
153 .arg(path)
154 .args(args)
155 .args(["-an", "-fps_mode", "passthrough", "-f", "rawvideo", "-pix_fmt", pix_fmt, "-"])
156 .output()
157 .expect("ffmpeg runs");
158 assert!(out.status.success(), "ffmpeg: {}", String::from_utf8_lossy(&out.stderr));
159 out.stdout
160}
161
162fn psnr(a: &[u8], b: &[u8], deep: bool) -> f64 {
163 assert_eq!(a.len(), b.len(), "the same number of samples");
164 let (mut squared, n) = (0f64, if deep { a.len() / 2 } else { a.len() });
165 if deep {
166 for (x, y) in a.as_chunks::<2>().0.iter().zip(b.as_chunks::<2>().0) {
167 let d = f64::from(u16::from_le_bytes(*x)) - f64::from(u16::from_le_bytes(*y));
168 squared += d * d;
169 }
170 } else {
171 for (x, y) in a.iter().zip(b) {
172 let d = f64::from(*x) - f64::from(*y);
173 squared += d * d;
174 }
175 }
176 if squared == 0.0 {
177 return f64::INFINITY;
178 }
179 let peak = if deep { 1023.0f64 } else { 255.0 };
180 10.0 * (peak * peak * n as f64 / squared).log10()
181}
182
183/// Share of luma pixels that are an extreme against both vertical neighbours.
184fn combing(luma: &[u8]) -> f64 {
185 let mut hits = 0u64;
186 for y in 1..H - 1 {
187 for x in 0..W {
188 let (a, b, c) = (i32::from(luma[(y - 1) * W + x]), i32::from(luma[y * W + x]), i32::from(luma[(y + 1) * W + x]));
189 if ((b - a) > 20 && (b - c) > 20) || ((a - b) > 20 && (c - b) > 20) {
190 hits += 1;
191 }
192 }
193 }
194 hits as f64 / (W * (H - 2)) as f64
195}
196
197/// Mean combing of an 8-bit 4:2:0 raw run.
198fn combing_of(raw: &[u8]) -> f64 {
199 let frame = W * H * 3 / 2;
200 let n = raw.len() / frame;
201 raw.chunks(frame).map(|f| combing(&f[..W * H])).sum::<f64>() / n as f64
202}
203
204fn frames_of(raw: &[u8], look: Look) -> Vec<&[u8]> {
205 raw.chunks(look.frame_bytes()).collect()
206}
207
208const LOOKS: [(&str, Look); 4] = [
209 ("t8-tff.mp4", Look { tff: true, deep: false, c422: false }),
210 ("t8-bff.mkv", Look { tff: false, deep: false, c422: false }),
211 ("t10-tff.mp4", Look { tff: true, deep: true, c422: false }),
212 ("t422-bff.mkv", Look { tff: false, deep: false, c422: true }),
213];
214
215fn field_stage(pics: Vec<VideoFrame>) -> Vec<(i64, VideoFrame)> {
216 let mut stage = Deinterlacer::with_mode(Deinterlace::Field, true, 0, Interlace::Progressive);
217 let mut out = Vec::new();
218 for (i, pic) in pics.into_iter().enumerate() {
219 out.extend(stage.push_all(i as i64, pic));
220 }
221 out.extend(stage.finish_all());
222 out
223}
224
225fn frame_stage(pics: Vec<VideoFrame>) -> Vec<VideoFrame> {
226 let mut stage = Deinterlacer::new(true, 0, Interlace::Progressive);
227 let mut out = Vec::new();
228 for (i, pic) in pics.into_iter().enumerate() {
229 out.extend(stage.push(i as i64, pic).map(|(_, f)| f));
230 }
231 out.extend(stage.finish().map(|(_, f)| f));
232 out
233}
234
235/// The numbers: ours, ffmpeg's send_field, and the progressive moments, per clip.
236#[test]
237fn field_mode_is_bwdif_send_field() {
238 if !have_x264() {
239 eprintln!("no ffmpeg with libx264: skipping");
240 return;
241 }
242 let dir = scratch("dm-bwdif");
243 for (name, look) in LOOKS {
244 let (clip, reference) = make(&dir, name, look);
245 let want = std::fs::read(&reference).expect("reference");
246 let pics = woven(&clip);
247 let fields = field_stage(pics.clone());
248 assert_eq!(fields.len(), 2 * FRAMES as usize, "{name}: one picture per field");
249 assert_eq!(fields.iter().map(|f| f.0).collect::<Vec<_>>(), (0..2 * i64::from(FRAMES)).collect::<Vec<_>>(), "{name}");
250 let ours = raw(&fields.iter().map(|f| f.1.clone()).collect::<Vec<_>>());
251 let bwdif = ffmpeg_raw(&["-vf", &format!("bwdif=mode=send_field:parity={}:deint=all", look.parity())], &clip, look.pix());
252 assert_eq!(bwdif.len(), ours.len(), "{name}: ffmpeg's send_field has the same number of pictures");
253 let (po, pb, pd) = (psnr(&want, &ours, look.deep), psnr(&want, &bwdif, look.deep), psnr(&bwdif, &ours, look.deep));
254 // Per picture, to see whether the second field is as close as the first.
255 let (mut first, mut second) = (Vec::new(), Vec::new());
256 for (i, (a, b)) in frames_of(&ours, look).iter().zip(frames_of(&bwdif, look)).enumerate() {
257 (if i % 2 == 0 { &mut first } else { &mut second }).push(psnr(a, b, look.deep));
258 }
259 let mean = |v: &[f64]| v.iter().map(|x| x.min(99.0)).sum::<f64>() / v.len() as f64;
260 eprintln!(
261 "send_field {name}: vs original ours {po:.2} dB, bwdif {pb:.2} dB; ours vs bwdif {pd:.2} dB (first fields {:.2}, second fields {:.2})",
262 mean(&first),
263 mean(&second)
264 );
265 assert!(po > pb - 0.5, "{name}: ours {po:.2} dB is not within 0.5 dB of bwdif {pb:.2} dB");
266 assert!(pd > 40.0, "{name}: ours is {pd:.2} dB from bwdif send_field");
267 // The first field of every frame is exactly the frame-rate picture, so a
268 // timeline at the frame rate shows the same thing in either mode.
269 let frame_rate = frame_stage(pics);
270 for (n, f) in frame_rate.iter().enumerate() {
271 assert!(f == &fields[2 * n].1, "{name}: first field of frame {n} differs from Frame mode");
272 }
273 }
274 let _ = std::fs::remove_dir_all(&dir);
275}
276
277#[test]
278fn off_is_the_plain_decode() {
279 if !have_x264() {
280 eprintln!("no ffmpeg with libx264: skipping");
281 return;
282 }
283 let dir = scratch("dm-off");
284 for (name, look) in LOOKS {
285 let (clip, _) = make(&dir, name, look);
286 let pics = woven(&clip);
287 let mut stage = Deinterlacer::with_mode(Deinterlace::Off, true, 0, Interlace::Progressive);
288 let mut out = Vec::new();
289 for (i, pic) in pics.into_iter().enumerate() {
290 let got = stage.push_all(i as i64, pic);
291 assert_eq!(got.len(), 1, "{name}: no delay");
292 out.extend(got.into_iter().map(|(_, f)| f));
293 }
294 assert!(stage.finish_all().is_empty());
295 let plain = ffmpeg_raw(&[], &clip, look.pix());
296 assert!(raw(&out) == plain, "{name}: Off differs from ffmpeg's plain decode");
297 }
298 let _ = std::fs::remove_dir_all(&dir);
299}
300
301fn session(clip: &Path) -> PlaybackSession {
302 let s = PlaybackSession::open(clip).unwrap_or_else(|e| panic!("open {}: {e}", clip.display()));
303 s.set_gain(0.0);
304 s
305}
306
307/// The default (`Frame`) is a no-op the session reports as unchanged.
308fn set_mode(s: &mut PlaybackSession, mode: Deinterlace) {
309 assert!(s.set_deinterlace(Lane::V1, 0, mode) || mode == Deinterlace::Frame, "{mode:?}");
310}
311
312fn export_session(session: &PlaybackSession, out: &Path) {
313 let settings = ExportSettings { format: Format::Mp4, ..Default::default() };
314 let handle = session.export_to_with(out, &settings);
315 let started = Instant::now();
316 while !handle.is_finished() {
317 assert!(started.elapsed() < Duration::from_secs(600), "the export did not finish in 600 s");
318 std::thread::sleep(Duration::from_millis(20));
319 }
320 handle.result().expect("an outcome").expect("the export");
321}
322
323fn duration(path: &Path) -> f64 {
324 let o = Command::new("ffprobe")
325 .args(["-v", "error", "-show_entries", "format=duration", "-of", "csv=p=0"])
326 .arg(path)
327 .output()
328 .expect("ffprobe runs");
329 String::from_utf8_lossy(&o.stdout).trim().parse().unwrap_or(0.0)
330}
331
332/// Exports `clip` with `mode` on a timeline at `fps` (`None`: the clip's own) and
333/// returns the decoded raw frames of the result.
334fn exported(clip: &Path, out: &Path, mode: Deinterlace, fps: Option<f64>, reverse: bool, look: Look) -> Vec<u8> {
335 let mut s = session(clip);
336 set_mode(&mut s, mode);
337 if let Some(fps) = fps {
338 assert!(s.set_frame_rate(fps), "to {fps}");
339 }
340 if reverse {
341 s.set_reverse(Lane::V1, 0, true).expect("reverse");
342 }
343 software(|| export_session(&s, out));
344 ffmpeg_raw(&[], out, look.pix())
345}
346
347#[test]
348fn a_50p_timeline_shows_every_field_of_a_25i_field_clip() {
349 if !have_x264() {
350 eprintln!("no ffmpeg with libx264: skipping");
351 return;
352 }
353 let dir = scratch("dm-50p");
354 for (name, look) in [LOOKS[0], LOOKS[1]] {
355 let (clip, reference) = make(&dir, name, look);
356 let want = std::fs::read(&reference).expect("reference");
357 let out = dir.join(format!("{name}-50p.mp4"));
358 let decoded = exported(&clip, &out, Deinterlace::Field, Some(50.0), false, look);
359 let frames = frames_of(&decoded, look);
360 assert_eq!(frames.len(), 2 * FRAMES as usize, "{name}: twice the frames");
361 let secs = duration(&out);
362 assert!((secs - f64::from(FRAMES) / 25.0).abs() < 0.1, "{name}: {secs} s, want 1.2 s");
363 // Motion continuity: each field's picture differs from the next, and the
364 // content moves forward (closest to its own moment).
365 for w in frames.windows(2) {
366 assert!(w[0] != w[1], "{name}: two equal pictures in a row");
367 }
368 let bwdif = ffmpeg_raw(&["-vf", &format!("bwdif=mode=send_field:parity={}:deint=all", look.parity())], &clip, look.pix());
369 let (pe, pb) = (psnr(&want, &decoded, false), psnr(&want, &bwdif, false));
370 eprintln!("50p export {name}: {} frames, {secs:.3} s, {pe:.2} dB vs original (bwdif send_field {pb:.2} dB)", frames.len());
371 assert!(pe > pb - 1.5, "{name}: exported {pe:.2} dB vs bwdif {pb:.2} dB");
372 let reference_frames = frames_of(&want, look);
373 for (k, f) in frames.iter().enumerate() {
374 let own = psnr(reference_frames[k], f, false);
375 let other = psnr(reference_frames[(k + 1).min(frames.len() - 1)], f, false);
376 assert!(own >= other, "{name}: picture {k} is closer to moment {} than to its own", k + 1);
377 }
378 // Reverse plays the fields last to first.
379 let back = dir.join(format!("{name}-50p-rev.mp4"));
380 let rev = exported(&clip, &back, Deinterlace::Field, Some(50.0), true, look);
381 let rframes = frames_of(&rev, look);
382 assert_eq!(rframes.len(), frames.len(), "{name}: reverse keeps the count");
383 for (d, f) in rframes.iter().enumerate() {
384 let p = psnr(frames[frames.len() - 1 - d], f, false);
385 assert!(p > 28.0, "{name}: reversed picture {d} is {p:.2} dB from field {}", frames.len() - 1 - d);
386 }
387 // Speed 2 on the 50p timeline: every first field, half the frames.
388 let mut s = session(&clip);
389 set_mode(&mut s, Deinterlace::Field);
390 assert!(s.set_frame_rate(50.0));
391 s.set_speed(Lane::V1, 0, Speed::from_permille(2000)).expect("speed");
392 let fast = dir.join(format!("{name}-50p-x2.mp4"));
393 software(|| export_session(&s, &fast));
394 let fast_frames = ffmpeg_raw(&[], &fast, look.pix());
395 assert_eq!(frames_of(&fast_frames, look).len(), FRAMES as usize, "{name}: speed 2 halves the frames");
396 let fast_frames = frames_of(&fast_frames, look);
397 for (k, f) in fast_frames.iter().enumerate() {
398 let p = psnr(frames[2 * k], f, false);
399 assert!(p > 28.0, "{name}: speed-2 picture {k} is {p:.2} dB from field {}", 2 * k);
400 }
401 }
402 let _ = std::fs::remove_dir_all(&dir);
403}
404
405#[test]
406fn a_25p_timeline_shows_the_first_field_of_each_frame_like_frame_mode() {
407 if !have_x264() {
408 eprintln!("no ffmpeg with libx264: skipping");
409 return;
410 }
411 let dir = scratch("dm-25p");
412 for (name, look) in [LOOKS[0], LOOKS[1]] {
413 let (clip, _) = make(&dir, name, look);
414 let field = exported(&clip, &dir.join(format!("{name}-field.mp4")), Deinterlace::Field, None, false, look);
415 let frame = exported(&clip, &dir.join(format!("{name}-frame.mp4")), Deinterlace::Frame, None, false, look);
416 let off = exported(&clip, &dir.join(format!("{name}-off.mp4")), Deinterlace::Off, None, false, look);
417 assert_eq!(frames_of(&field, look).len(), FRAMES as usize, "{name}");
418 assert!(field == frame, "{name}: Field on a 25p timeline is not Frame's pictures");
419 let (cf, co) = (combing_of(&frame), combing_of(&off));
420 eprintln!("25p export {name}: combing frame {cf:.5}, off {co:.5}");
421 assert!(co > cf * 2.0, "{name}: Off ({co:.5}) should keep the woven combing Frame ({cf:.5}) removes");
422 }
423 let _ = std::fs::remove_dir_all(&dir);
424}
425
426#[test]
427fn stills_follow_the_mode() {
428 if !have_x264() {
429 eprintln!("no ffmpeg with libx264: skipping");
430 return;
431 }
432 let dir = scratch("dm-still");
433 let (name, look) = LOOKS[0];
434 let (clip, _) = make(&dir, name, look);
435 let still = |mode: Deinterlace, fps: Option<f64>, frame: u32| {
436 let mut s = session(&clip);
437 set_mode(&mut s, mode);
438 if let Some(fps) = fps {
439 assert!(s.set_frame_rate(fps));
440 }
441 software(|| s.compose_at(frame, W as u32, H as u32)).expect("compose_at").bgra
442 };
443 for n in [0u32, 1, 7, 10, 11, 29] {
444 let frame = still(Deinterlace::Frame, None, n);
445 assert!(still(Deinterlace::Field, None, n) == frame, "25p frame {n}: Field differs from Frame");
446 let first = still(Deinterlace::Field, Some(50.0), 2 * n);
447 let second = still(Deinterlace::Field, Some(50.0), 2 * n + 1);
448 assert!(first == frame, "50p frame {}: not Frame mode's picture {n}", 2 * n);
449 assert!(second != first, "50p frame {}: the second field repeats the first", 2 * n + 1);
450 assert!(still(Deinterlace::Off, None, n) != frame, "25p frame {n}: Off equals Frame");
451 }
452 let _ = std::fs::remove_dir_all(&dir);
453}
454
455#[test]
456fn a_progressive_source_ignores_the_setting() {
457 if !have_x264() {
458 eprintln!("no ffmpeg with libx264: skipping");
459 return;
460 }
461 let dir = scratch("dm-prog");
462 let look = Look { tff: true, deep: false, c422: false };
463 let clip = progressive(&dir, "p.mp4", 25);
464 for fps in [None, Some(50.0)] {
465 let base = exported(&clip, &dir.join("base.mp4"), Deinterlace::Frame, fps, false, look);
466 for mode in [Deinterlace::Field, Deinterlace::Off] {
467 let other = exported(&clip, &dir.join("other.mp4"), mode, fps, false, look);
468 assert!(other == base, "{mode:?} at {fps:?} changed a progressive export");
469 }
470 let still = |mode: Deinterlace| {
471 let mut s = session(&clip);
472 set_mode(&mut s, mode);
473 if let Some(fps) = fps {
474 s.set_frame_rate(fps);
475 }
476 software(|| s.compose_at(5, W as u32, H as u32)).expect("compose_at").bgra
477 };
478 assert!(still(Deinterlace::Field) == still(Deinterlace::Frame), "{fps:?}: still");
479 assert!(still(Deinterlace::Off) == still(Deinterlace::Frame), "{fps:?}: still");
480 }
481 let _ = std::fs::remove_dir_all(&dir);
482}
483
484/// Playback and scrub follow the mode. Needs the `playback.rs` change in the lane
485/// report (the decode layer is field-ready, the session's rate mapping is not), so it
486/// is ignored until that lands: `cargo test --test deinterlace_mode -- --ignored`.
487#[test]
488#[ignore = "needs the peer-owned playback.rs hunk from the lane report"]
489fn playback_and_scrub_show_the_field_the_export_writes() {
490 if !have_x264() {
491 eprintln!("no ffmpeg with libx264: skipping");
492 return;
493 }
494 let dir = scratch("dm-play");
495 let (name, look) = LOOKS[0];
496 let (clip, _) = make(&dir, name, look);
497 let mut s = session(&clip);
498 set_mode(&mut s, Deinterlace::Field);
499 assert!(s.set_frame_rate(50.0));
500 for k in [0u32, 1, 2, 5, 20, 31, 58, 59] {
501 // Mid-GOP seeks and back-and-forth scrubs alike.
502 s.seek((f64::from(k) + 0.25) / 50.0);
503 let deadline = Instant::now() + Duration::from_secs(20);
504 let shown = loop {
505 if let Some(f) = software(|| s.try_frame()) {
506 break f;
507 }
508 assert!(Instant::now() < deadline, "no frame at {k}");
509 std::thread::sleep(Duration::from_millis(5));
510 };
511 let want = software(|| s.compose_at(k, W as u32, H as u32)).expect("compose_at");
512 assert!(shown.bgra == want.bgra, "scrub to {k}: the viewer and the export disagree");
513 }
514 let _ = std::fs::remove_dir_all(&dir);
515}